//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using bs; namespace bs.Editor { /** @addtogroup Utility-Editor * @{ */ /// /// Contains various utility methods used throughout the editor. /// public class EditorUtility { /// /// Calculates the axis aligned box that encapsulated the provided scene object and its components and children. /// Only certain components like will be included in bound calculations. /// /// Scene object to calculate the bounds for. /// Axis aligned box encompassing all scene object elements, in world space. public static AABox CalculateBounds(SceneObject so) { AABox bounds; Internal_CalculateBounds(so, out bounds); return bounds; } /// /// Calculates the axis aligned box that encapsulated the provided scene objects and their components and children. /// Only certain components like will be included in bound calculations. /// /// Scene objects to calculate the bounds for. /// Axis aligned box encompassing all scene object elements, in world space. public static AABox CalculateBounds(SceneObject[] objects) { AABox bounds; Internal_CalculateBoundsArray(objects, out bounds); return bounds; } /// /// Calculates the center of all axis aligned boxes of the provided scene objects. /// Only certain components like will be included in center calculations. /// /// Scene objects to calculate the center for. /// Center of the objects group in world space. public static Vector3 CalculateCenter(SceneObject[] objects) { Vector3 center; Internal_CalculateArrayCenter(objects, out center); return center; } /// /// Converts a hierarchy of scene objects and their children into a flat array. Doesn't modify the scene object's /// themselves. /// /// Scene object whose hierarchy to flatten. /// Array of flattened hierarchy in a depth-first manner. public static SceneObject[] FlattenHierarchy(SceneObject so) { Stack todo = new Stack(); todo.Push(so); List flattenedHierarchy = new List(); while (todo.Count > 0) { SceneObject cur = todo.Pop(); flattenedHierarchy.Add(cur); int numChildren = cur.GetNumChildren(); for (int i = 0; i < numChildren; i++) todo.Push(cur.GetChild(i)); } return flattenedHierarchy.ToArray(); } /// /// Find all resources that the provided resource depends on. /// /// Resource whose dependencies to find. /// Determines whether or not child objects will also be searched (if object has any /// children). /// All resources the provided resource is dependant on (does not include itself). public static Resource[] FindDependencies(Resource resource, bool recursive = true) { return Internal_FindDependencies(resource, recursive); } /// /// Checks is the provided scene object internal (hidden from normal user, used by internal engine systems). /// /// Scene object to check. /// True if internal, false otherwise. public static bool IsInternal(SceneObject so) { if (so == null) return false; IntPtr objPtr = so.GetCachedPtr(); return Internal_IsInternal(objPtr); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CalculateBounds(SceneObject so, out AABox bounds); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CalculateBoundsArray(SceneObject[] objects, out AABox bounds); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CalculateArrayCenter(SceneObject[] objects, out Vector3 center); [MethodImpl(MethodImplOptions.InternalCall)] private static extern Resource[] Internal_FindDependencies(Resource resource, bool recursive); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Internal_IsInternal(IntPtr soPtr); } /** @} */ }