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(); gameObject.GetOrAddComponent(); //读取xml颜色并转化 effect.outlineColor = Utility.ToColor(device.HighColor); StringEventSystem.Global.Register(Global.HighLightTrigger, OnHighLightTriggerEvent); TypeEventSystem.Global.Register(OnStepChanged); #if VR effect.constantWidth = false; #endif } if (device.MeshCollider) { gameObject.GetOrAddComponent(); } else if (string.IsNullOrEmpty(device.BoxColliderSize) == false) { BoxCollider box = gameObject.GetOrAddComponent(); 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.Set(device.Tip); } } private void OnStepChanged(StepStatusOnChange change) { var effect = gameObject.GetComponent(); if (effect != null) { effect.highlighted = false; } } public void Close() { device = null; tipItem = null; StringEventSystem.Global.UnRegister(Global.HighLightTrigger, OnHighLightTriggerEvent); TypeEventSystem.Global.UnRegister(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(); if (high != null) { gameObject.GetComponent().enabled = isActive; } else { Debug.LogError(device.Name + "身上没有高亮组件"); } } } } private void OnMouseUpAsButton() { var effect = gameObject.GetComponent(); if (effect != null) { effect.highlighted = false; } } }