/// <summary> /// Sets the game scene identifier. /// </summary> /// <param name="gameSceneIdentifier">Game scene identifier.</param> public void SetGameScene(GameSceneIdentifier gameSceneIdentifier) { // First check if the specified game scene identifier differs from // the current game scene identifier... if (this.GameSceneIdentifier != gameSceneIdentifier) { // ... it does so call a method to handle any actions we may // need to perform when the game scene identifier is changed. OnGameSceneChange(gameSceneIdentifier); } }
/// <summary> /// Initializes a new instance of the <see cref="GameSceneChangingEventArgs"/> class. /// </summary> /// <param name="currentSceneIdentifier"> /// Indicates the identifier of the current scene before the scene change. /// </param> /// <param name="prospectiveSceneIdentifier"> /// Indicates identifier of what the new scene will be after the change. /// </param> internal GameSceneChangingEventArgs(GameSceneIdentifier currentSceneIdentifier, GameSceneIdentifier prospectiveSceneIdentifier) { CurrentSceneIdentifier = currentSceneIdentifier; ProspectiveSceneIdentifier = prospectiveSceneIdentifier; }
/// <summary> /// Called when the game scene needs to be changed /// </summary> /// <param name="newGameSceneIdentifier">The new game scene identifier.</param> private void OnGameSceneChange(GameSceneIdentifier newGameSceneIdentifier) { // We will capture the 'Original' scene as we will need to know what // it originally was after it has changed GameSceneIdentifier originalSceneIdentifier = this.GameSceneIdentifier; // Create the game scene transition we are about to make happen and // use this in the rule engine to validate that the game scene // transition is valid. GameSceneTransition sceneTransition = new GameSceneTransition(originalSceneIdentifier, newGameSceneIdentifier); RuleEngine.ActualValue = sceneTransition; // A valid transitoin is one which matches ANY of the rules bool isValidTransition = RuleEngine.MatchAny(); // Check if the transition is valid... if (!isValidTransition) { // It's not so we will check the GameSceneTransitionFailedCallback // has a reference and call that with a parameter indicating the reason CallGameSceneTransitionFailedCallBackIfRequired(GameSceneTransitionFailedReasons.InvalidTransition); // Exit the method return; } // As we intend to raise an event before the same scene is changed // in case any subscribers wish to cancel the scene change we need a // flag which we can use to signify cancellation. Initially we will // assume the game scene wont be cancelled... bool cancelled = false; // Raise the game scene changing event to give any subscribers chance // to cancel this process State.GameManager.EventManager.RaiseGameSceneChangingEvent(originalSceneIdentifier, newGameSceneIdentifier, ref cancelled); // Check to see if the event was cancelled... if (cancelled) { // ... it was so we will check the GameSceneTransitionFailedCallback // has a reference and call that with a parameter indicating the reason CallGameSceneTransitionFailedCallBackIfRequired(GameSceneTransitionFailedReasons.CancelledTransition); // Exit the method return; } // Getting here indicates that the event was not cancelled, so // we can actually set the game scene! this.GameSceneIdentifier = newGameSceneIdentifier; // Raise the game scene changed event to notify any listeners that // the game state has changed. State.GameManager.EventManager.RaiseGameSceneChangedEvent(originalSceneIdentifier, newGameSceneIdentifier); }
/// <summary> /// Initializes a new instance of the <see cref="GameSceneChangedEventArgs"/> class. /// </summary> /// <param name="currentSceneIdentifier"> /// Indicates the identifier of the current game scene after the change happened. /// </param> /// <param name="originalSceneIdentifier"> /// Indicates the identifier of the original game scene before the change happened. /// </param> public GameSceneChangedEventArgs(GameSceneIdentifier currentSceneIdentifier, GameSceneIdentifier originalSceneIdentifier) { CurrentSceneIdentifier = currentSceneIdentifier; OriginalSceneIdentifier = originalSceneIdentifier; }