Ejemplo n.º 1
0
        private IEnumerator loadScene(string sceneName, LuaTable newStage)
        {
            LuaTable lastStage = curStage;

            curStage = newStage;


            CallFunction(lastStage, "onExit");

            stageLoader = new StageLoader();
            CallFunction(newStage, "onEnter", stageLoader);

            while (stageLoader.MoveNext())
            {
                yield return(null);
            }

            UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);

            while (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name != sceneName)
            {
                yield return(null);
            }

            //wait a frame
            yield return(null);

            this.OnCompleted();

            CallFunction(newStage, "onShow");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method actually does the transition. It is run in a coroutine and therefore needs to do
        /// yield returns to play an animation or do another progress over time. When this method returns
        /// the transition is expected to be finished.
        /// </summary>
        /// <returns>
        /// A <see cref="IEnumerator"/> for showing the transition status. Use yield return statements to keep
        /// the transition running, otherwise simply end the method to stop the transition.
        /// </returns>
        protected virtual IEnumerator DoTransition()
        {
            // make sure the transition doesn't get lost when switching the level.
            DontDestroyOnLoad(gameObject);

            if (prefetchLevel)
            {
                state = SMTransitionState.Prefetch;
                SendMessage("SMBeforeTransitionPrefetch", this, SendMessageOptions.DontRequireReceiver);
                yield return(0); // wait one frame

                SendMessage("SMOnTransitionPrefetch", this, SendMessageOptions.DontRequireReceiver);

                if (Loader != null)
                {
                    while (Loader.MoveNext())
                    {
                        yield return(0);
                    }
                }
            }

            state = SMTransitionState.Out;
            SendMessage("SMBeforeTransitionOut", this, SendMessageOptions.DontRequireReceiver);
            Prepare();
            SendMessage("SMOnTransitionOut", this, SendMessageOptions.DontRequireReceiver);
            float time = 0;

            while (Process(time))
            {
                time += DeltaTime;
                // wait for the next frame
                yield return(0);
            }

            SendMessage("SMAfterTransitionOut", this, SendMessageOptions.DontRequireReceiver);
            // wait another frame...
            yield return(0);

            state = SMTransitionState.Hold;
            SendMessage("SMBeforeTransitionHold", this, SendMessageOptions.DontRequireReceiver);
            SendMessage("SMOnTransitionHold", this, SendMessageOptions.DontRequireReceiver);

            // wait another frame...
            yield return(0);


            if (!prefetchLevel && Loader != null)
            {
                // level is not prefetched, load it right now.
                while (Loader.MoveNext())
                {
                    yield return(0);
                }
            }

            SendMessage("SMAfterTransitionHold", this, SendMessageOptions.DontRequireReceiver);
            // wait another frame...
            yield return(0);

            state = SMTransitionState.In;
            SendMessage("SMBeforeTransitionIn", this, SendMessageOptions.DontRequireReceiver);
            Prepare();
            SendMessage("SMOnTransitionIn", this, SendMessageOptions.DontRequireReceiver);
            time = 0;

            while (Process(time))
            {
                time += DeltaTime;
                // wait for the next frame
                yield return(0);
            }

            sceneStageMgr.OnCompleted();
            SendMessage("SMAfterTransitionIn", this, SendMessageOptions.DontRequireReceiver);
            // wait another frame...
            yield return(0);

            Destroy(gameObject);
        }