Example #1
0
        void TransitionToState(State newState)
        {
            Debug.LogFormat("MatchController State {0} -> {1}", m_currentState, newState);

            if (m_currentState != newState)
            {
                var oldState = m_currentState;
                m_currentState = newState;

                // state transition logic
                switch (newState)
                {
                case State.NONE:
                    SetupForIdle();
                    MoveCameraToIdlePosition();
                    PlatformManager.TransitionToState(PlatformManager.State.WAITING_TO_PRACTICE_OR_MATCHMAKE);
                    m_matchmakeButtonText.text = "Play Online";
                    break;

                case State.WAITING_TO_START_PRACTICE:
                    Assert.AreEqual(oldState, State.NONE);
                    SetupForPractice();
                    MoveCameraToMatchPosition();
                    PlatformManager.TransitionToState(PlatformManager.State.MATCH_TRANSITION);
                    m_nextStateTransitionTime = Time.time + PRACTICE_WARMUP_TIME;
                    break;

                case State.PRACTICING:
                    Assert.AreEqual(oldState, State.WAITING_TO_START_PRACTICE);
                    PlatformManager.TransitionToState(PlatformManager.State.PLAYING_A_LOCAL_MATCH);
                    m_nextStateTransitionTime = Time.time + MATCH_TIME;
                    break;

                case State.VIEWING_RESULTS_PRACTICE:
                    Assert.AreEqual(oldState, State.PRACTICING);
                    PlatformManager.TransitionToState(PlatformManager.State.MATCH_TRANSITION);
                    m_nextStateTransitionTime = Time.time + MATCH_COOLDOWN_TIME;
                    m_timerText.text          = "0:00.00";
                    break;

                case State.WAITING_FOR_MATCH:
                    Assert.AreEqual(oldState, State.NONE);
                    PlatformManager.TransitionToState(PlatformManager.State.MATCH_TRANSITION);
                    m_matchmakeButtonText.text = "Cancel";
                    break;

                case State.WAITING_TO_SETUP_MATCH:
                    Assert.AreEqual(oldState, State.WAITING_FOR_MATCH);
                    m_nextStateTransitionTime = Time.time + MATCH_WARMUP_TIME;
                    break;

                case State.PLAYING_MATCH:
                    Assert.AreEqual(oldState, State.WAITING_TO_SETUP_MATCH);
                    PlatformManager.TransitionToState(PlatformManager.State.PLAYING_A_NETWORKED_MATCH);
                    m_nextStateTransitionTime = Time.time + MATCH_TIME;
                    break;

                case State.VIEWING_MATCH_RESULTS:
                    Assert.AreEqual(oldState, State.PLAYING_MATCH);
                    PlatformManager.TransitionToState(PlatformManager.State.MATCH_TRANSITION);
                    m_nextStateTransitionTime = Time.time + MATCH_COOLDOWN_TIME;
                    m_timerText.text          = "0:00.00";
                    CalculateMatchResults();
                    break;
                }
            }
        }