예제 #1
0
        /// <summary>
        /// A coroutine used to trigger the pause event
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator PauseButtonCo()
        {
            yield return(null);

            // we trigger a Pause event for the GameManager and other classes that could be listening to it too
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.TogglePause);
        }
        /// <summary>
        /// Initialization
        /// </summary>
        public virtual void Start()
        {
            if (Players == null || Players.Count == 0)
            {
                return;
            }

            Initialization();

            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.SpawnCharacterStarts);

            // we handle the spawn of the character(s)
            if (Players.Count == 1)
            {
                SpawnSingleCharacter();
            }
            else
            {
                SpawnMultipleCharacters();
            }

            LevelGUIStart();
            CheckpointAssignment();

            // we trigger a level start event
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.LevelStart);
            MMGameEvent.Trigger("Load");

            MMCameraEvent.Trigger(MMCameraEventTypes.SetConfiner, null, BoundsCollider);
            MMCameraEvent.Trigger(MMCameraEventTypes.SetTargetCharacter, Players[0]);
            MMCameraEvent.Trigger(MMCameraEventTypes.StartFollowing);
        }
예제 #3
0
        /// <summary>
        /// Initialization
        /// </summary>
        public virtual void Start()
        {
            if (Players == null || Players.Count == 0)
            {
                return;
            }

            Initialization();
            LevelGUIStart();

            // we handle the spawn of the character(s)
            if (Players.Count == 1)
            {
                SpawnSingleCharacter();
                InstantiateNoGoingBack();
            }
            else
            {
                SpawnMultipleCharacters();
            }

            CheckpointAssignment();

            // we trigger a level start event
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.LevelStart);
            MMGameEvent.Trigger("Load");
        }
예제 #4
0
 public void ReloadScene()
 {
     //LevelManager.Instance.GotoLevel(SceneManager.GetActiveScene().name);
     CorgiEngineEvent.Trigger(CorgiEngineEventTypes.UnPause);
     SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
     //LoadingSceneManager.LoadScene(SceneManager.GetActiveScene().name);
 }
예제 #5
0
        /// <summary>
        /// Waits for a short time and then loads the specified level
        /// </summary>
        /// <returns>The level co.</returns>
        /// <param name="levelName">Level name.</param>
        protected virtual IEnumerator GotoLevelCo(string levelName)
        {
            if (Players != null && Players.Count > 0)
            {
                foreach (Character player in Players)
                {
                    player.Disable();
                }
            }

            if (Time.timeScale > 0.0f)
            {
                yield return(new WaitForSeconds(OutroFadeDuration));
            }
            // we trigger an unPause event for the GameManager (and potentially other classes)
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.UnPause);

            if (string.IsNullOrEmpty(levelName))
            {
                LoadingSceneManager.LoadScene("StartScreen");
            }
            else
            {
                LoadingSceneManager.LoadScene(levelName);
            }
        }
        /// <summary>
        /// When getting game events, acts on them
        /// </summary>
        /// <param name="corgiEngineEvent"></param>
        public virtual void OnMMEvent(CorgiEngineEvent corgiEngineEvent)
        {
            if (corgiEngineEvent.EventType == CorgiEngineEventTypes.Respawn)
            {
                if (InstantRepositionCameraOnRespawn)
                {
                    TeleportCameraToTarget();
                }
            }

            if (corgiEngineEvent.EventType == CorgiEngineEventTypes.CharacterSwitch)
            {
                SetTarget(LevelManager.Instance.Players[0]);
                StartFollowing();
            }

            if (corgiEngineEvent.EventType == CorgiEngineEventTypes.CharacterSwap)
            {
                SetTarget(LevelManager.Instance.Players[0]);
                StartFollowing();
            }
            if (corgiEngineEvent.EventType == CorgiEngineEventTypes.FocusThenBack)
            {
                StartCoroutine(FocusThenBack(LevelManager.Instance.targetToFocus));
                //StartFollowing();
            }
        }
예제 #7
0
        /// <summary>
        /// Gets the player to the specified level
        /// </summary>
        /// <param name="levelName">Level name.</param>
        public virtual void GotoLevel(string levelName)
        {
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.LevelEnd);
            MMGameEvent.Trigger("Save");

            MMFadeInEvent.Trigger(OutroFadeDuration);
            StartCoroutine(GotoLevelCo(levelName));
        }
예제 #8
0
 /// <summary>
 /// If the pause button has been pressed, we change the pause state
 /// </summary>
 protected virtual void TriggerPause()
 {
     if (!AbilityPermitted &&
         (_condition.CurrentState == CharacterStates.CharacterConditions.Normal || _condition.CurrentState == CharacterStates.CharacterConditions.Paused))
     {
         return;
     }
     // we trigger a Pause event for the GameManager and other classes that could be listening to it too
     CorgiEngineEvent.Trigger(CorgiEngineEventTypes.Pause);
 }
예제 #9
0
/// Puts the game on pause
        public virtual void PauseButtonAction()
        {
            // we trigger a Pause event for the GameManager and other classes that could be listening to it too
            ToggleCharacter(); // if this isn't done, the character does not move after the pause event
            if (GameManager.Instance.Paused)
            {
                CorgiEngineEvent.Trigger(CorgiEngineEventTypes.UnPause);
            }
            else
            {
                CorgiEngineEvent.Trigger(CorgiEngineEventTypes.Pause);
            }
        }
예제 #10
0
        /// <summary>
        /// Catches CorgiEngineEvents and acts on them, playing the corresponding sounds
        /// </summary>
        /// <param name="engineEvent">CorgiEngineEvent event.</param>
        public virtual void OnMMEvent(CorgiEngineEvent engineEvent)
        {
            switch (engineEvent.EventType)
            {
            case CorgiEngineEventTypes.Pause:
                Pause();
                break;

            case CorgiEngineEventTypes.UnPause:
                UnPause();
                break;
            }
        }
예제 #11
0
        public virtual void OnMMEvent(CorgiEngineEvent corgiEngineEvent)
        {
            switch (corgiEngineEvent.EventType)
            {
            case CorgiEngineEventTypes.LevelEnd:
                MMAchievementManager.UnlockAchievement("PrincessInAnotherCastle");
                break;

            case CorgiEngineEventTypes.PlayerDeath:
                MMAchievementManager.UnlockAchievement("DeathIsOnlyTheBeginning");
                break;
            }
        }
        /// <summary>
        /// When we grab a level complete event, we update our status, and save our progress to file
        /// </summary>
        /// <param name="gameEvent">Game event.</param>
        public virtual void OnMMEvent(CorgiEngineEvent gameEvent)
        {
            switch (gameEvent.EventType)
            {
            case CorgiEngineEventTypes.LevelComplete:
                LevelComplete();
                SaveProgress();
                break;

            case CorgiEngineEventTypes.GameOver:
                GameOver();
                break;
            }
        }
        /// <summary>
        /// On LevelStart we initialize, on Respawn we reset our bounds values
        /// </summary>
        /// <param name="corgiEngineEvent"></param>
        public void OnMMEvent(CorgiEngineEvent corgiEngineEvent)
        {
            switch (corgiEngineEvent.EventType)
            {
            case CorgiEngineEventTypes.LevelStart:
                Initialization();
                break;

            case CorgiEngineEventTypes.Respawn:
                _minBoundsLastFrame           = LevelManager.Instance.LevelBounds.min;
                _maxBoundsLastFrame           = LevelManager.Instance.LevelBounds.max;
                OneWayLevelAutoScrolling      = _initialOneWayLevelAutoScrolling;
                OneWayLevelAutoScrollingSpeed = _initialOneWayLevelAutoScrollingSpeed;
                break;
            }
        }
 /// <summary>
 /// Watches for pause events to cut the sound on pause
 /// </summary>
 /// <param name="engineEvent"></param>
 public virtual void OnMMEvent(CorgiEngineEvent engineEvent)
 {
     if (engineEvent.EventType == CorgiEngineEventTypes.Pause)
     {
         if (MuteSfxOnPause)
         {
             MuteAllSfx();
         }
     }
     if (engineEvent.EventType == CorgiEngineEventTypes.UnPause)
     {
         if (MuteSfxOnPause)
         {
             UnmuteAllSfx();
         }
     }
 }
예제 #15
0
        /// <summary>
        /// Coroutine that kills the player, stops the camera, resets the points.
        /// </summary>
        /// <returns>The player co.</returns>
        protected virtual IEnumerator SoloModeRestart()
        {
            if (PlayerPrefabs.Count() <= 0)
            {
                yield break;
            }

            // if we've setup our game manager to use lives (meaning our max lives is more than zero)
            if (GameManager.Instance.MaximumLives > 0)
            {
                // we lose a life
                GameManager.Instance.LoseLife();
                // if we're out of lives, we check if we have an exit scene, and move there
                if (GameManager.Instance.CurrentLives <= 0)
                {
                    CorgiEngineEvent.Trigger(CorgiEngineEventTypes.GameOver);
                    if ((GameManager.Instance.GameOverScene != null) && (GameManager.Instance.GameOverScene != ""))
                    {
                        LoadingSceneManager.LoadScene(GameManager.Instance.GameOverScene);
                    }
                }
            }

            if (LevelCameraController != null)
            {
                LevelCameraController.FollowsPlayer = false;
            }

            yield return(new WaitForSeconds(RespawnDelay));

            if (LevelCameraController != null)
            {
                LevelCameraController.FollowsPlayer = true;
            }

            if (CurrentCheckPoint != null)
            {
                CurrentCheckPoint.SpawnPlayer(Players[0]);
            }
            _started = DateTime.UtcNow;
            // we send a new points event for the GameManager to catch (and other classes that may listen to it too)
            CorgiEnginePointsEvent.Trigger(PointsMethods.Set, 0);
            // we trigger a respawn event
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.Respawn);
        }
예제 #16
0
 /// <summary>
 /// When we detect a character switch, we equip the current weapon if AutoEquipWeaponOnCharacterSwitch is true
 /// </summary>
 /// <param name="corgiEngineEvent"></param>
 public virtual void OnMMEvent(CorgiEngineEvent corgiEngineEvent)
 {
     if (corgiEngineEvent.EventType == CorgiEngineEventTypes.CharacterSwitch)
     {
         if (!AutoEquipWeaponOnCharacterSwitch)
         {
             return;
         }
         this.Setup();
         if (WeaponInventory != null)
         {
             if (!InventoryItem.IsNull(WeaponInventory.Content[0]))
             {
                 _characterHandleWeapon.Setup();
                 WeaponInventory.Content[0].Equip();
             }
         }
     }
 }
        /// <summary>
        /// Gets the player to the specified level
        /// </summary>
        /// <param name="levelName">Level name.</param>
        public virtual void GotoLevel(string levelName, bool fadeOut = true)
        {
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.LevelEnd);
            MMGameEvent.Trigger("Save");

            if (fadeOut)
            {
                if (Players.Count > 0)
                {
                    MMFadeInEvent.Trigger(OutroFadeDuration, FadeTween, FaderID, true, Players[0].transform.position);
                }
                else
                {
                    MMFadeInEvent.Trigger(OutroFadeDuration, FadeTween, FaderID, true, Vector3.zero);
                }
            }

            StartCoroutine(GotoLevelCo(levelName, fadeOut));
        }
        /// <summary>
        /// Sets a target for this camera to look at then back to character
        /// </summary>
        /// <param name="target"></param>
        public virtual IEnumerator FocusThenBack(Transform target)
        {
            CorgiEngineEvent swapEvent = new CorgiEngineEvent(CorgiEngineEventTypes.CharacterSwap);

            CharacterSwapManager.DisableSwap();
            InputManager.Instance.SetHorizontalMovement(0);
            InputManager.Instance.InputDetectionActive = false;
            var _targetController = TargetController;
            var _targetCharacter  = TargetCharacter;

            _virtualCamera.Follow     = target;
            _targetController.enabled = false;
            yield return(new WaitForSeconds(2f));

            MMEventManager.TriggerEvent(swapEvent);
            CharacterSwapManager.EnableSwap();
            InputManager.Instance.InputDetectionActive = true;
            _targetController.enabled = true;
        }
        /// <summary>
        /// Waits for a short time and then loads the specified level
        /// </summary>
        /// <returns>The level co.</returns>
        /// <param name="levelName">Level name.</param>
        protected virtual IEnumerator GotoLevelCo(string levelName, bool fadeOut = true)
        {
            if (Players != null && Players.Count > 0)
            {
                foreach (Character player in Players)
                {
                    player.Disable();
                }
            }

            if (fadeOut)
            {
                if (Time.timeScale > 0.0f)
                {
                    yield return(new WaitForSeconds(OutroFadeDuration));
                }
                else
                {
                    yield return(new WaitForSecondsRealtime(OutroFadeDuration));
                }
            }

            // we trigger an unPause event for the GameManager (and potentially other classes)
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.UnPause);
            CorgiEngineEvent.Trigger(CorgiEngineEventTypes.LoadNextScene);


            if (string.IsNullOrEmpty(levelName))
            {
                //DongDD fix
//				LoadingSceneManager.LoadScene("StartScreen");
                Application.backgroundLoadingPriority = ThreadPriority.High;
                SceneManager.LoadScene("StartScreen");
            }
            else
            {
                //DongDD fix
//				LoadingSceneManager.LoadScene(levelName);
                Application.backgroundLoadingPriority = ThreadPriority.High;
                SceneManager.LoadScene(levelName);
            }
        }
        /// <summary>
        /// Kills the player.
        /// </summary>
        public virtual void KillPlayer(Character player)
        {
            Health characterHealth = player.GetComponent <Health>();

            if (characterHealth == null)
            {
                return;
            }
            else
            {
                // we kill the character
                characterHealth.Kill();
                CorgiEngineEvent.Trigger(CorgiEngineEventTypes.PlayerDeath);

                // if we have only one player, we restart the level
                if (Players.Count < 2)
                {
                    StartCoroutine(SoloModeRestart());
                }
            }
        }
        /// <summary>
        /// When we get a Corgi Engine event, we act on it
        /// </summary>
        /// <param name="gameEvent"></param>
        public virtual void OnMMEvent(CorgiEngineEvent engineEvent)
        {
            if (!AbilityAuthorized)
            {
                return;
            }

            if (engineEvent.EventType == CorgiEngineEventTypes.LoadNextScene)
            {
                this.gameObject.SetActive(false);
            }

            if (engineEvent.EventType == CorgiEngineEventTypes.SpawnCharacterStarts)
            {
                this.gameObject.SetActive(true);
                Character character = this.gameObject.GetComponentInParent <Character>();
                character.enabled = true;
                character.ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal);
                character.MovementState.ChangeState(CharacterStates.MovementStates.Idle);
                character.GetMainCamera();
                character.SetInputManager();
            }
        }
        /// <summary>
        /// Catches CorgiEngineEvents and acts on them, playing the corresponding sounds
        /// </summary>
        /// <param name="engineEvent">CorgiEngineEvent event.</param>
        public override void OnMMEvent(CorgiEngineEvent engineEvent)
        {
            switch (engineEvent.EventType)
            {
            case CorgiEngineEventTypes.TogglePause:
                if (Paused)
                {
                    CorgiEngineEvent.Trigger(CorgiEngineEventTypes.UnPause);
                }
                else
                {
                    CorgiEngineEvent.Trigger(CorgiEngineEventTypes.Pause);
                }
                break;

            case CorgiEngineEventTypes.Pause:
                PauseGame();
                break;

            case CorgiEngineEventTypes.UnPause:
                UnPauseGame();
                break;
            }
        }
예제 #23
0
 public void LoadScene(string level)
 {
     CorgiEngineEvent.Trigger(CorgiEngineEventTypes.UnPause);
     SceneManager.LoadScene(level, LoadSceneMode.Single);
 }
예제 #24
0
 public void Unpause()
 {
     CorgiEngineEvent.Trigger(CorgiEngineEventTypes.UnPause);
 }
 /// <summary>
 /// Loads the next level
 /// </summary>
 public override void GoToNextLevel()
 {
     CorgiEngineEvent.Trigger(CorgiEngineEventTypes.LevelComplete);
     MMGameEvent.Trigger("Save");
     LevelManager.Instance.SetNextLevel(LevelName);
 }
예제 #26
0
 /// <summary>
 /// Restarts the current level
 /// </summary>
 public virtual void RestartLevel()
 {
     // we trigger an unPause event for the GameManager (and potentially other classes)
     CorgiEngineEvent.Trigger(CorgiEngineEventTypes.UnPause);
     LoadingSceneManager.LoadScene(SceneManager.GetActiveScene().name);
 }
예제 #27
0
 /// Puts the game on pause
 public virtual void PauseButtonAction()
 {
     // we trigger a Pause event for the GameManager and other classes that could be listening to it too
     CorgiEngineEvent.Trigger(CorgiEngineEventTypes.Pause);
 }