Пример #1
0
        public void StepGraphInternal(VarTracerGraphItData graph)
        {
#if UNITY_EDITOR
            foreach (KeyValuePair <string, VarTracerDataInternal> entry in graph.mData)
            {
                VarTracerDataInternal g = entry.Value;
                if (g.mDataInfos.Count <= 0)
                {
                    continue;
                }

                float sum = g.mDataInfos[0].Value;
                float min = g.mDataInfos[0].Value;
                float max = g.mDataInfos[0].Value;
                for (int i = 1; i < g.mDataInfos.Count; ++i)
                {
                    sum += g.mDataInfos[i].Value;
                    min  = Mathf.Min(min, g.mDataInfos[i].Value);
                    max  = Mathf.Max(max, g.mDataInfos[i].Value);
                }
                if (graph.mInclude0)
                {
                    min = Mathf.Min(min, 0.0f);
                    max = Mathf.Max(max, 0.0f);
                }

                g.mMin = min;
                g.mMax = max;
            }
#endif
        }
        private static void DrawGraphAttribute(KeyValuePair <string, VarTracerGraphItData> kv)
        {
            GUILayout.Label("Graph:" + kv.Key, NameLabel);
            int colorIndex = kv.Value.mData.Count;

            foreach (var varBodyName in GetAllVariableBodyFromChannel(kv.Key))
            {
                NameLabel.normal.textColor = Color.white;

                GUILayout.Label("LogicName:" + varBodyName, NameLabel);

                foreach (var entry in kv.Value.mData)
                {
                    var variable            = VarTracer.GetGraphItVariableByVariableName(entry.Key);
                    VarTracerDataInternal g = entry.Value;
                    if (variable.VarBodyName.Equals(varBodyName))
                    {
                        if (kv.Value.mData.Count >= 1)
                        {
                            NameLabel.normal.textColor = g.mColor;
                        }
                        GUILayout.Label("     [Variable]   " + entry.Key + ":" + g.mCurrentValue.ToString(VarTracerConst.NUM_FORMAT_2), NameLabel);
                    }
                }

                var varBody = VarTracer.Instance.groups[varBodyName];

                foreach (var eventName in varBody.EventInfos.Keys)
                {
                    colorIndex++;
                    NameLabel.normal.textColor = VarTracerUtils.GetColorByIndex(colorIndex);
                    GUILayout.BeginHorizontal();

                    Color saveColor = GUI.backgroundColor;
                    GUI.backgroundColor = NameLabel.normal.textColor;
                    GUILayout.Button("", EventButtonStyle, GUILayout.Width(10));
                    GUI.backgroundColor = saveColor;
                    var flag = EditorGUILayout.Toggle(varBody.EventInfos[eventName].IsCutFlag, GUILayout.Width(10));
                    if (flag != varBody.EventInfos[eventName].IsCutFlag)
                    {
                        varBody.EventInfos[eventName].IsCutFlag = flag;
                        if (flag)
                        {
                            varBody.EventInfos[eventName].TimeStamp = VarTracerUtils.GetTimeStamp();
                        }
                    }
                    GUILayout.Label("     <Event>    " + eventName, NameLabel);
                    GUILayout.EndHorizontal();
                }
            }

            if (kv.Value.mData.Count >= 1)
            {
                HoverText.normal.textColor = Color.white;
                GUILayout.Label("duration:" + (mWidth / kv.Value.XStep / VarTracerConst.FPS).ToString(VarTracerConst.NUM_FORMAT_3) + "(s)", HoverText, GUILayout.Width(140));
                kv.Value.XStep = GUILayout.HorizontalSlider(kv.Value.XStep, 0.1f, 15, GUILayout.Width(160));
            }
        }
Пример #3
0
        public float GetMax(string subgraph)
        {
            bool  max_set = false;
            float max     = 0;

            foreach (KeyValuePair <string, VarTracerDataInternal> entry in mData)
            {
                VarTracerDataInternal g = entry.Value;
                if (!max_set)
                {
                    max     = g.mMax;
                    max_set = true;
                }
                max = Math.Max(max, g.mMax);
            }
            m_maxValue = max;
            return(max);
        }
        public static void DrawGraphs(Rect rect, EditorWindow window)
        {
            if (VarTracer.Instance)
            {
                CreateLineMaterial();

                mLineMaterial.SetPass(0);

                int graph_index = 0;

                //use this to get the starting y position for the GL rendering
                Rect find_y = EditorGUILayout.BeginVertical(GUIStyle.none);
                EditorGUILayout.EndVertical();

                int currentFrameIndex = VarTracerNet.Instance.GetCurrentFrameFromTimestamp(VarTracerUtils.GetTimeStamp());
                if (m_isPaused)
                {
                    currentFrameIndex = VarTracerNet.Instance.GetCurrentFrameFromTimestamp(VarTracerUtils.StopTimeStamp);
                }

                float scrolled_y_pos = y_offset - mGraphViewScrollPos.y;
                if (Event.current.type == EventType.Repaint)
                {
                    GL.PushMatrix();
                    float start_y = find_y.y;
                    GL.Viewport(new Rect(0, 0, rect.width, rect.height - start_y));
                    GL.LoadPixelMatrix(0, rect.width, rect.height - start_y, 0);

                    //Draw grey BG
                    GL.Begin(GL.QUADS);
                    GL.Color(new Color(0.2f, 0.2f, 0.2f));

                    foreach (KeyValuePair <string, VarTracerGraphItData> kv in VarTracer.Instance.Graphs)
                    {
                        float height = kv.Value.GetHeight();

                        GL.Vertex3(x_offset, scrolled_y_pos, 0);
                        GL.Vertex3(x_offset + mWidth, scrolled_y_pos, 0);
                        GL.Vertex3(x_offset + mWidth, scrolled_y_pos + height, 0);
                        GL.Vertex3(x_offset, scrolled_y_pos + height, 0);

                        scrolled_y_pos += (height + y_gap);
                    }
                    GL.End();

                    scrolled_y_pos = y_offset - mGraphViewScrollPos.y;
                    //Draw Lines
                    GL.Begin(GL.LINES);

                    foreach (KeyValuePair <string, VarTracerGraphItData> kv in VarTracer.Instance.Graphs)
                    {
                        graph_index++;
                        float height = kv.Value.GetHeight();
                        DrawGraphGridLines(scrolled_y_pos, mWidth, height, graph_index == mMouseSelectedGraphNum);

                        foreach (KeyValuePair <string, VarTracerDataInternal> entry in kv.Value.mData)
                        {
                            VarTracerDataInternal g = entry.Value;

                            float y_min   = kv.Value.GetMin(entry.Key);
                            float y_max   = kv.Value.GetMax(entry.Key);
                            float y_range = Mathf.Max(y_max - y_min, 0.00001f);

                            //draw the 0 line
                            if (y_min != 0.0f)
                            {
                                GL.Color(Color.white);
                                float y = scrolled_y_pos + height * (1 - (0.0f - y_min) / y_range);
                                Plot(x_offset, y, x_offset + mWidth, y);
                            }

                            GL.Color(g.mColor);

                            float previous_value = 0, value = 0;
                            int   dataInfoIndex = 0, frameIndex = 0;
                            for (int i = 0; i <= currentFrameIndex; i++)
                            {
                                int dataCount = g.mDataInfos.Count;
                                if (dataCount != 0)
                                {
                                    int   lastFrame = g.mDataInfos[dataCount - 1].FrameIndex;
                                    float lastValue = g.mDataInfos[dataCount - 1].Value;
                                    frameIndex = g.mDataInfos[dataInfoIndex].FrameIndex;

                                    if (dataInfoIndex >= 1)
                                    {
                                        value = g.mDataInfos[dataInfoIndex - 1].Value;
                                    }

                                    if (dataInfoIndex == 0 && i < frameIndex)
                                    {
                                        value = 0;
                                    }

                                    if (i >= frameIndex)
                                    {
                                        while (g.mDataInfos[dataInfoIndex].FrameIndex == frameIndex && dataInfoIndex < dataCount - 1)
                                        {
                                            dataInfoIndex++;
                                        }
                                    }

                                    if (i > lastFrame)
                                    {
                                        value = lastValue;
                                    }
                                }
                                else
                                {
                                    value = 0;
                                }

                                if (i >= 1)
                                {
                                    float x0 = x_offset + (i - 1) * kv.Value.XStep - kv.Value.ScrollPos.x;
                                    if (x0 <= x_offset - kv.Value.XStep)
                                    {
                                        continue;
                                    }
                                    if (x0 >= mWidth + x_offset)
                                    {
                                        break;
                                    }
                                    float y0 = scrolled_y_pos + height * (1 - (previous_value - y_min) / y_range);

                                    if (i == 1)
                                    {
                                        x0 = x_offset;
                                        y0 = scrolled_y_pos + height;
                                    }

                                    float x1 = x_offset + i * kv.Value.XStep - kv.Value.ScrollPos.x;
                                    float y1 = scrolled_y_pos + height * (1 - (value - y_min) / y_range);

                                    if (m_isDrawLine)
                                    {
                                        Plot(x0, y0, x1, y1);
                                    }
                                    else
                                    {
                                        Plot(x0, y0, x0 + 1, y0 + 1);
                                    }
                                }
                                previous_value = value;
                            }
                        }
                        scrolled_y_pos += (height + y_gap);
                    }
                    GL.End();

                    scrolled_y_pos = y_offset - mGraphViewScrollPos.y;
                    scrolled_y_pos = ShowEventLabel(scrolled_y_pos);
                    GL.PopMatrix();

                    GL.Viewport(new Rect(0, 0, rect.width, rect.height));
                    GL.LoadPixelMatrix(0, rect.width, rect.height, 0);
                }

                float allGraphHieght = (VarTracerConst.DefaultChannelHieght + y_gap) * VarTracer.Instance.Graphs.Count - y_gap - mGraphViewScrollPos.y;
                Rect  rec            = new Rect(10, allGraphHieght, 100, 1000);
                GUILayout.BeginArea(rec);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("+", GUILayout.Width(20), GUILayout.Height(20)))
                {
                    VarTracer.AddChannel();
                }

                if (GUILayout.Button("-", GUILayout.Width(20), GUILayout.Height(20)))
                {
                    VarTracer.RemoveChannel();
                }

                GUILayout.EndHorizontal();
                GUILayout.EndArea();

                mGraphViewScrollPos = EditorGUILayout.BeginScrollView(mGraphViewScrollPos, GUIStyle.none);
                GUILayout.Label("", GUILayout.Height((VarTracerConst.DefaultChannelHieght + y_gap) * VarTracer.Instance.Graphs.Count + y_offset + m_controlScreenHeight));
                graph_index = 0;
                mWidth      = window.position.width - VarTracerConst.NavigationAreaRWidth;
                foreach (KeyValuePair <string, VarTracerGraphItData> kv in VarTracer.Instance.Graphs)
                {
                    graph_index++;
                    float height = kv.Value.GetHeight();
                    float width  = currentFrameIndex * kv.Value.XStep;
                    if (width < mWidth)
                    {
                        width = mWidth - x_offset;
                    }
                    else
                    {
                        if (!m_isPaused)
                        {
                            kv.Value.ScrollPos = new Vector2(width - mWidth, kv.Value.ScrollPos.y);
                        }
                    }

                    GUIStyle s = new GUIStyle();
                    s.fixedHeight  = height + y_gap;
                    s.stretchWidth = true;
                    Rect r = EditorGUILayout.BeginVertical(s);

                    //skip subgraph title if only one, and it's the same.
                    NameLabel.normal.textColor = Color.white;

                    r.height = height + 50;
                    r.width  = width;
                    r.x      = x_offset - 35;
                    r.y      = (height + y_gap) * (graph_index - 1) - 10;

                    if (kv.Value.mData.Count > 0)
                    {
                        GUILayout.BeginArea(r);
                        GUILayout.BeginVertical();
                        for (int i = 0; i < VarTracerConst.Graph_Grid_Row_Num + 1; i++)
                        {
                            GUILayout.Space(6);
                            EditorGUILayout.LabelField("");
                        }
                        GUILayout.BeginHorizontal();
                        kv.Value.ScrollPos = GUILayout.BeginScrollView(kv.Value.ScrollPos, GUILayout.Width(mWidth), GUILayout.Height(0));
                        GUILayout.Label("", GUILayout.Width(width), GUILayout.Height(0));
                        GUILayout.EndScrollView();
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();
                        GUILayout.EndArea();
                    }

                    r.width = mWidth + 35;
                    ////Respond to mouse input!
                    if (Event.current.type == EventType.MouseDrag && r.Contains(Event.current.mousePosition - Event.current.delta))
                    {
                        if (Event.current.button == 0)
                        {
                            kv.Value.ScrollPos = new Vector2(kv.Value.ScrollPos.x + Event.current.delta.x, kv.Value.ScrollPos.y);
                        }
                        window.Repaint();
                    }
                    else if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition))
                    {
                        mMouseSelectedGraphNum = graph_index;
                    }

                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndScrollView();
            }
        }