Example #1
0
        static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem,
                                               bool injectOnFirst,
                                               Type loopRunnerYieldType, ContinuationQueue cq,
                                               Type loopRunnerType, PlayerLoopRunner runner)
        {
#if UNITY_EDITOR
            EditorApplication.playModeStateChanged += (state) =>
            {
                if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.ExitingEditMode)
                {
                    IsEditorApplicationQuitting = true;
                    // run rest action before clear.
                    if (runner != null)
                    {
                        runner.Run();
                        runner.Clear();
                    }
                    if (cq != null)
                    {
                        cq.Run();
                        cq.Clear();
                    }
                    IsEditorApplicationQuitting = false;
                }
            };
#endif

            var yieldLoop = new PlayerLoopSystem
            {
                type           = loopRunnerYieldType,
                updateDelegate = cq.Run
            };

            var runnerLoop = new PlayerLoopSystem
            {
                type           = loopRunnerType,
                updateDelegate = runner.Run
            };

            // Remove items from previous initializations.
            var source = RemoveRunner(loopSystem, loopRunnerYieldType, loopRunnerType);
            var dest   = new PlayerLoopSystem[source.Length + 2];

            Array.Copy(source, 0, dest, injectOnFirst ? 2 : 0, source.Length);
            if (injectOnFirst)
            {
                dest[0] = yieldLoop;
                dest[1] = runnerLoop;
            }
            else
            {
                dest[dest.Length - 2] = yieldLoop;
                dest[dest.Length - 1] = runnerLoop;
            }

            return(dest);
        }
        static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType,
                                               ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
        {
#if UNITY_EDITOR
            EditorApplication.playModeStateChanged += (state) =>
            {
                if (state == PlayModeStateChange.EnteredEditMode ||
                    state == PlayModeStateChange.EnteredPlayMode)
                {
                    return;
                }

                if (runner != null)
                {
                    runner.Clear();
                }
                if (cq != null)
                {
                    cq.Clear();
                }
            };
#endif

            var yieldLoop = new PlayerLoopSystem
            {
                type           = loopRunnerYieldType,
                updateDelegate = cq.Run
            };

            var runnerLoop = new PlayerLoopSystem
            {
                type           = loopRunnerType,
                updateDelegate = runner.Run
            };

            var source = loopSystem.subSystemList // Remove items from previous initializations.
                         .Where(ls => ls.type != loopRunnerYieldType && ls.type != loopRunnerType).ToArray();
            var dest = new PlayerLoopSystem[source.Length + 2];
            Array.Copy(source, 0, dest, 2, source.Length);
            dest[0] = yieldLoop;
            dest[1] = runnerLoop;
            return(dest);
        }
Example #3
0
        static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType,
                                               ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
        {
#if UNITY_EDITOR
            EditorApplication.playModeStateChanged += (state) =>
            {
                if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.EnteredPlayMode)
                {
                    return;
                }

                if (runner != null)
                {
                    runner.Clear();
                }
                if (cq != null)
                {
                    cq.Clear();
                }
            };
#endif


            var yieldLoop = new PlayerLoopSystem
            {
                type           = loopRunnerYieldType,
                updateDelegate = cq.Run
            };

            var runnerLoop = new PlayerLoopSystem
            {
                type           = loopRunnerType,
                updateDelegate = runner.Run
            };

            var dest = new PlayerLoopSystem[loopSystem.subSystemList.Length + 2];
            Array.Copy(loopSystem.subSystemList, 0, dest, 2, loopSystem.subSystemList.Length);
            dest[0] = yieldLoop;
            dest[1] = runnerLoop;
            return(dest);
        }
Example #4
0
        static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem,
                                               Type loopRunnerYieldType, ContinuationQueue cq, Type lastLoopRunnerYieldType, ContinuationQueue lastCq,
                                               Type loopRunnerType, PlayerLoopRunner runner, Type lastLoopRunnerType, PlayerLoopRunner lastRunner)
        {
#if UNITY_EDITOR
            EditorApplication.playModeStateChanged += (state) =>
            {
                if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.ExitingEditMode)
                {
                    IsEditorApplicationQuitting = true;
                    // run rest action before clear.
                    if (runner != null)
                    {
                        runner.Run();
                        runner.Clear();
                    }
                    if (lastRunner != null)
                    {
                        lastRunner.Run();
                        lastRunner.Clear();
                    }

                    if (cq != null)
                    {
                        cq.Run();
                        cq.Clear();
                    }
                    if (lastCq != null)
                    {
                        lastCq.Run();
                        lastCq.Clear();
                    }
                    IsEditorApplicationQuitting = false;
                }
            };
#endif

            var yieldLoop = new PlayerLoopSystem
            {
                type           = loopRunnerYieldType,
                updateDelegate = cq.Run
            };

            var lastYieldLoop = new PlayerLoopSystem
            {
                type           = lastLoopRunnerYieldType,
                updateDelegate = lastCq.Run
            };

            var runnerLoop = new PlayerLoopSystem
            {
                type           = loopRunnerType,
                updateDelegate = runner.Run
            };

            var lastRunnerLoop = new PlayerLoopSystem
            {
                type           = lastLoopRunnerType,
                updateDelegate = lastRunner.Run
            };

            // Remove items from previous initializations.
            var source = loopSystem.subSystemList
                         .Where(ls => ls.type != loopRunnerYieldType && ls.type != loopRunnerType && ls.type != lastLoopRunnerYieldType && ls.type != lastLoopRunnerType)
                         .ToArray();

            var dest = new PlayerLoopSystem[source.Length + 4];

            Array.Copy(source, 0, dest, 2, source.Length);
            dest[0] = yieldLoop;
            dest[1] = runnerLoop;
            dest[dest.Length - 2] = lastYieldLoop;
            dest[dest.Length - 1] = lastRunnerLoop;

            return(dest);
        }