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.

47 lines
1.5 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace AmplifyShaderEditor
  6. {
  7. public class DragAndDropTool
  8. {
  9. public delegate void OnValidDropObject(params UnityEngine.Object[] draggedObjs );
  10. public event OnValidDropObject OnValidDropObjectEvt;
  11. public void Destroy()
  12. {
  13. OnValidDropObjectEvt = null;
  14. }
  15. public void TestDragAndDrop( Rect dropArea )
  16. {
  17. Event currentEvent = Event.current;
  18. EventType currentEventType = currentEvent.type;
  19. switch (currentEventType)
  20. {
  21. case EventType.DragUpdated:
  22. case EventType.DragPerform:
  23. {
  24. if (!dropArea.Contains(currentEvent.mousePosition))
  25. return;
  26. DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
  27. if (currentEvent.type == EventType.DragPerform)
  28. {
  29. DragAndDrop.AcceptDrag();
  30. if (OnValidDropObjectEvt != null)
  31. {
  32. OnValidDropObjectEvt(DragAndDrop.objectReferences);
  33. }
  34. }
  35. }break;
  36. case EventType.DragExited:DragAndDrop.PrepareStartDrag();break;
  37. }
  38. }
  39. }
  40. }