EditorUtility.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Collections.Generic;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. public class EditorUtility
  7. {
  8. public static AABox CalculateBounds(SceneObject so)
  9. {
  10. AABox bounds;
  11. Internal_CalculateBounds(so, out bounds);
  12. return bounds;
  13. }
  14. public static AABox CalculateBounds(SceneObject[] objects)
  15. {
  16. AABox bounds;
  17. Internal_CalculateBoundsArray(objects, out bounds);
  18. return bounds;
  19. }
  20. public static SceneObject[] FlattenHierarchy(SceneObject so)
  21. {
  22. Stack<SceneObject> todo = new Stack<SceneObject>();
  23. todo.Push(so);
  24. List<SceneObject> flattenedHierarchy = new List<SceneObject>();
  25. while (todo.Count > 0)
  26. {
  27. SceneObject cur = todo.Pop();
  28. flattenedHierarchy.Add(cur);
  29. int numChildren = cur.GetNumChildren();
  30. for (int i = 0; i < numChildren; i++)
  31. todo.Push(cur.GetChild(i));
  32. }
  33. return flattenedHierarchy.ToArray();
  34. }
  35. [MethodImpl(MethodImplOptions.InternalCall)]
  36. private static extern void Internal_CalculateBounds(SceneObject so, out AABox bounds);
  37. [MethodImpl(MethodImplOptions.InternalCall)]
  38. private static extern void Internal_CalculateBoundsArray(SceneObject[] objects, out AABox bounds);
  39. }
  40. }