Selection.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. public sealed class Selection
  7. {
  8. public static Action<SceneObject[], string[]> OnSelectionChanged;
  9. public static Action<SceneObject> OnSceneObjectPing;
  10. public static Action<string> OnResourcePing;
  11. public static SceneObject sceneObject
  12. {
  13. get
  14. {
  15. SceneObject[] selection;
  16. Internal_GetSceneObjectSelection(out selection);
  17. if(selection.Length > 0)
  18. return selection[0];
  19. return null;
  20. }
  21. set
  22. {
  23. Internal_SetSceneObjectSelection(new SceneObject[] { value });
  24. }
  25. }
  26. public static SceneObject[] sceneObjects
  27. {
  28. get
  29. {
  30. SceneObject[] selection;
  31. Internal_GetSceneObjectSelection(out selection);
  32. return selection;
  33. }
  34. set
  35. {
  36. Internal_SetSceneObjectSelection(value);
  37. }
  38. }
  39. public static string[] resourceUUIDs
  40. {
  41. get
  42. {
  43. string[] selection;
  44. Internal_GetResourceUUIDSelection(out selection);
  45. return selection;
  46. }
  47. set
  48. {
  49. Internal_SetResourceUUIDSelection(value);
  50. }
  51. }
  52. public static string[] resourcePaths
  53. {
  54. get
  55. {
  56. string[] selection;
  57. Internal_GetResourcePathSelection(out selection);
  58. return selection;
  59. }
  60. set
  61. {
  62. Internal_SetResourcePathSelection(value);
  63. }
  64. }
  65. public static void Ping(Resource resource)
  66. {
  67. string path = ProjectLibrary.GetPath(resource);
  68. Internal_PingResource(path);
  69. }
  70. public static void Ping(SceneObject so)
  71. {
  72. Internal_PingSceneObject(so);
  73. }
  74. private static void Internal_TriggerSelectionChanged(SceneObject[] objects, string[] paths)
  75. {
  76. if (OnSelectionChanged != null)
  77. OnSelectionChanged(objects, paths);
  78. }
  79. private static void Internal_TriggerSceneObjectPing(SceneObject so)
  80. {
  81. if (OnSceneObjectPing != null)
  82. OnSceneObjectPing(so);
  83. }
  84. private static void Internal_TriggerResourcePing(string path)
  85. {
  86. if (OnResourcePing != null)
  87. OnResourcePing(path);
  88. }
  89. [MethodImpl(MethodImplOptions.InternalCall)]
  90. internal static extern void Internal_GetSceneObjectSelection(out SceneObject[] selection);
  91. [MethodImpl(MethodImplOptions.InternalCall)]
  92. internal static extern void Internal_SetSceneObjectSelection(SceneObject[] selection);
  93. [MethodImpl(MethodImplOptions.InternalCall)]
  94. internal static extern void Internal_GetResourceUUIDSelection(out string[] selection);
  95. [MethodImpl(MethodImplOptions.InternalCall)]
  96. internal static extern void Internal_SetResourceUUIDSelection(string[] selection);
  97. [MethodImpl(MethodImplOptions.InternalCall)]
  98. internal static extern void Internal_GetResourcePathSelection(out string[] selection);
  99. [MethodImpl(MethodImplOptions.InternalCall)]
  100. internal static extern void Internal_SetResourcePathSelection(string[] selection);
  101. [MethodImpl(MethodImplOptions.InternalCall)]
  102. internal static extern void Internal_PingResource(string resourcePath);
  103. [MethodImpl(MethodImplOptions.InternalCall)]
  104. internal static extern void Internal_PingSceneObject(SceneObject so);
  105. }
  106. }