96 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using HighlightPlus;
using QFramework;
using QFramework.Example;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static OperationController;
public class DeviceItem : MonoBehaviour
{
public XMLTool.Device device;
public TipItem tipItem;
public void Init(XMLTool.Device device)
{
this.device = device;
if (string.IsNullOrEmpty(device.HighColor) == false)
{
var effect = gameObject.GetOrAddComponent<HighlightEffect>();
gameObject.GetOrAddComponent<HighlightTrigger>();
//¶ÁÈ¡xmlÑÕÉ«²¢×ª»¯
effect.outlineColor = Utility.ToColor(device.HighColor);
StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
}
if (device.MeshCollider)
{
gameObject.GetOrAddComponent<MeshCollider>();
}
else if (string.IsNullOrEmpty(device.BoxColliderSize) == false)
{
BoxCollider box = gameObject.GetOrAddComponent<BoxCollider>();
box.size = Utility.GetVector3FromStrArray(device.BoxColliderSize);
if (string.IsNullOrEmpty(device.BoxColliderCenter) == false)
{
box.center = Utility.GetVector3FromStrArray(device.BoxColliderCenter);
}
}
if (string.IsNullOrEmpty(device.Tip) == false)
{
tipItem = gameObject.GetOrAddComponent<TipItem>();
tipItem.Set(device.Tip);
}
}
private void OnStepChanged(StepStatusOnChange change)
{
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect != null)
{
effect.highlighted = false;
}
}
public void Close()
{
device = null;
tipItem = null;
StringEventSystem.Global.UnRegister<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
TypeEventSystem.Global.UnRegister<StepStatusOnChange>(OnStepChanged);
}
private void OnHighLightTriggerEvent(string[] obj)
{
if (obj.Length > 0)
{
bool isActive = true;
bool.TryParse(obj[0], out isActive);
if (obj.Length == 1 || (obj.Length > 1 && obj[1] == device.Name))
{
var high = gameObject.GetComponent<HighlightTrigger>();
if (high != null)
{
gameObject.GetComponent<HighlightTrigger>().enabled = isActive;
}
else
{
Debug.LogError(device.Name + "ÉíÉÏûÓиßÁÁ×é¼þ");
}
}
}
}
private void OnMouseUpAsButton()
{
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect != null)
{
effect.highlighted = false;
}
}
}