Scene.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Runtime.CompilerServices;
  2. namespace BansheeEngine
  3. {
  4. /// <summary>
  5. /// Handles operations with the active scene (level).
  6. /// </summary>
  7. public static class Scene
  8. {
  9. /// <summary>
  10. /// Returns the name of the scene prefab. This is empty if scene hasn't been saved yet.
  11. /// </summary>
  12. public static string ActiveSceneName { get { return activeSceneName; } }
  13. /// <summary>
  14. /// Returns the UUID of the scene prefab. This is empty if scene hasn't been saved yet.
  15. /// </summary>
  16. internal static string ActiveSceneUUID { get { return activeSceneUUID; } }
  17. private static string activeSceneName = "Unnamed";
  18. private static string activeSceneUUID = "";
  19. /// <summary>
  20. /// Returns the root scene object for the current scene.
  21. /// </summary>
  22. public static SceneObject Root
  23. {
  24. get { return Internal_GetRoot(); }
  25. }
  26. /// <summary>
  27. /// Returns the main camera that controls the final render surface that is displayed to the user. If the current
  28. /// scene has no main camera null is returned.
  29. /// </summary>
  30. public static Camera Camera
  31. {
  32. get
  33. {
  34. SceneObject so = Internal_GetMainCameraSO();
  35. if (so == null)
  36. return null;
  37. return so.GetComponent<Camera>();
  38. }
  39. }
  40. /// <summary>
  41. /// Clears all scene objects from the current scene.
  42. /// </summary>
  43. public static void Clear()
  44. {
  45. Internal_ClearScene();
  46. activeSceneUUID = null;
  47. activeSceneName = "Unnamed";
  48. }
  49. /// <summary>
  50. /// Loads a new scene.
  51. /// </summary>
  52. /// <param name="path">Path to the prefab to load.</param>
  53. public static void Load(string path)
  54. {
  55. Clear();
  56. Prefab scene = Internal_LoadScene(path);
  57. SetActive(scene);
  58. }
  59. /// <summary>
  60. /// Sets the currently active scene to the provided scene.
  61. /// </summary>
  62. /// <param name="scene">Scene which to set as active.</param>
  63. internal static void SetActive(Prefab scene)
  64. {
  65. if (scene != null)
  66. {
  67. activeSceneUUID = scene.UUID;
  68. activeSceneName = scene.Name;
  69. }
  70. }
  71. [MethodImpl(MethodImplOptions.InternalCall)]
  72. private static extern Prefab Internal_LoadScene(string path);
  73. [MethodImpl(MethodImplOptions.InternalCall)]
  74. private static extern SceneObject Internal_GetRoot();
  75. [MethodImpl(MethodImplOptions.InternalCall)]
  76. private static extern void Internal_ClearScene();
  77. [MethodImpl(MethodImplOptions.InternalCall)]
  78. private static extern SceneObject Internal_GetMainCameraSO();
  79. }
  80. }