From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/UICommon/XUIDragDropItem.cs | 103 ++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Client/Assets/Scripts/UICommon/XUIDragDropItem.cs (limited to 'Client/Assets/Scripts/UICommon/XUIDragDropItem.cs') diff --git a/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs b/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs new file mode 100644 index 00000000..07a4d103 --- /dev/null +++ b/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs @@ -0,0 +1,103 @@ +using UILib; +using UnityEngine; +using System; + +public class XUIDragDropItem : XUIObject, IXUIDragDropItem +{ + + private UIPanel m_panel; + private void Awake() + { + m_dragdrop = GetComponent(); + + if (null == m_dragdrop) + { + Debug.LogError("null == m_dragdrop"); + } + } + + public void SetCloneOnDrag(bool cloneOnDrag) + { + m_dragdrop.cloneOnDrag = cloneOnDrag; + } + + public void SetRestriction(int restriction) + { + m_dragdrop.restriction = (UIDragDropItem.Restriction)Enum.ToObject(typeof(UIDragDropItem.Restriction), restriction); + } + + + public void SetActive(bool active) + { + m_dragdrop.enabled = active; + enabled = active; + } + + + public void SetParent(Transform parent , bool addPanel = false, int depth = 0) + { + transform.parent = parent; + m_panel = gameObject.GetComponent(); + if (addPanel) + { + m_panel = gameObject.GetComponent(); + if (m_panel == null) m_panel = gameObject.AddComponent(); + m_panel.depth = depth; + m_panel.enabled = true; + } + else + { + if (m_panel != null) m_panel.enabled = false; + } + } + + public void RegisterOnFinishEventHandler(OnDropReleaseEventHandler eventHandler) + { + m_OnFinishHandler = eventHandler; + + //m_uiPlayTween.customFinishCallback = OnFinish; + m_dragdrop.onFinished.Clear(); + EventDelegate.Add(m_dragdrop.onFinished, OnFinish); + } + + public void RegisterOnStartEventHandler(OnDropStartEventHandler eventHandler) + { + m_OnStartHandler = eventHandler; + m_dragdrop.onStart.Clear(); + EventDelegate.Add(m_dragdrop.onStart, OnStart); + } + + public OnDropStartEventHandler GetStartEventHandler() + { + return m_OnStartHandler; + } + + public OnDropReleaseEventHandler GetReleaseEventHandler() + { + return m_OnFinishHandler; + } + + + void OnFinish() + { + if (m_OnFinishHandler != null) + { + m_OnFinishHandler(gameObject, UICamera.hoveredObject); + } + } + + new void OnStart() + { + if (m_OnStartHandler != null) + { + m_OnStartHandler(gameObject); + } + } + + public UIDragDropItem m_dragdrop; + + public OnDropReleaseEventHandler m_OnFinishHandler = null; + public OnDropStartEventHandler m_OnStartHandler = null; + + +} -- cgit v1.1-26-g67d0