/// <summary> /// Pauses the current scene and makes the given scene the new /// active scene. It MUST be already attached to the manager. /// Does NOT remove the old active scene. /// If the new scene is unloaded, it will be automatically loaded. /// </summary> /// <param name="newScenesName"></param> public void SwapScene(Scene.Name newScenesName) { Scene newScene = this.FindScene(newScenesName); Debug.Assert(newScene != null, "The Scene could not be found upon swapping a scene!"); // Pause the old Scene Debug.Assert(this.activeScene != null, "Swapping a Scene requires an Active Scene to exist!"); this.activeScene.PauseScene(); AudioSourceManager.Self.StopAllAudio(); // Delete the old Scene if it was marked for deletion if (this.activeScene.IsMarkedForRemoval) { this.UnloadScene(this.ActiveSceneName); } this.activeScene = null; // Load or unpause the new Scene this.activeScene = newScene; if (newScene.IsLoaded) { if (newScene.IsPaused) { this.activeScene.UnpauseScene(this.AzulClockTime); } } else { this.activeScene.LoadScene(); } }
// // Constructors // public Scene() { // Make all the managers this.manAnimationFlip = new AnimationFlipManager(2, 1); this.manAnimationFrame = new AnimationFrameManager(4, 1); this.manAnimationMotion = new AnimationMotionManager(1, 1); this.manCollisionPair = new CollisonPairManager(13, 1); this.manGameObject = new GameObjectManager(50, 10); this.manSpriteBatch = new SpriteBatchManager(7, 1); this.manSpriteProxy = new SpriteProxyManager(50, 10); this.manSpriteColProxy = new SpriteCollisonProxyManager(50, 10); this.manTimedEvent = new TimedEventManager(10, 1, SceneManager.Self.AzulClockTime); // Make all the other containers this.gameData = new GameSessionData(); this.hudDisplay = this.CreateHud(); this.collisionBatch = this.manSpriteBatch.Find(SpriteBatch.Name.SpriteCollisions); this.collisionBatch.IsEnabled = false; // Set scene data this.name = Name.UNINITIALIZED; this.lastAzulTime = 0.0f; this.alienCoordinatorId = 0u; this.ufoId = 0u; this.isLoaded = false; this.isPaused = false; this.isMarkedForSceneChange = false; this.isMarkedForRemoval = false; }
/// <summary> /// Finds a Scene in the manager and returns it /// </summary> /// <param name="name"></param> /// <returns></returns> public Scene FindScene(Scene.Name name) { Debug.Assert(name != Scene.Name.UNINITIALIZED, "Trying to find an unitialized Scene!"); SceneHolder holder = this.BaseFind(name, this.activeList) as SceneHolder; if (holder == null) { return(null); } return(holder.SceneRef); }
/// <summary> /// Load an already attached Scene. Makes it the active Scene. /// Removes the old active scene. /// </summary> /// <param name="sceneName"></param> public void LoadScene(Scene.Name newScenesName) { // Find the new scene Scene newScene = this.FindScene(newScenesName); Debug.Assert(newScene != null, "The Scene could not be found upon loading a scene by name!"); // Unload the old active scene if any if (activeScene != null) { bool wasRemoved = this.UnloadScene(ActiveSceneName); Debug.Assert(wasRemoved, "Upon loading a new Scene, the old Scene was not successfuly removed!"); this.activeScene = null; } // Make the new scene the active scene this.activeScene = newScene; Debug.Assert(newScene.IsPaused == false, "Loading a new Scene should not be paused!"); this.activeScene.LoadScene(); }
/// <summary> /// Removes a Scene from the manager, given the scene's name /// </summary> /// <param name="oldName"></param> /// <returns></returns> public bool UnloadScene(Scene.Name oldName) { SceneHolder oldHolder = this.BaseRecycle(oldName) as SceneHolder; if (oldHolder == null) { return(false); } // Make the active scene null if it's being removed //if(this.activeScene == oldHolder.SceneRef) //{ // this.activeScene = null; //} // Reset the holder, which unloads the Scene internally oldHolder.Reset(); AudioSourceManager.Self.StopAllAudio(); // Good time to call Garbage collector MemoryJunkyard.Self.RecycleYard(); return(true); }