//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; using bs; namespace bs.Editor { /** @addtogroup General * @{ */ /// /// Handles scene object and resource selection. Triggeres events when selection changes and allows the user to query /// current selection state. /// public sealed class Selection { /// /// Triggered whenever scene object or resource selection changes. The provided parameters will contain the newly /// selected objects/resource paths. /// public static Action OnSelectionChanged; /// /// Triggered when a resource ping is requested. Ping usually means the object will be highlighted in its respective /// editors. /// internal static Action OnResourcePing; /// /// Currently selected scene object. If more than one object is selected, this returns the first one. /// public static SceneObject SceneObject { get { SceneObject[] selection; Internal_GetSceneObjectSelection(out selection); if(selection.Length > 0) return selection[0]; return null; } set { Internal_SetSceneObjectSelection(new SceneObject[] { value }); } } /// /// Currently selected set of scene objects. /// public static SceneObject[] SceneObjects { get { SceneObject[] selection; Internal_GetSceneObjectSelection(out selection); return selection; } set { Internal_SetSceneObjectSelection(value); } } /// /// Currently selected set of resource UUIDs. /// public static string[] ResourceUUIDs { get { string[] selection; Internal_GetResourceUUIDSelection(out selection); return selection; } set { Internal_SetResourceUUIDSelection(value); } } /// /// Currently selected set of resource paths. /// public static string[] ResourcePaths { get { string[] selection; Internal_GetResourcePathSelection(out selection); return selection; } set { Internal_SetResourcePathSelection(value); } } /// /// Pings the resource, highlighting it in its respective editors. /// /// Resource to highlight. public static void Ping(Resource resource) { string path = ProjectLibrary.GetPath(resource); Internal_PingResource(path); } /// /// Pings the scene object, highlighting it in its respective editors. /// /// Scene object to highlight. public static void Ping(SceneObject so) { Internal_PingSceneObject(so); } /// /// Triggered internally by the runtime when the selection changes. /// /// Set of newly selected scene objects. /// Set of newly selected resource paths. private static void Internal_TriggerSelectionChanged(SceneObject[] objects, string[] paths) { if (OnSelectionChanged != null) OnSelectionChanged(objects, paths); } /// /// Triggered internally by the runtime when the scene object ping is triggered. /// /// Scene object to highlight. private static void Internal_TriggerSceneObjectPing(SceneObject so) { // Ignoring this until something needs this event } /// /// Triggered internally by the runtime when the resource ping is triggered. /// /// Path to the resource to highlight. private static void Internal_TriggerResourcePing(string path) { if (OnResourcePing != null) OnResourcePing(path); } [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Internal_GetSceneObjectSelection(out SceneObject[] selection); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Internal_SetSceneObjectSelection(SceneObject[] selection); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Internal_GetResourceUUIDSelection(out string[] selection); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Internal_SetResourceUUIDSelection(string[] selection); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Internal_GetResourcePathSelection(out string[] selection); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Internal_SetResourcePathSelection(string[] selection); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Internal_PingResource(string resourcePath); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Internal_PingSceneObject(SceneObject so); } /** @} */ }