You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.7 KiB
106 lines
2.7 KiB
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>(); |
|
toggle.onValueChanged.AddListener(ValueChanged); |
|
element = GetComponent<LayoutElement>(); |
|
} |
|
// 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); |
|
} |
|
/// <summary> |
|
/// 播放指定一级节点 |
|
/// </summary> |
|
/// <param name="data"></param> |
|
private void SelectNode(IMessage data) |
|
{ |
|
var nodeID = (int)data.Data; |
|
if (obj.nodeID == nodeID) |
|
{ |
|
SecondNodeItem.replay = true; |
|
toggle.isOn = true; |
|
} |
|
} |
|
/// <summary> |
|
/// 删除节点后重新调整显示索引 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
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(); |
|
} |
|
/// <summary> |
|
/// 设置节点属性 |
|
/// </summary> |
|
/// <param name="nodeOjbect"></param> |
|
/// <param name="nodeIndex"></param> |
|
public void SetItem(FirstNodeObject nodeOjbect, int nodeIndex) |
|
{ |
|
obj = nodeOjbect; |
|
index = nodeIndex; |
|
if (index == 0) |
|
{ |
|
toggle.isOn = true; |
|
} |
|
SetUI(); |
|
} |
|
/// <summary> |
|
/// 设置节点显示文字 |
|
/// </summary> |
|
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; |
|
} |
|
} |
|
}
|
|
|