summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/UICommon/XUIDragDropItem.cs
blob: 07a4d1035bd98b1db1eaee342e17f621da09bfe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using UILib;
using UnityEngine;
using System;

public class XUIDragDropItem : XUIObject, IXUIDragDropItem
{
 
    private UIPanel  m_panel;
    private void Awake()
    {
        m_dragdrop = GetComponent<UIDragDropItem>();

        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<UIPanel>();
        if (addPanel)
        {
            m_panel = gameObject.GetComponent<UIPanel>();
            if (m_panel == null)  m_panel = gameObject.AddComponent<UIPanel>();
            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;


}