//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System.Runtime.CompilerServices; namespace BansheeEngine { /** @addtogroup Scene * @{ */ /// /// Handles operations with the active scene (level). /// public static class Scene { /// /// Returns the name of the scene prefab. This is empty if scene hasn't been saved yet. /// public static string ActiveSceneName { get { return activeSceneName; } } /// /// Returns the UUID of the scene prefab. This is empty if scene hasn't been saved yet. /// internal static UUID ActiveSceneUUID { get { return activeSceneUUID; } } /// /// Checks is the loaded scene a generic scene object group, instead of an actual scene. /// . /// internal static bool IsGenericPrefab { get { return isGenericPrefab; } } private static string activeSceneName = "Unnamed"; private static UUID activeSceneUUID; private static bool isGenericPrefab = false; /// /// Returns the root scene object for the current scene. /// public static SceneObject Root { get { return Internal_GetRoot(); } } /// /// Returns the main camera that controls the final render surface that is displayed to the user. If the current /// scene has no main camera null is returned. /// public static Camera Camera { get { SceneObject so = Internal_GetMainCameraSO(); if (so == null) return null; return so.GetComponent(); } } /// /// Clears all scene objects from the current scene. /// public static void Clear() { Internal_ClearScene(); activeSceneUUID = UUID.Empty; activeSceneName = "Unnamed"; } /// /// Loads a new scene. /// /// Path to the prefab to load. public static void Load(string path) { Clear(); Prefab scene = Internal_LoadScene(path); SetActive(scene); } /// /// Sets the currently active scene to the provided scene. /// /// Scene which to set as active. internal static void SetActive(Prefab scene) { if (scene != null) { activeSceneUUID = scene.UUID; activeSceneName = scene.Name; isGenericPrefab = !scene.IsScene; } } /// /// Wrapper around scene name static field because Mono has problems accessing static fields directly. /// /// Name of the currently active scene. private static string GetSceneName() { return activeSceneName; } /// /// Wrapper around scene name static field because Mono has problems accessing static fields directly. /// /// Name of the currently active scene. private static void SetSceneName(string name) { activeSceneName = name; } /// /// Wrapper around scene UUID static field because Mono has problems accessing static fields directly. /// /// UUID of the currently active scene. private static UUID GetSceneUUID() { return activeSceneUUID; } /// /// Wrapper around scene UUID static field because Mono has problems accessing static fields directly. /// /// UUID of the currently active scene. private static void SetSceneUUID(UUID uuid) { activeSceneUUID = uuid; } /// /// Wrapper around the isGenericPrefab static field because Mono has problems accessing static fields directly. /// /// True if the loaded scene a generic scene object group, instead of an actual scene. private static bool GetIsGenericPrefab() { return isGenericPrefab; } /// /// Wrapper around scene UUID static field because Mono has problems accessing static fields directly. /// /// Determines is the loaded scene a generic scene object group, instead of an actual scene. /// private static void SetIsGenericPrefab(bool isGenericPrefab) { Scene.isGenericPrefab = isGenericPrefab; } [MethodImpl(MethodImplOptions.InternalCall)] private static extern Prefab Internal_LoadScene(string path); [MethodImpl(MethodImplOptions.InternalCall)] private static extern SceneObject Internal_GetRoot(); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_ClearScene(); [MethodImpl(MethodImplOptions.InternalCall)] private static extern SceneObject Internal_GetMainCameraSO(); } /** @} */ }