Selection.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Handles scene object and resource selection. Triggeres events when selection changes and allows the user to query
  8. /// current selection state.
  9. /// </summary>
  10. public sealed class Selection
  11. {
  12. /// <summary>
  13. /// Triggered whenever scene object or resource selection changes. The provided parameters will contain the newly
  14. /// selected objects/resource paths.
  15. /// </summary>
  16. public static Action<SceneObject[], string[]> OnSelectionChanged;
  17. /// <summary>
  18. /// Triggered when a resource ping is requested. Ping usually means the object will be highlighted in its respective
  19. /// editors.
  20. /// </summary>
  21. internal static Action<string> OnResourcePing;
  22. /// <summary>
  23. /// Currently selected scene object. If more than one object is selected, this returns the first one.
  24. /// </summary>
  25. public static SceneObject SceneObject
  26. {
  27. get
  28. {
  29. SceneObject[] selection;
  30. Internal_GetSceneObjectSelection(out selection);
  31. if(selection.Length > 0)
  32. return selection[0];
  33. return null;
  34. }
  35. set
  36. {
  37. Internal_SetSceneObjectSelection(new SceneObject[] { value });
  38. }
  39. }
  40. /// <summary>
  41. /// Currently selected set of scene objects.
  42. /// </summary>
  43. public static SceneObject[] SceneObjects
  44. {
  45. get
  46. {
  47. SceneObject[] selection;
  48. Internal_GetSceneObjectSelection(out selection);
  49. return selection;
  50. }
  51. set
  52. {
  53. Internal_SetSceneObjectSelection(value);
  54. }
  55. }
  56. /// <summary>
  57. /// Currently selected set of resource UUIDs.
  58. /// </summary>
  59. public static string[] ResourceUUIDs
  60. {
  61. get
  62. {
  63. string[] selection;
  64. Internal_GetResourceUUIDSelection(out selection);
  65. return selection;
  66. }
  67. set
  68. {
  69. Internal_SetResourceUUIDSelection(value);
  70. }
  71. }
  72. /// <summary>
  73. /// Currently selected set of resource paths.
  74. /// </summary>
  75. public static string[] ResourcePaths
  76. {
  77. get
  78. {
  79. string[] selection;
  80. Internal_GetResourcePathSelection(out selection);
  81. return selection;
  82. }
  83. set
  84. {
  85. Internal_SetResourcePathSelection(value);
  86. }
  87. }
  88. /// <summary>
  89. /// Pings the resource, highlighting it in its respective editors.
  90. /// </summary>
  91. /// <param name="resource">Resource to highlight.</param>
  92. public static void Ping(Resource resource)
  93. {
  94. string path = ProjectLibrary.GetPath(resource);
  95. Internal_PingResource(path);
  96. }
  97. /// <summary>
  98. /// Pings the scene object, highlighting it in its respective editors.
  99. /// </summary>
  100. /// <param name="so">Scene object to highlight.</param>
  101. public static void Ping(SceneObject so)
  102. {
  103. Internal_PingSceneObject(so);
  104. }
  105. /// <summary>
  106. /// Triggered internally by the runtime when the selection changes.
  107. /// </summary>
  108. /// <param name="objects">Set of newly selected scene objects.</param>
  109. /// <param name="paths">Set of newly selected resource paths.</param>
  110. private static void Internal_TriggerSelectionChanged(SceneObject[] objects, string[] paths)
  111. {
  112. if (OnSelectionChanged != null)
  113. OnSelectionChanged(objects, paths);
  114. }
  115. /// <summary>
  116. /// Triggered internally by the runtime when the scene object ping is triggered.
  117. /// </summary>
  118. /// <param name="so">Scene object to highlight.</param>
  119. private static void Internal_TriggerSceneObjectPing(SceneObject so)
  120. {
  121. // Ignoring this until something needs this event
  122. }
  123. /// <summary>
  124. /// Triggered internally by the runtime when the resource ping is triggered.
  125. /// </summary>
  126. /// <param name="path">Path to the resource to highlight.</param>
  127. private static void Internal_TriggerResourcePing(string path)
  128. {
  129. if (OnResourcePing != null)
  130. OnResourcePing(path);
  131. }
  132. [MethodImpl(MethodImplOptions.InternalCall)]
  133. internal static extern void Internal_GetSceneObjectSelection(out SceneObject[] selection);
  134. [MethodImpl(MethodImplOptions.InternalCall)]
  135. internal static extern void Internal_SetSceneObjectSelection(SceneObject[] selection);
  136. [MethodImpl(MethodImplOptions.InternalCall)]
  137. internal static extern void Internal_GetResourceUUIDSelection(out string[] selection);
  138. [MethodImpl(MethodImplOptions.InternalCall)]
  139. internal static extern void Internal_SetResourceUUIDSelection(string[] selection);
  140. [MethodImpl(MethodImplOptions.InternalCall)]
  141. internal static extern void Internal_GetResourcePathSelection(out string[] selection);
  142. [MethodImpl(MethodImplOptions.InternalCall)]
  143. internal static extern void Internal_SetResourcePathSelection(string[] selection);
  144. [MethodImpl(MethodImplOptions.InternalCall)]
  145. internal static extern void Internal_PingResource(string resourcePath);
  146. [MethodImpl(MethodImplOptions.InternalCall)]
  147. internal static extern void Internal_PingSceneObject(SceneObject so);
  148. }
  149. }