internal static void RemoveScene(AppScene scene) { if (!s_isDisposing) { lock (s_scenes) { s_scenes.Remove(scene); } } }
/// <summary> /// Queues a change of the active scene to the passed scene. This will notify the current active scene of the /// pending change. The actual change will not start until the next application frame. /// </summary> /// <param name="newScene">The new scene to change to, can be null if no scene should be shown.</param> public static void ChangeScene(AppScene newScene /* TODO: Scene Transitions */) { if (newScene != null && ReferenceEquals(newScene, ActiveScene)) { throw new ArgumentException("Cannot change the active scene to the same scene instance"); } if (s_queuedScene != null) { throw new InvalidOperationException("Cannot queue a scene change if there is already a change in progress"); } s_queuedScene = newScene; SceneChanging = true; // Notify s_queuedScene?.QueueChange(false); ActiveScene?.QueueChange(false); }
internal static void Shutdown() { // Deal with active scene ActiveScene?.QueueChange(false); ActiveScene?.Remove(); ActiveScene?.Dispose(); ActiveScene = null; // Might be a queued scene s_queuedScene?.Dispose(); s_queuedScene = null; // Deal with other cached states s_isDisposing = true; s_scenes.ForEach(scene => scene.Dispose()); s_scenes.Clear(); s_isDisposing = false; }
// Called to perform the actual transition between active scenes private static void DoSceneChange() { // Remove the current scene, and GC collect as there may be many objects released in the disposal ActiveScene?.Remove(); ActiveScene?.Dispose(); if (ActiveScene != null) { GC.Collect(); } // Load the new scene, and GC collect to remove the many temporary objects created during loading ActiveScene = s_queuedScene; ActiveScene?.Start(); s_queuedScene = null; if (ActiveScene != null) { GC.Collect(); } SceneChanging = false; }