Scene.cs 3.2 KB

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