// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; namespace FlaxEngine { partial class Level { /// /// Unloads all active scenes and loads the given scene (in the background). /// /// The scene asset identifier (scene to load). /// True if action fails (given asset is not a scene asset, missing data, scene loading error), otherwise false. public static bool ChangeSceneAsync(Guid sceneAssetId) { UnloadAllScenesAsync(); return LoadSceneAsync(sceneAssetId); } /// /// Unloads all active scenes and loads the given scene (in the background). /// /// The asset with the scene to load. /// True if action fails (given asset is not a scene asset, missing data, scene loading error), otherwise false. public static bool ChangeSceneAsync(SceneReference sceneAsset) { return ChangeSceneAsync(sceneAsset.ID); } /// /// Loads scene from the asset. /// /// The asset with the scene to load. /// True if action fails (given asset is not a scene asset, missing data, scene loading error), otherwise false. public static bool LoadScene(SceneReference sceneAsset) { return LoadScene(sceneAsset.ID); } /// /// Loads scene from the asset. Done in the background. /// /// The asset with the scene to load. /// True if failed (given asset is not a scene asset, missing data), otherwise false. public static bool LoadSceneAsync(SceneReference sceneAsset) { return LoadSceneAsync(sceneAsset.ID); } /// /// Tries to find script of the given type in all loaded scenes. /// /// Type of the object. /// Found script or null. public static T FindScript() where T : Script { return FindScript(typeof(T)) as T; } /// /// Tries to find actor of the given type in all loaded scenes. /// /// Type of the object. /// Found actor or null. public static T FindActor() where T : Actor { return FindActor(typeof(T)) as T; } /// /// Tries to find actor with the given ID in all loaded scenes. It's very fast O(1) lookup. /// /// Type of the object. /// The id. /// Found actor or null. public static T FindActor(ref Guid id) where T : Actor { return FindActor(id) as T; } /// /// Finds all the scripts of the given type in all the loaded scenes. /// /// Type of the object. /// Found scripts list. public static T[] GetScripts() where T : Script { var scripts = GetScripts(typeof(T)); var result = new T[scripts.Length]; for (int i = 0; i < scripts.Length; i++) result[i] = scripts[i] as T; return result; } /// /// Finds all the actors of the given type in all the loaded scenes. /// /// Type of the object. /// Found actors list. public static T[] GetActors() where T : Actor { var actors = GetActors(typeof(T)); var result = new T[actors.Length]; for (int i = 0; i < actors.Length; i++) result[i] = actors[i] as T; return result; } } }