Selection.cs 6.0 KB

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