summaryrefslogtreecommitdiff
path: root/Assets/AmplifyShaderEditor/Plugins/Editor/Menu/DragAndDropTool.cs
blob: 2da02086d45236acaa6345e7438e9a3c1fcd06fe (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
// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>

using UnityEditor;
using UnityEngine;

namespace AmplifyShaderEditor
{
    public class DragAndDropTool
    {
        public delegate void OnValidDropObject(params UnityEngine.Object[] draggedObjs );
        public event OnValidDropObject OnValidDropObjectEvt;

        public void Destroy()
        {
            OnValidDropObjectEvt = null;
        }

        public void TestDragAndDrop( Rect dropArea )
        {
            Event currentEvent = Event.current;
            EventType currentEventType = currentEvent.type;
            
            switch (currentEventType)
            {
                case EventType.DragUpdated:
                case EventType.DragPerform:
                {
                    
                    if (!dropArea.Contains(currentEvent.mousePosition))
                        return;

                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    if (currentEvent.type == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();
                        if (OnValidDropObjectEvt != null)
                        {
                            OnValidDropObjectEvt(DragAndDrop.objectReferences);
                        }
                    }
                }break;
                case EventType.DragExited:DragAndDrop.PrepareStartDrag();break;
            }
        }
    }
}