Beispiel #1
0
        public void OnGUI()
        {
            //toolbar/header
            if (Event.current.type == EventType.Repaint)
            {
                EditorStyles.toolbar.Draw(new Rect(0, 0, position.width, toolbarHeight), new GUIContent(), 0);
            }

            //Record
            Timer.enabled = EditorGUI.Toggle(new Rect(5, 0, 50, toolbarHeight), Timer.enabled, style: EditorStyles.toolbarButton);
            EditorGUI.LabelField(new Rect(9, 1, 50, toolbarHeight), "Record", style: EditorStyles.miniBoldLabel);

            //Group
            bool newGroupEnabled = EditorGUI.Toggle(new Rect(55, 0, 50, toolbarHeight), groupEnabled, style: EditorStyles.toolbarButton);

            if (newGroupEnabled && groupEnabled)             //just pressed
            {
                prevEnabled   = Timer.enabled;
                Timer.enabled = true;
                groupTimer    = Timer.Start("Record Group " + Timer.history.Count);
                groupEnabled  = true;
            }
            if (!newGroupEnabled && groupEnabled)
            {
                groupTimer.Dispose();
                groupEnabled  = false;
                Timer.enabled = prevEnabled;
            }
            EditorGUI.LabelField(new Rect(63, 1, 50, toolbarHeight), "Group", style: EditorStyles.miniBoldLabel);

            //Clear
            if (UnityEngine.GUI.Button(new Rect(105, 0, 50, toolbarHeight), "Clear", style: EditorStyles.toolbarButton))
            {
                Timer.history.Clear();
            }

            DrawHeaderValues(new Rect(0, 0, position.width - scrollWidth, toolbarHeight));

            //calculating lines number
            int historyCount = Timer.history.Count;
            int linesCount   = historyCount;

            for (int h = 0; h < historyCount; h++)
            {
                linesCount += Timer.history[h].GetExpandedCount();
            }

            //drawing timers
            scrollPosition = UnityEngine.GUI.BeginScrollView(
                position: new Rect(0, toolbarHeight, position.width, position.height - toolbarHeight),
                scrollPosition: scrollPosition,
                viewRect: new Rect(0, 0, position.width - scrollWidth, linesCount * lineHeight),
                alwaysShowHorizontal: false,
                alwaysShowVertical: true);

            int lineNum = 0;

            for (int h = 0; h < historyCount; h++)
            {
                Timer.TimerInstance timer = Timer.history[h];
                DrawTimer(new Rect(0, lineNum * lineHeight, position.width - scrollWidth, lineHeight), timer, ref lineNum, 0, h);
            }

            UnityEngine.GUI.EndScrollView();
        }
Beispiel #2
0
        public void DrawTimer(Rect rect, Timer.TimerInstance timer, ref int lineNum, int offset = 0, int num = -1)
        {
            float namesWidth  = rect.width * namesWidthPercent;
            float valuesWidth = rect.width - namesWidth;
            float rowWidth    = valuesWidth / 7;
            float numWidth    = 25;
            float tabWidth    = 10;

            if (rect.y - scrollPosition.y >= 0 && rect.y - scrollPosition.y < position.height)
            {
                //selection
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
                {
                    selectedLine = lineNum;
                    Repaint();
                }

                if (selectedLine == lineNum && Event.current.type == EventType.Repaint)
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorStyles.helpBox.Draw(rect, new GUIContent(), 0);
                    EditorGUI.EndDisabledGroup();
                }

                //disabling if fastest value is too low
                EditorGUI.BeginDisabledGroup(timer.fastest < 10);

                //name
                if (num >= 0)
                {
                    EditorGUI.LabelField(new Rect(rect.x, rect.y, numWidth, rect.height), num.ToString());
                }

                float namePos  = offset * tabWidth + numWidth;
                Rect  nameRect = new Rect(rect.x + namePos, rect.y, namesWidth - namePos, rect.height);
                if (timer.subTimers != null)
                {
                    timer.expanded = EditorGUI.Foldout(nameRect, timer.expanded, timer.name);
                }
                else
                {
                    EditorGUI.LabelField(new Rect(nameRect.x + 12, nameRect.y, nameRect.width - 12, nameRect.height), timer.name);
                }

                //values
                Rect row = new Rect(rect.x + namesWidth, rect.y, rowWidth, rect.height);
                EditorGUI.LabelField(row, timer.calls.ToString());

                row.x += rowWidth;
                EditorGUI.LabelField(row, Timer.TicksToMilliseconds(timer.total).ToString("0.000"));

                row.x += rowWidth;
                EditorGUI.LabelField(row, Timer.TicksToMilliseconds(timer.SelfTime()).ToString("0.000"));

                row.x += rowWidth;
                EditorGUI.LabelField(row, Timer.TicksToMilliseconds(timer.total / timer.calls).ToString("0.000"));

                row.x += rowWidth;
                EditorGUI.LabelField(row, Timer.TicksToMilliseconds(timer.fastest).ToString("0.000"));

                row.x += rowWidth;
                EditorGUI.LabelField(row, Timer.TicksToMilliseconds(timer.slowest).ToString("0.000"));

                row.x += rowWidth;
                EditorGUI.LabelField(row, Timer.TicksToMilliseconds(timer.fastest * timer.calls).ToString("0.000"));

                EditorGUI.EndDisabledGroup();
            }

            //sub-timers
            int origLineNum = lineNum;

            lineNum++;
            if (timer.expanded && timer.subTimers != null)
            {
                for (int i = 0; i < timer.subTimers.Count; i++)
                {
                    DrawTimer(new Rect(rect.x, rect.y + lineHeight * (lineNum - origLineNum), rect.width, rect.height), timer.subTimers[i], ref lineNum, offset + 1);
                }
            }
        }