예제 #1
0
    public void EnterFeature <TEnterState>(object transitionInfo         = null,
                                           TransitionType transitionType = TransitionType.FastTransition) where TEnterState : State
    {
        _nguiTransitionController.ShowTransition(transitionType);

        // Delay one frame to allow transition screen to show, just in case this EnterState will block immediately
        _coroutineCreator.DelayActionOneFrame(() => {
            _stateController.EnterState(typeof(TEnterState), transitionInfo);
        });
    }
    private void ContinueEnteringState(State enterState, object transitionInfo, Action preEnterStateCallback = null)
    {
        //TODO This is a temporary fix for making sure that the Exiting of a current state and entering of the new state do not occur in the same frame.
        //Cleaner solution would be to make the EnterState function a co routine and yielding a frame after Exiting and before calling the enter function of the next state.
        _coroutineCreator.DelayActionOneFrame(() =>
        {
                        #if METRICS_ENABLED && INCLUDE_DEV_METRICS
            Metrics.Start(GetType().Name + ":Enter:" + enterState.Name);
                        #endif

            int cleanupFrequency = _config.GetUnloadUnusedAssetsEachStateFrequency();
            if (cleanupFrequency > 0 && ++_stateEnterCounter >= cleanupFrequency)
            {
                Resources.UnloadUnusedAssets();
                GC.Collect();
                _stateEnterCounter = 0;
            }

            // Set TimeEntered before SC_Enter because State implementations can perform initialization functions before
            // the base class SC_Enter gets called.  So we want this called before all that happens.
            enterState.TimeEntered = Time.realtimeSinceStartup;

            // Callback used for actions that need to happen before SC_Enter, but after DelayActionOneFrame and setting of TimeEntered
            if (preEnterStateCallback != null)
            {
                preEnterStateCallback();
            }

            // Initialize & in the process, kick off the transition sequence
            if (!enterState.SC_Enter(transitionInfo, OnEnterComplete))
            {
                                #if METRICS_ENABLED && INCLUDE_DEV_METRICS
                Metrics.End(GetType().Name + ":Enter:" + enterState.Name);
                                #endif
                // State failed to start
                ExitState(enterState, false);
            }
        });
    }