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.
99 lines
2.5 KiB
99 lines
2.5 KiB
4 years ago
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.EventSystems;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
[RequireComponent(typeof(Toggle))]
|
||
|
public class SecondNodeItem : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||
|
{
|
||
|
public SecondNodeObject obj;
|
||
|
private Toggle toggle;
|
||
|
public Text uiName;
|
||
|
public static bool replay;//是否播放第一个节点,在自动播放中使用
|
||
|
private SecondNodeManager secondNodeManager;
|
||
|
private bool control = false;
|
||
|
private float time;
|
||
|
private void Awake()
|
||
|
{
|
||
|
toggle = GetComponent<Toggle>();
|
||
|
toggle.onValueChanged.AddListener(ValueChanged);
|
||
|
}
|
||
|
// Use this for initialization
|
||
|
void Start()
|
||
|
{
|
||
|
MessageDispatcher.AddListener("ReplaySecondNode", SelectNode);
|
||
|
secondNodeManager = TransformHelper.FindParentByName(transform, "SecondNodePanel").GetComponent<SecondNodeManager>();
|
||
|
}
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("ReplaySecondNode", SelectNode);
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 播放指定二级节点
|
||
|
/// </summary>
|
||
|
/// <param name="data"></param>
|
||
|
private void SelectNode(IMessage data)
|
||
|
{
|
||
|
var nodeID = (int)data.Data;
|
||
|
if (obj.nodeID== nodeID)
|
||
|
{
|
||
|
toggle.isOn = true;
|
||
|
MessageDispatcher.SendMessage("Replay");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
if (control)
|
||
|
{
|
||
|
time -= Time.deltaTime;
|
||
|
if (time < 0)
|
||
|
{
|
||
|
secondNodeManager.ShowTagList(gameObject);
|
||
|
control = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
private void ValueChanged(bool isOn)
|
||
|
{
|
||
|
if (isOn)
|
||
|
{
|
||
|
SecondNodeManager.selectNode = obj;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 设置节点属性
|
||
|
/// </summary>
|
||
|
/// <param name="nodeOjbect"></param>
|
||
|
public void SetItem(SecondNodeObject nodeOjbect)
|
||
|
{
|
||
|
obj = nodeOjbect;
|
||
|
SetUI();
|
||
|
if (replay)
|
||
|
{//自动播放第一个节点
|
||
|
replay = false;
|
||
|
toggle.isOn = true;
|
||
|
MessageDispatcher.SendMessage("Replay");
|
||
|
}
|
||
|
}
|
||
|
public void SetUI()
|
||
|
{
|
||
|
uiName.text = obj.nodeName;
|
||
|
}
|
||
|
public void OnPointerEnter(PointerEventData eventData)
|
||
|
{
|
||
|
time = 1;
|
||
|
control = true;
|
||
|
}
|
||
|
|
||
|
public void OnPointerExit(PointerEventData eventData)
|
||
|
{
|
||
|
control = false;
|
||
|
secondNodeManager.HideTagList();
|
||
|
}
|
||
|
}
|