Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        static void InsertLoop(PlayerLoopSystem[] copyList, InjectPlayerLoopTimings injectTimings, Type loopType, InjectPlayerLoopTimings targetTimings,
                               int index, bool injectOnFirst, Type loopRunnerYieldType, Type loopRunnerType, PlayerLoopTiming playerLoopTiming)
        {
            var i = FindLoopSystemIndex(copyList, loopType);

            if ((injectTimings & targetTimings) == targetTimings)
            {
                copyList[i].subSystemList = InsertRunner(copyList[i], injectOnFirst,
                                                         loopRunnerYieldType, yielders[index] = new ContinuationQueue(playerLoopTiming),
                                                         loopRunnerType, runners[index]       = new PlayerLoopRunner(playerLoopTiming));
            }
            else
            {
                copyList[i].subSystemList = RemoveRunner(copyList[i], loopRunnerYieldType, loopRunnerType);
            }
        }
Ejemplo n.º 3
0
        public void Run()
        {
            var runner = new PlayerLoopRunner();

            var oneshot    = new OneshotLoopItem();
            var disposable = new DisposableLoopItem();
            var nested     = new NestedLoopItem(runner);

            runner.Dispatch(oneshot);
            runner.Dispatch(disposable);
            runner.Dispatch(nested);
            runner.Run();
            runner.Run();
            disposable.Dispose();
            runner.Run();

            Assert.That(oneshot.Called, Is.EqualTo(1));
            Assert.That(disposable.Called, Is.EqualTo(2));
            Assert.That(nested.Called, Is.EqualTo(3));
            Assert.That(nested.ChildLoopItem.Called, Is.EqualTo(1));
        }
Ejemplo n.º 4
0
        static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType, ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
        {
            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);
        }
Ejemplo n.º 5
0
        public static void Initialize(ref PlayerLoopSystem playerLoop)
        {
            yielders = new ContinuationQueue[7];
            runners  = new PlayerLoopRunner[7];

            var copyList = playerLoop.subSystemList.ToArray();

            copyList[0].subSystemList = InsertRunner(copyList[0], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldInitialization), yielders[0] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization), runners[0] = new PlayerLoopRunner());
            copyList[1].subSystemList = InsertRunner(copyList[1], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldEarlyUpdate), yielders[1] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerEarlyUpdate), runners[1] = new PlayerLoopRunner());
            copyList[2].subSystemList = InsertRunner(copyList[2], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldFixedUpdate), yielders[2] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerFixedUpdate), runners[2] = new PlayerLoopRunner());
            copyList[3].subSystemList = InsertRunner(copyList[3], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreUpdate), yielders[3] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreUpdate), runners[3] = new PlayerLoopRunner());
            copyList[4].subSystemList = InsertRunner(copyList[4], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldUpdate), yielders[4] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerUpdate), runners[4] = new PlayerLoopRunner());
            copyList[5].subSystemList = InsertRunner(copyList[5], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreLateUpdate), yielders[5] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreLateUpdate), runners[5] = new PlayerLoopRunner());
            copyList[6].subSystemList = InsertRunner(copyList[6], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPostLateUpdate), yielders[6] = new ContinuationQueue(), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPostLateUpdate), runners[6] = new PlayerLoopRunner());

            playerLoop.subSystemList = copyList;
            PlayerLoop.SetPlayerLoop(playerLoop);
        }
        static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType, ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
        {
            var yieldLoop = new PlayerLoopSystem
            {
                type = loopRunnerYieldType,
#if UNITY_EDITOR
                updateDelegate = () =>
                {
                    if (Application.isPlaying)
                    {
                        cq.Run();
                    }
                }
#else
                updateDelegate = cq.Run
#endif
            };

            var runnerLoop = new PlayerLoopSystem
            {
                type = loopRunnerType,
#if UNITY_EDITOR
                updateDelegate = () =>
                {
                    if (Application.isPlaying)
                    {
                        runner.Run();
                    }
                }
#else
                updateDelegate = runner.Run
#endif
            };

            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);
        }
Ejemplo n.º 7
0
        public static void Initialize(ref PlayerLoopSystem playerLoop)
        {
            yielders = new ContinuationQueue[14];
            runners  = new PlayerLoopRunner[14];

            var copyList = playerLoop.subSystemList.ToArray();

            // Initialization
            copyList[0].subSystemList = InsertRunner(copyList[0], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldInitialization), yielders[0] = new ContinuationQueue(PlayerLoopTiming.Initialization),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldInitialization), yielders[1] = new ContinuationQueue(PlayerLoopTiming.LastInitialization),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization), runners[0]           = new PlayerLoopRunner(PlayerLoopTiming.Initialization),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastInitialization), runners[1]       = new PlayerLoopRunner(PlayerLoopTiming.LastInitialization));
            // EarlyUpdate
            copyList[1].subSystemList = InsertRunner(copyList[1], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldEarlyUpdate), yielders[2] = new ContinuationQueue(PlayerLoopTiming.EarlyUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldEarlyUpdate), yielders[3] = new ContinuationQueue(PlayerLoopTiming.LastEarlyUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerEarlyUpdate), runners[2]           = new PlayerLoopRunner(PlayerLoopTiming.EarlyUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastEarlyUpdate), runners[3]       = new PlayerLoopRunner(PlayerLoopTiming.LastEarlyUpdate));
            // FixedUpdate
            copyList[2].subSystemList = InsertRunner(copyList[2], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldFixedUpdate), yielders[4] = new ContinuationQueue(PlayerLoopTiming.FixedUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldFixedUpdate), yielders[5] = new ContinuationQueue(PlayerLoopTiming.LastFixedUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerFixedUpdate), runners[4]           = new PlayerLoopRunner(PlayerLoopTiming.FixedUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastFixedUpdate), runners[5]       = new PlayerLoopRunner(PlayerLoopTiming.LastFixedUpdate));
            // PreUpdate
            copyList[3].subSystemList = InsertRunner(copyList[3], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreUpdate), yielders[6] = new ContinuationQueue(PlayerLoopTiming.PreUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPreUpdate), yielders[7] = new ContinuationQueue(PlayerLoopTiming.LastPreUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreUpdate), runners[6]           = new PlayerLoopRunner(PlayerLoopTiming.PreUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPreUpdate), runners[7]       = new PlayerLoopRunner(PlayerLoopTiming.LastPreUpdate));
            // Update
            copyList[4].subSystemList = InsertRunner(copyList[4], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldUpdate), yielders[8] = new ContinuationQueue(PlayerLoopTiming.Update),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldUpdate), yielders[9] = new ContinuationQueue(PlayerLoopTiming.LastUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerUpdate), runners[8]           = new PlayerLoopRunner(PlayerLoopTiming.Update),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastUpdate), runners[9]       = new PlayerLoopRunner(PlayerLoopTiming.LastUpdate));
            // PreLateUpdate
            copyList[5].subSystemList = InsertRunner(copyList[5], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreLateUpdate), yielders[10] = new ContinuationQueue(PlayerLoopTiming.PreLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPreLateUpdate), yielders[11] = new ContinuationQueue(PlayerLoopTiming.LastPreLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreLateUpdate), runners[10]           = new PlayerLoopRunner(PlayerLoopTiming.PreLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPreLateUpdate), runners[11]       = new PlayerLoopRunner(PlayerLoopTiming.LastPreLateUpdate));
            // PostLateUpdate
            copyList[6].subSystemList = InsertRunner(copyList[6], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPostLateUpdate), yielders[12] = new ContinuationQueue(PlayerLoopTiming.PostLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPostLateUpdate), yielders[13] = new ContinuationQueue(PlayerLoopTiming.LastPostLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerPostLateUpdate), runners[12]           = new PlayerLoopRunner(PlayerLoopTiming.PostLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPostLateUpdate), runners[13]       = new PlayerLoopRunner(PlayerLoopTiming.LastPostLateUpdate));

            // Insert UniTaskSynchronizationContext to Update loop
            copyList[4].subSystemList = InsertUniTaskSynchronizationContext(copyList[4]);

            playerLoop.subSystemList = copyList;
            PlayerLoop.SetPlayerLoop(playerLoop);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public static void Initialize(ref PlayerLoopSystem playerLoop)
        {
#if UNITY_2020_2_OR_NEWER
            yielders = new ContinuationQueue[16];
            runners  = new PlayerLoopRunner[16];
#else
            yielders = new ContinuationQueue[14];
            runners  = new PlayerLoopRunner[14];
#endif

            var copyList = playerLoop.subSystemList.ToArray();

            var i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.Initialization));
            copyList[i].subSystemList = InsertRunner(copyList[i], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldInitialization), yielders[0] = new ContinuationQueue(PlayerLoopTiming.Initialization),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldInitialization), yielders[1] = new ContinuationQueue(PlayerLoopTiming.LastInitialization),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization), runners[0]           = new PlayerLoopRunner(PlayerLoopTiming.Initialization),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastInitialization), runners[1]       = new PlayerLoopRunner(PlayerLoopTiming.LastInitialization));
            // EarlyUpdate
            i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.EarlyUpdate));
            copyList[i].subSystemList = InsertRunner(copyList[i], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldEarlyUpdate), yielders[2] = new ContinuationQueue(PlayerLoopTiming.EarlyUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldEarlyUpdate), yielders[3] = new ContinuationQueue(PlayerLoopTiming.LastEarlyUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerEarlyUpdate), runners[2]           = new PlayerLoopRunner(PlayerLoopTiming.EarlyUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastEarlyUpdate), runners[3]       = new PlayerLoopRunner(PlayerLoopTiming.LastEarlyUpdate));
            // FixedUpdate
            i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.FixedUpdate));
            copyList[i].subSystemList = InsertRunner(copyList[i], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldFixedUpdate), yielders[4] = new ContinuationQueue(PlayerLoopTiming.FixedUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldFixedUpdate), yielders[5] = new ContinuationQueue(PlayerLoopTiming.LastFixedUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerFixedUpdate), runners[4]           = new PlayerLoopRunner(PlayerLoopTiming.FixedUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastFixedUpdate), runners[5]       = new PlayerLoopRunner(PlayerLoopTiming.LastFixedUpdate));
            // PreUpdate
            i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.PreUpdate));
            copyList[i].subSystemList = InsertRunner(copyList[i], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreUpdate), yielders[6] = new ContinuationQueue(PlayerLoopTiming.PreUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPreUpdate), yielders[7] = new ContinuationQueue(PlayerLoopTiming.LastPreUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreUpdate), runners[6]           = new PlayerLoopRunner(PlayerLoopTiming.PreUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPreUpdate), runners[7]       = new PlayerLoopRunner(PlayerLoopTiming.LastPreUpdate));
            // Update
            i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.Update));
            copyList[i].subSystemList = InsertRunner(copyList[i], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldUpdate), yielders[8] = new ContinuationQueue(PlayerLoopTiming.Update),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldUpdate), yielders[9] = new ContinuationQueue(PlayerLoopTiming.LastUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerUpdate), runners[8]           = new PlayerLoopRunner(PlayerLoopTiming.Update),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastUpdate), runners[9]       = new PlayerLoopRunner(PlayerLoopTiming.LastUpdate));
            // PreLateUpdate
            i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.PreLateUpdate));
            copyList[i].subSystemList = InsertRunner(copyList[i], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreLateUpdate), yielders[10] = new ContinuationQueue(PlayerLoopTiming.PreLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPreLateUpdate), yielders[11] = new ContinuationQueue(PlayerLoopTiming.LastPreLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreLateUpdate), runners[10]           = new PlayerLoopRunner(PlayerLoopTiming.PreLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPreLateUpdate), runners[11]       = new PlayerLoopRunner(PlayerLoopTiming.LastPreLateUpdate));
            // PostLateUpdate
            i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.PostLateUpdate));
            copyList[i].subSystemList = InsertRunner(copyList[i], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPostLateUpdate), yielders[12] = new ContinuationQueue(PlayerLoopTiming.PostLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPostLateUpdate), yielders[13] = new ContinuationQueue(PlayerLoopTiming.LastPostLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerPostLateUpdate), runners[12]           = new PlayerLoopRunner(PlayerLoopTiming.PostLateUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPostLateUpdate), runners[13]       = new PlayerLoopRunner(PlayerLoopTiming.LastPostLateUpdate));
#if UNITY_2020_2_OR_NEWER
            // TimeUpdate
            i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.TimeUpdate));
            copyList[i].subSystemList = InsertRunner(copyList[i], typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldTimeUpdate), yielders[14] = new ContinuationQueue(PlayerLoopTiming.TimeUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldTimeUpdate), yielders[15] = new ContinuationQueue(PlayerLoopTiming.LastTimeUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerTimeUpdate), runners[14]           = new PlayerLoopRunner(PlayerLoopTiming.TimeUpdate),
                                                     typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastTimeUpdate), runners[15]       = new PlayerLoopRunner(PlayerLoopTiming.LastTimeUpdate));
#endif

            // Insert UniTaskSynchronizationContext to Update loop
            i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.Update));
            copyList[i].subSystemList = InsertUniTaskSynchronizationContext(copyList[i]);

            playerLoop.subSystemList = copyList;
            PlayerLoop.SetPlayerLoop(playerLoop);
        }
Ejemplo n.º 11
0
 public NestedLoopItem(PlayerLoopRunner runner)
 {
     this.runner = runner;
 }
Ejemplo n.º 12
0
        public static void Initialize(ref PlayerLoopSystem playerLoop, InjectPlayerLoopTimings injectTimings = InjectPlayerLoopTimings.All)
        {
            var manualIndex = (int)PlayerLoopTiming.Manual;

            yielders = new ContinuationQueue[manualIndex + 1];
            runners  = new PlayerLoopRunner[manualIndex + 1];

            yielders[manualIndex] = new ContinuationQueue(PlayerLoopTiming.Manual);
            runners[manualIndex]  = new PlayerLoopRunner(PlayerLoopTiming.Manual);

            var copyList = playerLoop.subSystemList.ToArray();

            // Initialization
            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.Initialization),
                       InjectPlayerLoopTimings.Initialization, 0, true,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldInitialization), typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization), PlayerLoopTiming.Initialization);

            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.Initialization),
                       InjectPlayerLoopTimings.LastInitialization, 1, false,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldInitialization), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastInitialization), PlayerLoopTiming.LastInitialization);

            // EarlyUpdate
            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.EarlyUpdate),
                       InjectPlayerLoopTimings.EarlyUpdate, 2, true,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldEarlyUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerEarlyUpdate), PlayerLoopTiming.EarlyUpdate);

            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.EarlyUpdate),
                       InjectPlayerLoopTimings.LastEarlyUpdate, 3, false,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldEarlyUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastEarlyUpdate), PlayerLoopTiming.LastEarlyUpdate);

            // FixedUpdate
            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.FixedUpdate),
                       InjectPlayerLoopTimings.FixedUpdate, 4, true,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldFixedUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerFixedUpdate), PlayerLoopTiming.FixedUpdate);

            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.FixedUpdate),
                       InjectPlayerLoopTimings.LastFixedUpdate, 5, false,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldFixedUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastFixedUpdate), PlayerLoopTiming.LastFixedUpdate);

            // PreUpdate
            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.PreUpdate),
                       InjectPlayerLoopTimings.PreUpdate, 6, true,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreUpdate), PlayerLoopTiming.PreUpdate);

            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.PreUpdate),
                       InjectPlayerLoopTimings.LastPreUpdate, 7, false,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPreUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPreUpdate), PlayerLoopTiming.LastPreUpdate);

            // Update
            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.Update),
                       InjectPlayerLoopTimings.Update, 8, true,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerUpdate), PlayerLoopTiming.Update);

            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.Update),
                       InjectPlayerLoopTimings.LastUpdate, 9, false,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastUpdate), PlayerLoopTiming.LastUpdate);

            // PreLateUpdate
            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.PreLateUpdate),
                       InjectPlayerLoopTimings.PreLateUpdate, 10, true,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPreLateUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreLateUpdate), PlayerLoopTiming.PreLateUpdate);

            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.PreLateUpdate),
                       InjectPlayerLoopTimings.LastPreLateUpdate, 11, false,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPreLateUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPreLateUpdate), PlayerLoopTiming.LastPreLateUpdate);

            // PostLateUpdate
            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.PostLateUpdate),
                       InjectPlayerLoopTimings.PostLateUpdate, 12, true,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldPostLateUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerPostLateUpdate), PlayerLoopTiming.PostLateUpdate);

            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.PostLateUpdate),
                       InjectPlayerLoopTimings.LastPostLateUpdate, 13, false,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldPostLateUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastPostLateUpdate), PlayerLoopTiming.LastPostLateUpdate);

#if UNITY_2020_2_OR_NEWER
            // TimeUpdate
            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.TimeUpdate),
                       InjectPlayerLoopTimings.TimeUpdate, 14, true,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerYieldTimeUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerTimeUpdate), PlayerLoopTiming.TimeUpdate);

            InsertLoop(copyList, injectTimings, typeof(PlayerLoopType.TimeUpdate),
                       InjectPlayerLoopTimings.LastTimeUpdate, 15, false,
                       typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastYieldTimeUpdate), typeof(UniTaskLoopRunners.UniTaskLoopRunnerLastTimeUpdate), PlayerLoopTiming.LastTimeUpdate);
#endif

            // Insert UniTaskSynchronizationContext to Update loop
            var i = FindLoopSystemIndex(copyList, typeof(PlayerLoopType.Update));
            copyList[i].subSystemList = InsertUniTaskSynchronizationContext(copyList[i]);

            playerLoop.subSystemList = copyList;
            PlayerLoop.SetPlayerLoop(playerLoop);
        }
Ejemplo n.º 13
0
        static PlayerLoopSystem[] InsertRunner(PlayerLoopSystem loopSystem, Type loopRunnerYieldType, ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
        {
            var yieldLoop = new PlayerLoopSystem
            {
                type = loopRunnerYieldType,
#if UNITY_EDITOR
                updateDelegate = () =>
                {
                    if (Application.isPlaying)
                    {
                        cq.Run();
                    }
                }
#else
                updateDelegate = cq.Run
#endif
            };

            var runnerLoop = new PlayerLoopSystem
            {
                type = loopRunnerType,
#if UNITY_EDITOR
                updateDelegate = () =>
                {
                    if (Application.isPlaying)
                    {
                        runner.Run();
                    }
                }
#else
                updateDelegate = runner.Run
#endif
            };

            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);
        }
Ejemplo n.º 14
0
        static PlayerLoopSystem[] InsertRunner(Type type, PlayerLoopSystem loopSystem, PlayerLoopRunner runner)
        {
            var runnerLoop = new PlayerLoopSystem
            {
                type           = type,
                updateDelegate = runner.Run
            };

            var dest = new PlayerLoopSystem[loopSystem.subSystemList.Length + 1];

            Array.Copy(loopSystem.subSystemList, 0, dest, 1, loopSystem.subSystemList.Length);
            dest[0] = runnerLoop;
            return(dest);
        }
Ejemplo n.º 15
0
        public static void Initialize(ref UnityEngine.LowLevel.PlayerLoopSystem playerLoop)
        {
            runners = new PlayerLoopRunner[7];

            var copyList = playerLoop.subSystemList.ToArray();

            copyList[0].subSystemList = InsertRunner(typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization), copyList[0], runners[0] = new PlayerLoopRunner());
            copyList[1].subSystemList = InsertRunner(typeof(UniTaskLoopRunners.UniTaskLoopRunnerEarlyUpdate), copyList[1], runners[1] = new PlayerLoopRunner());
            copyList[2].subSystemList = InsertRunner(typeof(UniTaskLoopRunners.UniTaskLoopRunnerFixedUpdate), copyList[2], runners[2] = new PlayerLoopRunner());
            copyList[3].subSystemList = InsertRunner(typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreUpdate), copyList[3], runners[3] = new PlayerLoopRunner());
            copyList[4].subSystemList = InsertRunner(typeof(UniTaskLoopRunners.UniTaskLoopRunnerUpdate), copyList[4], runners[4] = new PlayerLoopRunner());
            copyList[5].subSystemList = InsertRunner(typeof(UniTaskLoopRunners.UniTaskLoopRunnerPreLateUpdate), copyList[5], runners[5] = new PlayerLoopRunner());
            copyList[6].subSystemList = InsertRunner(typeof(UniTaskLoopRunners.UniTaskLoopRunnerPostLateUpdate), copyList[6], runners[6] = new PlayerLoopRunner());

            playerLoop.subSystemList = copyList;
            UnityEngine.LowLevel.PlayerLoop.SetPlayerLoop(playerLoop);
        }
Ejemplo n.º 16
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 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);
        }