83 lines
2.4 KiB
C#
83 lines
2.4 KiB
C#
using HighlightPlus;
|
||
using QFramework;
|
||
using QFramework.Example;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
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>();
|
||
effect.outlineColor = Color.green;
|
||
StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
|
||
}
|
||
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);
|
||
}
|
||
}
|
||
|
||
public void Close()
|
||
{
|
||
device = null;
|
||
tipItem = null;
|
||
StringEventSystem.Global.UnRegister<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
|
||
}
|
||
|
||
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 + "<22><><EFBFBD><EFBFBD>û<EFBFBD>и<EFBFBD><D0B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void OnMouseUpAsButton()
|
||
{
|
||
var effect = gameObject.GetComponent<HighlightEffect>();
|
||
if (effect != null)
|
||
{
|
||
effect.highlighted = false;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|