Selection.cs 6.0 KB

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