using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using AX.MessageSystem; [RequireComponent(typeof(Toggle))] [RequireComponent(typeof(LayoutElement))] public class FirstNodeItem : MonoBehaviour { public FirstNodeObject obj; public int index; private Toggle toggle; private LayoutElement element; public Text uiName; private void Awake() { toggle = GetComponent(); toggle.onValueChanged.AddListener(ValueChanged); element = GetComponent(); } // Use this for initialization void Start() { MessageDispatcher.AddListener("DeleteFirstNode",ChangeIndex); MessageDispatcher.AddListener("ReplayFirstNode", SelectNode); } private void OnDestroy() { MessageDispatcher.RemoveListener("DeleteFirstNode", ChangeIndex); MessageDispatcher.RemoveListener("ReplayFirstNode", SelectNode); } /// /// 播放指定一级节点 /// /// private void SelectNode(IMessage data) { var nodeID = (int)data.Data; if (obj.nodeID == nodeID) { SecondNodeItem.replay = true; toggle.isOn = true; } } /// /// 删除节点后重新调整显示索引 /// /// private void ChangeIndex(IMessage obj) { var delIndex = (int)obj.Data; if (index> delIndex) { index--; SetUI(); } } // Update is called once per frame void Update() { } private void ValueChanged(bool isOn) { if (isOn) { FirstNodeManager.selectNode = obj; MessageDispatcher.SendMessage("FirstNodeSelected");//发送消息,改变二级节点UI } SetUI(); } /// /// 设置节点属性 /// /// /// public void SetItem(FirstNodeObject nodeOjbect, int nodeIndex) { obj = nodeOjbect; index = nodeIndex; if (index == 0) { toggle.isOn = true; } SetUI(); } /// /// 设置节点显示文字 /// public void SetUI() { if (toggle.isOn) { uiName.text = FirstNodeManager.ToChinese(index) + "、" + obj.nodeName; element.flexibleWidth = 3; } else { uiName.text = FirstNodeManager.ToChinese(index); element.flexibleWidth = 1; } } }