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.
162 lines
5.1 KiB
162 lines
5.1 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, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||
|
{
|
||
|
public SecondNodeObject obj;
|
||
|
private Toggle toggle;
|
||
|
public Text uiName;
|
||
|
public static bool replay;//是否播放第一个节点,在自动播放中使用
|
||
|
private SecondNodeManager secondNodeManager;
|
||
|
private bool control = false;
|
||
|
private float time;
|
||
|
private DragNode dragNode;
|
||
|
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>();
|
||
|
dragNode = GameObject.Find("Canvas/TopUI/WorkflowUI/DragNode").GetComponent<DragNode>();
|
||
|
}
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
public void OnBeginDrag(PointerEventData eventData)
|
||
|
{
|
||
|
// if (QuestionManager.GetInstance().editorRight)
|
||
|
if (DisasterManager.editorRight)
|
||
|
{
|
||
|
dragNode.gameObject.SetActive(true);
|
||
|
dragNode.SetUI(obj.nodeName);
|
||
|
dragNode.BeginDrag(eventData);
|
||
|
dragNode.SetinfoWhileBeginDrag(obj);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void OnDrag(PointerEventData eventData)
|
||
|
{
|
||
|
//if (QuestionManager.GetInstance().editorRight)
|
||
|
if (DisasterManager.editorRight)
|
||
|
{
|
||
|
dragNode.Drag(eventData);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void OnEndDrag(PointerEventData eventData)
|
||
|
{
|
||
|
// if (QuestionManager.GetInstance().editorRight)
|
||
|
if(DisasterManager.editorRight )
|
||
|
{
|
||
|
//判断鼠标在UI上
|
||
|
var depth = eventData.pointerCurrentRaycast.depth;
|
||
|
if (depth != 0)
|
||
|
{
|
||
|
//判断鼠标在节点上
|
||
|
var pointerObj = eventData.pointerCurrentRaycast.gameObject;
|
||
|
var secondNodeItem = pointerObj.GetComponentInParent<SecondNodeItem>();
|
||
|
if (secondNodeItem)
|
||
|
{
|
||
|
if (secondNodeItem.obj.nodeName!=obj.nodeName)
|
||
|
{
|
||
|
obj = (SecondNodeObject)secondNodeItem.obj.DeepCopy();
|
||
|
SetUI();
|
||
|
secondNodeItem.obj = dragNode.SecondNodeObjectObj;
|
||
|
secondNodeItem.SetUI();
|
||
|
}
|
||
|
//if (secondNodeItem.obj.order != obj.order)
|
||
|
//{
|
||
|
// var index = secondNodeItem.transform.GetSiblingIndex();
|
||
|
// transform.SetSiblingIndex(index);
|
||
|
// foreach (Transform item in transform.parent)
|
||
|
// {
|
||
|
// item.GetComponent<SecondNodeItem>().obj.order = item.GetSiblingIndex();
|
||
|
// }
|
||
|
// // QuestionManager.GetInstance().nodeList.secondNodeList.Sort((x, y) => x.order.CompareTo(y.order));//升序
|
||
|
// // QuestionManager.GetInstance().UpdateNodeListJson();//更新本地nodeList文件存储
|
||
|
//}
|
||
|
}
|
||
|
}
|
||
|
GetComponentInParent<SecondNodeManager>().UpdateSecondNodeSort(transform.parent);
|
||
|
dragNode.gameObject.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
}
|