DropTarget.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. public class DropTarget : ScriptObject
  7. {
  8. public Action<int, int> OnDrop;
  9. public Action<int, int> OnEnter;
  10. public Action OnLeave;
  11. public Action<int, int> OnDrag;
  12. public DropTarget(EditorWindow window)
  13. {
  14. IntPtr nativeWindow = window.GetCachedPtr();;
  15. Internal_CreateInstance(this, nativeWindow);
  16. }
  17. public void Destroy()
  18. {
  19. Internal_Destroy(mCachedPtr);
  20. }
  21. public Rect2I Bounds
  22. {
  23. set { Internal_SetBounds(mCachedPtr, value); }
  24. }
  25. public string[] FilePaths
  26. {
  27. get { return Internal_GetFilePaths(mCachedPtr); }
  28. }
  29. private void InternalDoOnEnter(int x, int y)
  30. {
  31. if (OnEnter != null)
  32. OnEnter(x, y);
  33. }
  34. private void InternalDoOnLeave()
  35. {
  36. if (OnLeave != null)
  37. OnLeave();
  38. }
  39. private void InternalDoOnDrag(int x, int y)
  40. {
  41. if (OnDrag != null)
  42. OnDrag(x, y);
  43. }
  44. private void InternalDoOnDrop(int x, int y)
  45. {
  46. if (OnDrop != null)
  47. OnDrop(x, y);
  48. }
  49. [MethodImpl(MethodImplOptions.InternalCall)]
  50. private static extern void Internal_CreateInstance(DropTarget instance, IntPtr editorWindow);
  51. [MethodImpl(MethodImplOptions.InternalCall)]
  52. private static extern void Internal_Destroy(IntPtr nativeInstance);
  53. [MethodImpl(MethodImplOptions.InternalCall)]
  54. private static extern void Internal_SetBounds(IntPtr nativeInstance, Rect2I bounds);
  55. [MethodImpl(MethodImplOptions.InternalCall)]
  56. private static extern string[] Internal_GetFilePaths(IntPtr nativeInstance);
  57. }
  58. }