Example #1
0
        //Signals key activation and path recording
        private void Update()
        {
            if (pause || !recording)
            {
                return;
            }

            if (DontRecordInBuild)
            {
                return;
            }

            foreach (Signal.Config signal in signals)
            {
                if (!signal.ActivateOnKey || !signal.LookUpObject)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(signal.Button) && Input.GetButtonDown(signal.Button))
                {
                    SendSignal(signals.IndexOf(signal));
                }

                if (Input.GetKeyDown(signal.Key))
                {
                    SendSignal(signals.IndexOf(signal));
                }
            }

            for (int i = 0; i < recordables.Count; i++)
            {
                if (!recordables[i].ObjectToRecord || !recordables[i].Record)
                {
                    continue;
                }

                if (recordables[i].UpdateTimer())
                {
                    Recordable.Runtime runtimePath = runtimePaths[recordables[i].ObjectToRecord.name];
                    if (runtimePath.Data.Count <= 0)
                    {
                        runtimePath.Add(new Recordable.Data(Time.time, recordables[i].ObjectToRecord.position, false));
                    }
                    else
                    {
                        Recordable.Data lastPoint = runtimePath.Data.Last();
                        if (Vector3.Distance(lastPoint.pos, recordables[i].ObjectToRecord.position) > 0.2f)
                        {
                            runtimePath.Add(new Recordable.Data(Time.time, recordables[i].ObjectToRecord.position, false));
                        }
                    }
                }
            }
        }
        //Read paths file
        private void ReadPaths()
        {
            editorPaths = new Dictionary <string, Recordable.Runtime>();

            if (pathsFile == null || string.IsNullOrEmpty(pathsFile.text))
            {
                return;
            }

            string[] lines = pathsFile.text.Split('\n');

            if (lines.Length < 2)
            {
                return;
            }

            Recordable.Runtime currentPath = null;
            bool commentary = false;

            comment = "";
            foreach (string line in lines)
            {
                ReadComment(line, ref commentary, ref comment);

                if (currentPath == null)
                {
                    if (line.Contains("PATH"))
                    {
                        string[] pathInfo  = Regex.Match(line, nameRegex).ToString().Trim('"').Split(':');
                        string   colorInfo = Regex.Match(line, parenthesesRegex).ToString().Trim('(', ')');
                        ColorUtility.TryParseHtmlString(colorInfo, out Color color);
                        currentPath = new Recordable.Runtime(pathInfo[1], pathInfo[0], color);
                    }
                }
                else
                {
                    string[] sides = line.Split(':');

                    if (sides.Length > 0 && line.Length > 3)
                    {
                        string[] posString  = sides[0].Split(',');
                        Vector3  pos        = new Vector3(Utils.ReadFloat(posString[0]), Utils.ReadFloat(posString[1]), Utils.ReadFloat(posString[2]));
                        string[] dataString = sides[1].Split(',');
                        float    time       = Utils.ReadFloat(dataString[0]);
                        bool     isBreak    = bool.Parse(dataString[1]);

                        if (editorPaths.ContainsKey(currentPath.objectName))
                        {
                            editorPaths[currentPath.objectName].Add(new Recordable.Data(time, pos, isBreak));
                        }
                        else
                        {
                            currentPath.Add(new Recordable.Data(time, pos, isBreak));
                            editorPaths.Add(currentPath.objectName, currentPath);
                        }
                    }
                    else
                    {
                        currentPath = null;
                    }
                }
            }
        }
Example #3
0
        private List <LevelMetricsTreeElement> CollectTree()
        {
            List <LevelMetricsTreeElement> result = new List <LevelMetricsTreeElement>();

            LevelMetricsTreeElement root = new LevelMetricsTreeElement()
            {
                id = 0, depth = -1, displayName = "root"
            };
            LevelMetricsTreeElement signals = new LevelMetricsTreeElement()
            {
                id = 1, displayName = "Signals"
            };
            LevelMetricsTreeElement paths = new LevelMetricsTreeElement()
            {
                id = 2, displayName = "Paths"
            };

            root.AddChild(signals);
            root.AddChild(paths);

            result.Add(root);
            result.Add(signals);
            result.Add(paths);

            int id = 3;

            for (int i = 0; i < script.editorSignals.Count; i++)
            {
                int objectIndex;
                List <Signal.Runtime> signalList = script.editorSignals.ElementAt(i).Value;
                foreach (Signal.Runtime signal in signalList)
                {
                    if (!CheckElementInBranch(signal.objectName, result, out objectIndex))
                    {
                        LevelMetricsTreeElement objectRoot = new LevelMetricsTreeElement();
                        objectRoot.id          = id++;
                        objectRoot.displayName = signal.objectName;
                        signals.AddChild(objectRoot);

                        result.Add(objectRoot);
                        objectIndex = result.Count - 1;
                    }

                    signal.treeElement.Reset();
                    signal.treeElement.displayName = signal.name;
                    signal.treeElement.id          = id++;
                    result[objectIndex].AddChild(signal.treeElement);
                    result.Add(signal.treeElement);

                    for (int d = 0; d < signal.Data.Count; d++)
                    {
                        signal.Data[d].treeElement.Reset();
                        signal.Data[d].treeElement.displayName = string.Format("{0}: {1} at {2}", signal.name, signal.Data[d].count, Utils.FloatToTime(signal.Data[d].time));
                        signal.Data[d].treeElement.id          = id++;
                        signal.treeElement.AddChild(signal.Data[d].treeElement);

                        result.Add(signal.Data[d].treeElement);
                    }
                }
            }

            for (int i = 0; i < script.editorPaths.Count; i++)
            {
                int objectIndex;
                Recordable.Runtime path = script.editorPaths.ElementAt(i).Value;
                if (!CheckElementInBranch(path.objectName, result.Where(x => !CheckParent("Signals", x)).ToList(), out objectIndex))
                {
                    LevelMetricsTreeElement objectRoot = new LevelMetricsTreeElement();
                    objectRoot.id          = id++;
                    objectRoot.displayName = path.objectName;
                    paths.AddChild(objectRoot);

                    result.Add(objectRoot);
                    objectIndex = result.Count - 1;
                }

                path.treeElement.Reset();
                path.treeElement.displayName = path.name;
                path.treeElement.id          = id++;
                result[objectIndex].AddChild(path.treeElement);
                result.Add(path.treeElement);
            }

            return(result);
        }
Example #4
0
        private static void DrawHandles(LevelMetricsViewer scr, GizmoType gizmoType)
        {
            if (!scr.Display)
            {
                return;
            }

            if (!scr.DisplaySettings.ShowText)
            {
                return;
            }

            if (!Selection.Contains(scr.gameObject))
            {
                return;
            }

            GUIStyle style = new GUIStyle();

            style.normal.textColor = Color.black;
            Bounds testBound = new Bounds(Vector3.zero, Vector3.one * 0.2f);

            if (scr.editorSignals.Count > 0)
            {
                foreach (KeyValuePair <string, List <Signal.Runtime> > pair in scr.editorSignals)
                {
                    foreach (Signal.Runtime signal in pair.Value)
                    {
                        string signalName = signal.name;

                        if (!signal.treeElement.IsVisible())
                        {
                            continue;
                        }

                        foreach (Signal.Data data in signal.Data)
                        {
                            testBound.center = data.pos;
                            if (scr.DisplaySettings.Mode == DisplaySettings.Modes.ViewCheck && !GeometryUtility.TestPlanesAABB(scr.Planes, testBound))
                            {
                                continue;
                            }

                            Vector3 pos = data.pos + Camera.current.transform.right * signal.gizmoSize * 0.5f;

                            if (data.treeElement.IsVisible())
                            {
                                Handles.Label(pos, string.Format("{0}: {1} at {2}", signalName, data.count, Utils.FloatToTime(data.time)), style);
                            }
                        }
                    }
                }
            }

            if (scr.editorPaths.Count > 0)
            {
                foreach (KeyValuePair <string, Recordable.Runtime> pair in scr.editorPaths)
                {
                    Recordable.Runtime path = pair.Value;

                    if (!path.treeElement.IsVisible())
                    {
                        continue;
                    }

                    for (int i = 0; i < path.Data.Count; i++)
                    {
                        testBound.center = path.Data[i].pos;
                        if (!GeometryUtility.TestPlanesAABB(scr.Planes, testBound))
                        {
                            continue;
                        }

                        Vector3 pos = path.Data[i].pos + Camera.current.transform.right * 0.2f;
                        if (i == 0)
                        {
                            Handles.Label(pos, string.Format("{0}: {1}", path.name, Utils.FloatToTime(path.Data[i].time)), style);
                        }
                        else
                        {
                            Handles.Label(pos, Utils.FloatToTime(path.Data[i].time), style);
                        }
                    }
                }
            }
        }