コード例 #1
0
        /** RemoveFromType
         */
        public static void RemoveFromType(ref UnityEngine.LowLevel.PlayerLoopSystem a_playerloopsystem, System.Type a_type)
        {
            int t_index_1;
            int t_index_2;
            int t_index_3;
            int t_index_count = Find.FindFromType(a_playerloopsystem, a_type, out t_index_1, out t_index_2, out t_index_3);

            switch (t_index_count)
            {
            case 1:
            {
                System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem> t_sub_list = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList);
                t_sub_list.RemoveAt(t_index_1);
                a_playerloopsystem.subSystemList = t_sub_list.ToArray();
            } break;

            case 2:
            {
                System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem> t_sub_list = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList[t_index_1].subSystemList);
                t_sub_list.RemoveAt(t_index_2);
                a_playerloopsystem.subSystemList[t_index_1].subSystemList = t_sub_list.ToArray();
            } break;

            case 3:
            {
                System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem> t_sub_list = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList[t_index_1].subSystemList[t_index_2].subSystemList);
                t_sub_list.RemoveAt(t_index_3);
                a_playerloopsystem.subSystemList[t_index_1].subSystemList[t_index_2].subSystemList = t_sub_list.ToArray();
            } break;
            }
        }
コード例 #2
0
        UnityEngine.LowLevel.PlayerLoopSystem GenerateCustomLoop()
        {
            // Note: this also resets the loop to its defalt state first.
            var playerLoop = UnityEngine.LowLevel.PlayerLoop.GetDefaultPlayerLoop();

            hasCustomPlayerLoop = true;

            // Grab the 4th subsystem - This is the man Update Phase
            var update = playerLoop.subSystemList[4];

            // convert the subsytem array to a List to make it easier to work with...
            var newList = new List <UnityEngine.LowLevel.PlayerLoopSystem>(update.subSystemList);

            // add a demo system to the start of it (implementation at the end of this file)
            UnityEngine.LowLevel.PlayerLoopSystem beginUpdateSystem = new UnityEngine.LowLevel.PlayerLoopSystem();
            beginUpdateSystem.type           = typeof(CustomPlayerLoopStartUpdate);        // Unity uses the name of the type here to identify the System - we would see this show up in the Profiler for example
            beginUpdateSystem.updateDelegate = CustomPlayerLoopStartUpdate.UpdateFunction; // we can plug a C# method into this delegate to control what actually happens when this System updates
            newList.Insert(0, beginUpdateSystem);                                          // Finally lets insert it into the front!

            // Also lets put one on the end (implementation at the end of this file)
            newList.Add(CustomPlayerLoopEndUpdate.GetNewSystem()); // this time, lets use a small static helper method i added to the Systems type to generate the PlayerLoopSystem. this pattern is much cleaner :)

            // convert the list back to an array and plug it into the Update system.
            update.subSystemList = newList.ToArray();

            // dont forget to put our newly edited System back into the main player loop system!!
            playerLoop.subSystemList[4] = update;
            return(playerLoop);
        }
コード例 #3
0
        private void RemoveSystem(UnityEngine.LowLevel.PlayerLoopSystem target, UnityEngine.LowLevel.PlayerLoopSystem playerLoopSystem)
        {
            // LIMITATION assumes that systems are never stacked more than one level deep (e.g Update.CustomThing.CoolSystem will not work! one level too deep
            // Hell im not even sure if that works in general? it seems like it should but ive not tried it... still thought it was best to flag it up here...
            for (int i = 0; i < playerLoopSystem.subSystemList.Length; i++)
            {
                var system = playerLoopSystem.subSystemList[i];
                if (system.type == target.type)
                {
                    // create a list of the subsystems, its easier to work with
                    var newList = new List <UnityEngine.LowLevel.PlayerLoopSystem>(playerLoopSystem.subSystemList);

                    // remove the target
                    newList.RemoveAt(i);
                    playerLoopSystem.subSystemList = newList.ToArray();

                    nextPlayerLoop = currentPlayerLoop; // copy the current loop...
                    // and plug in our updated parent into it.
                    for (int j = 0; j < currentPlayerLoop.subSystemList.Length; j++)
                    {
                        if (currentPlayerLoop.subSystemList[j].type == playerLoopSystem.type)
                        {
                            currentPlayerLoop.subSystemList[j] = playerLoopSystem;
                        }
                    }
                    // then flag that it needs to be applied at the end of the GUI draw
                    hasUpdated = true;
                }
            }
        }
コード例 #4
0
        static UnityEngine.LowLevel.PlayerLoopSystem[] InsertRunner(Type type, UnityEngine.LowLevel.PlayerLoopSystem loopSystem, PlayerLoopRunner runner)
        {
            var runnerLoop = new UnityEngine.LowLevel.PlayerLoopSystem
            {
                type           = type,
                updateDelegate = runner.Run
            };

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

            Array.Copy(loopSystem.subSystemList, 0, dest, 1, loopSystem.subSystemList.Length);
            dest[0] = runnerLoop;
            return(dest);
        }
コード例 #5
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);
        }
コード例 #6
0
        /** Start
         */
        private void Start()
        {
            //削除時にデフォルトに戻す。
            BlueBack.UnityPlayerLoop.UnityPlayerLoop.SetDefaultPlayerLoopOnUnityDestroy();

            //列挙。
            UnityEngine.LowLevel.PlayerLoopSystem t_playerloopsystem = BlueBack.UnityPlayerLoop.UnityPlayerLoop.GetCurrentPlayerLoop();
            if (t_playerloopsystem.subSystemList != null)
            {
                foreach (var t_item in t_playerloopsystem.subSystemList)
                {
                    UnityEngine.Debug.Log("" + t_item.type.ToString());
                    foreach (var t_item_item in t_item.subSystemList)
                    {
                        UnityEngine.Debug.Log(" + " + t_item_item.type.ToString());
                    }
                }
            }
        }
コード例 #7
0
        static UnityEngine.LowLevel.PlayerLoopSystem[] InsertRunner(UnityEngine.LowLevel.PlayerLoopSystem loopSystem, Type loopRunnerYieldType, ContinuationQueue cq, Type loopRunnerType, PlayerLoopRunner runner)
        {
            var yieldLoop = new UnityEngine.LowLevel.PlayerLoopSystem
            {
                type           = loopRunnerYieldType,
                updateDelegate = cq.Run
            };

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

            var dest = new UnityEngine.LowLevel.PlayerLoopSystem[loopSystem.subSystemList.Length + 2];

            Array.Copy(loopSystem.subSystemList, 0, dest, 2, loopSystem.subSystemList.Length);
            dest[0] = yieldLoop;
            dest[1] = runnerLoop;
            return(dest);
        }
コード例 #8
0
ファイル: Add.cs プロジェクト: bluebackblue/UnityPlayerLoop
        /** Find
         *
         *      a_playerloopsystem		: プレイヤーループシステム。
         *      a_mode					: モード。
         *      a_target_type			: 追加場所。
         *      a_type					: タイプ。
         *      a_function				: 関数。
         *
         */
        public static void AddFromType(ref UnityEngine.LowLevel.PlayerLoopSystem a_playerloopsystem, Mode a_mode, System.Type a_target_type, System.Type a_type, UnityEngine.LowLevel.PlayerLoopSystem.UpdateFunction a_function)
        {
            int t_index_1;
            int t_index_2;
            int t_index_3;
            int t_index_count = Find.FindFromType(a_playerloopsystem, a_target_type, out t_index_1, out t_index_2, out t_index_3);

            UnityEngine.LowLevel.PlayerLoopSystem t_item = new UnityEngine.LowLevel.PlayerLoopSystem();
            {
                t_item.subSystemList  = null;
                t_item.type           = a_type;
                t_item.updateDelegate = a_function;
            }

            int t_target_index;

            System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem> t_target_list;
            {
                switch (a_mode)
                {
                case Mode.AddFirst:
                case Mode.AddLast:
                {
                    t_target_index = -1;

                    switch (t_index_count)
                    {
                    case 1:
                    {
                        t_target_list = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList[t_index_1].subSystemList);
                    } break;

                    case 2:
                    {
                        t_target_list = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList[t_index_1].subSystemList[t_index_2].subSystemList);
                    } break;

                    case 3:
                    {
                        t_target_list = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList[t_index_1].subSystemList[t_index_2].subSystemList[t_index_3].subSystemList);
                    } break;

                    default:
                    {
                        //未発見。

                                                                #if (DEF_BLUEBACK_UNITYPLAYERLOOP_ASSERT)
                        DebugTool.Assert(false);
                                                                #endif

                        t_target_list = null;
                    } break;
                    }
                } break;

                case Mode.AddBefore:
                case Mode.AddAfter:
                {
                    switch (t_index_count)
                    {
                    case 1:
                    {
                        t_target_list  = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList);
                        t_target_index = t_index_1;
                    } break;

                    case 2:
                    {
                        t_target_list  = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList[t_index_1].subSystemList);
                        t_target_index = t_index_2;
                    } break;

                    case 3:
                    {
                        t_target_list  = new System.Collections.Generic.List <UnityEngine.LowLevel.PlayerLoopSystem>(a_playerloopsystem.subSystemList[t_index_1].subSystemList[t_index_2].subSystemList);
                        t_target_index = t_index_3;
                    } break;

                    default:
                    {
                        //未発見。

                                                                #if (DEF_BLUEBACK_UNITYPLAYERLOOP_ASSERT)
                        DebugTool.Assert(false);
                                                                #endif

                        t_target_list  = null;
                        t_target_index = -1;
                    } break;
                    }
                } break;

                default:
                {
                    //不明なタイプ。

                                                #if (DEF_BLUEBACK_UNITYPLAYERLOOP_ASSERT)
                    DebugTool.Assert(false);
                                                #endif

                    t_target_list  = null;
                    t_target_index = -1;
                } break;
                }
            }

            //追加。
            {
                switch (a_mode)
                {
                case Mode.AddFirst:
                {
                    t_target_list.Insert(0, t_item);
                } break;

                case Mode.AddLast:
                {
                    t_target_list.Add(t_item);
                } break;

                case Mode.AddBefore:
                {
                    t_target_list.Insert(t_target_index, t_item);
                } break;

                case Mode.AddAfter:
                {
                    t_target_list.Insert(t_target_index + 1, t_item);
                } break;

                default:
                {
                    //不明なタイプ。

                                                #if (DEF_BLUEBACK_UNITYPLAYERLOOP_ASSERT)
                    DebugTool.Assert(false);
                                                #endif
                } break;
                }
            }

            //適応。
            {
                switch (a_mode)
                {
                case Mode.AddFirst:
                case Mode.AddLast:
                {
                    switch (t_index_count)
                    {
                    case 1:
                    {
                        a_playerloopsystem.subSystemList[t_index_1].subSystemList = t_target_list.ToArray();
                    } break;

                    case 2:
                    {
                        a_playerloopsystem.subSystemList[t_index_1].subSystemList[t_index_2].subSystemList = t_target_list.ToArray();
                    } break;

                    case 3:
                    {
                        a_playerloopsystem.subSystemList[t_index_1].subSystemList[t_index_2].subSystemList[t_index_3].subSystemList = t_target_list.ToArray();
                    } break;

                    default:
                    {
                        //未発見。

                                                                #if (DEF_BLUEBACK_UNITYPLAYERLOOP_ASSERT)
                        DebugTool.Assert(false);
                                                                #endif
                    } break;
                    }
                } break;

                case Mode.AddBefore:
                case Mode.AddAfter:
                {
                    switch (t_index_count)
                    {
                    case 1:
                    {
                        a_playerloopsystem.subSystemList = t_target_list.ToArray();
                    } break;

                    case 2:
                    {
                        a_playerloopsystem.subSystemList[t_index_1].subSystemList = t_target_list.ToArray();
                    } break;

                    case 3:
                    {
                        a_playerloopsystem.subSystemList[t_index_1].subSystemList[t_index_2].subSystemList = t_target_list.ToArray();
                    } break;

                    default:
                    {
                        //未発見。

                                                                #if (DEF_BLUEBACK_UNITYPLAYERLOOP_ASSERT)
                        DebugTool.Assert(false);
                                                                #endif
                    } break;
                    }
                } break;

                default:
                {
                    //不明なタイプ。

                                                #if (DEF_BLUEBACK_UNITYPLAYERLOOP_ASSERT)
                    DebugTool.Assert(false);
                                                #endif
                } break;
                }
            }
        }
コード例 #9
0
        void OnGUI()
        {
            GUILayout.Label("Player Loop Visualizer", EditorStyles.boldLabel);

            // Check to see if we need to initialize the PlayerLoopSystem.
            if (currentPlayerLoop.subSystemList == null)
            {
                if (hasCustomPlayerLoop)
                {
                    // if were expecting a custom loop, use Generate Custom
                    currentPlayerLoop = GenerateCustomLoop();
                    UnityEngine.LowLevel.PlayerLoop.SetPlayerLoop(currentPlayerLoop);
                }
                else
                {
                    // Otherwise grab the default loop
                    currentPlayerLoop = UnityEngine.LowLevel.PlayerLoop.GetDefaultPlayerLoop();
                }
            }

            // Draw the entier list out in a scrollable area (it gets really big!)
            scroll = EditorGUILayout.BeginScrollView(scroll, GUIStyle.none, GUI.skin.verticalScrollbar);
            foreach (var loopSystem in currentPlayerLoop.subSystemList)
            {
                DrawSubsystemList(loopSystem, 0);

                if (hasUpdated)
                {
                    hasUpdated        = false;
                    currentPlayerLoop = nextPlayerLoop;
                    UnityEngine.LowLevel.PlayerLoop.SetPlayerLoop(currentPlayerLoop);
                }
            }
            EditorGUILayout.EndScrollView();

            // Draw out a documentation help box
            EditorGUILayout.HelpBox(infoBox, MessageType.Info, true);

            // and finally draw our demo interaction buttons!
            GUILayout.BeginHorizontal(EditorStyles.helpBox);
            if (!hasCustomPlayerLoop)
            {
                if (GUILayout.Button("Add Custom System"))
                {
                    hasCustomPlayerLoop = true;
                    currentPlayerLoop   = GenerateCustomLoop();
                    UnityEngine.LowLevel.PlayerLoop.SetPlayerLoop(currentPlayerLoop);
                }
            }
            else
            {
                if (GUILayout.Button("Remove Custom System"))
                {
                    hasCustomPlayerLoop = false;
                    currentPlayerLoop   = UnityEngine.LowLevel.PlayerLoop.GetDefaultPlayerLoop();
                    UnityEngine.LowLevel.PlayerLoop.SetPlayerLoop(currentPlayerLoop);

                    EditorApplication.QueuePlayerLoopUpdate();
                }
            }
            if (GUILayout.Button(getProfileTimingInfo ? "Disable Profiler" : "Enable Profiler"))
            {
                // simply toggle the profiler bool
                getProfileTimingInfo = !getProfileTimingInfo;
            }

            if (GUILayout.Button("Reset"))
            {
                // nulls the cached player loop system so the default system is grabbed again
                hasCustomPlayerLoop = false;
                currentPlayerLoop   = new UnityEngine.LowLevel.PlayerLoopSystem();
            }
            if (GUILayout.Button("Open Docs"))
            {
                Application.OpenURL("https://docs.unity3d.com/2018.1/Documentation/ScriptReference/Experimental.LowLevel.PlayerLoopSystem.html");
            }
            GUILayout.EndHorizontal();
        }
コード例 #10
0
        void DrawSubsystemList(UnityEngine.LowLevel.PlayerLoopSystem system, int increment = 1)
        {
            // here were using a stack to generate a path name for the PlayerLoopSystem were currently trying to draw
            // e.g Update.ScriptRunBehaviourUpdate. Unity uses these path names when storing profiler data on a step
            // that means  we can use these path names to retrieve profiler samples!
            if (pathStack.Count == 0)
            {
                // if this is a root object, add its name to the stack
                pathStack.Push(system.type.Name);
            }
            else
            {
                // otherwise add its name to its parents name...
                pathStack.Push(pathStack.Peek() + "." + system.type.Name);
            }

            using (new EditorGUI.IndentLevelScope(increment))
            {
                // if this System has Subsystems, draw a foldout
                bool header = system.subSystemList != null;
                if (header)
                {
                    var name = system.type.Name; var fullName = system.type.FullName;
                    // check fold

                    EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                    bool fold = EditorGUILayout.Foldout(GetFoldout(fullName), name, true); // use the GetFoldout helper method to see if its open or closed
                    EditorGUILayout.EndHorizontal();

                    if (fold)
                    {
                        // if the fold is open, draw all the Subsytems~
                        foreach (var loopSystem in system.subSystemList)
                        {
                            // store the current system Useful if we need to know the parent of a system later
                            systemStack.Push(system);
                            DrawSubsystemList(loopSystem);
                            systemStack.Pop();
                        }
                    }

                    SetFoldout(fullName, fold);
                }
                else
                {
                    // at the moment, all the defaut 'native' Systems update via a updateFunction (essentally, a pointer into the unmanaged C++ side of the engine.
                    // So we can tell if a system is a custom one because it has a value in updateDelegate instead. So if this is a custom system, make note of that
                    // so we can change how its drawn later
                    bool custom = system.updateDelegate != null;
                    using (new EditorGUI.DisabledScope(custom))
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space((float)EditorGUI.indentLevel * 18f); // indent the entry nicley. We have to do this manually cos the flexible space at the end conflicts with GUI.Indent

                        // draw the remove button...
                        if (GUILayout.Button("x"))
                        {
                            RemoveSystem(system, systemStack.Peek());
                        }
                        GUILayout.Label(system.type.Name); // draw the name out....

                        // If the profiling mode is enabled, get the profiler sampler for this System and display its execution times!
                        if (getProfileTimingInfo)
                        {
                            var sampler = Sampler.Get(pathStack.Peek());

                            var info = "";
                            if (sampler.GetRecorder().elapsedNanoseconds != 0)
                            {
                                info = (sampler.GetRecorder().elapsedNanoseconds / 1000000f) + "ms";
                            }
                            else
                            {
                                info = "0.000000ms";
                            }

                            using (new EditorGUI.DisabledScope(true))
                            {
                                GUILayout.Label("[" + info + "]");
                            }
                        }

                        GUILayout.FlexibleSpace();
                        EditorGUILayout.EndHorizontal();
                        //EditorGUILayout.LabelField(new GUIContent(/*"custom"*/));//, EditorGUIUtility.IconContent("cs Script Icon"));
                    }
                }
            }

            pathStack.Pop();
        }