| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.Events;
- using LuaInterface;
- namespace WXB
- {
- [RequireComponent(typeof(SymbolText))]
- public class SymbolTextEvent : MonoBehaviour, /*IPointerEnterHandler, IPointerExitHandler,*/ IPointerDownHandler, IPointerUpHandler
- {
- SymbolText d_symbolText;
- //RenderCache.BaseData d_baseData;
- [System.Serializable]
- public class OnClickEvent : UnityEvent<NodeBase>
- {
- }
- public OnClickEvent OnClick = new OnClickEvent(); // 点击了此结点
- LuaTable table;
- LuaFunction func;
- LuaTable param;
- void OnEnable()
- {
- if (d_symbolText == null)
- {
- d_symbolText = GetComponent<SymbolText>();
- }
- }
- void OnDisable()
- {
- //isEnter = false;
- //d_baseData = null;
- d_down_basedata = null;
- localPosition = Vector2.zero;
- }
- //bool isEnter = false;
- //public void OnPointerEnter(PointerEventData eventData)
- //{
- // isEnter = true;
- //}
- //public void OnPointerExit(PointerEventData eventData)
- //{
- // isEnter = false;
- //}
- RenderCache.BaseData d_down_basedata;
- public void RegisterClickEvent(LuaTable table, LuaFunction func)
- {
- this.table = table;
- this.func = func;
- }
- public void OnPointerDown(PointerEventData eventData)
- {
- if (!Tools.ScreenPointToWorldPointInRectangle(d_symbolText.rectTransform, eventData.position, d_symbolText.canvas.worldCamera, out localPosition))
- return;
- //localPosition *= d_symbolText.pixelsPerUnit;
- d_down_basedata = d_symbolText.renderCache.Get(localPosition);
- }
- public void OnPointerUp(PointerEventData eventData)
- {
- if (!Tools.ScreenPointToWorldPointInRectangle(d_symbolText.rectTransform, eventData.position, d_symbolText.canvas.worldCamera, out localPosition))
- return;
- //localPosition *= d_symbolText.pixelsPerUnit;
- var up_node = d_symbolText.renderCache.Get(localPosition);
- if (d_down_basedata != up_node)
- return;
- if (d_down_basedata != null)
- {
- OnClick.Invoke(d_down_basedata.node);
- if (func != null)
- {
- HyperlinkNode node = d_down_basedata.node as HyperlinkNode;
- if (node != null && !string.IsNullOrEmpty(node.d_link))
- {
- if (table != null)
- {
- func.Call(table, node.d_link);
- }
- else
- {
- func.Call(node.d_link);
- }
- }
- }
- }
- }
- Vector2 localPosition;
- //void Update()
- //{
- // if (isEnter)
- // {
- // Tools.ScreenPointToWorldPointInRectangle(d_symbolText.rectTransform, Input.mousePosition, d_symbolText.canvas.worldCamera, out localPosition);
- // localPosition *= d_symbolText.pixelsPerUnit;
- // //Debug.LogFormat("Pos:{0}", localPosition);
- // RenderCache.BaseData bd = d_symbolText.renderCache.Get(localPosition);
- // if (d_baseData != bd)
- // {
- // if (d_baseData != null)
- // {
- // d_baseData.OnMouseLevel();
- // }
- // d_baseData = bd;
- // if (d_baseData != null)
- // d_baseData.OnMouseEnter();
- // }
- // }
- // else
- // {
- // if (d_baseData != null)
- // {
- // d_baseData.OnMouseLevel();
- // d_baseData = null;
- // }
- // }
- //}
- }
- }
|