Example #1
0
 public float GetMin(string subgraph)
 {
     if (mSharedYAxis)
     {
         bool  min_set = false;
         float min     = 0;
         foreach (KeyValuePair <string, GraphItDataInternalLuaPro> entry in mData)
         {
             GraphItDataInternalLuaPro g = entry.Value;
             if (!min_set)
             {
                 min     = g.mMin;
                 min_set = true;
             }
             min = Math.Min(min, g.mMin);
         }
         return(min);
     }
     else
     {
         if (!mData.ContainsKey(subgraph))
         {
             mData[subgraph] = new GraphItDataInternalLuaPro(mData.Count);
         }
         return(mData[subgraph].mMin);
     }
 }
Example #2
0
 public float GetMax(string subgraph)
 {
     if (mSharedYAxis)
     {
         bool  max_set = false;
         float max     = 0;
         foreach (KeyValuePair <string, GraphItDataInternalLuaPro> entry in mData)
         {
             GraphItDataInternalLuaPro g = entry.Value;
             if (!max_set)
             {
                 max     = g.mMax;
                 max_set = true;
             }
             max = Math.Max(max, g.mMax);
         }
         return(max);
     }
     else
     {
         if (!mData.ContainsKey(subgraph))
         {
             mData[subgraph] = new GraphItDataInternalLuaPro(mData.Count);
         }
         return(mData[subgraph].mMax);
     }
 }
Example #3
0
 public static void Clear()
 {
     if (!mInstance)
     {
         return;
     }
     foreach (KeyValuePair <string, GraphItDataLuaPro> kv in mInstance.Graphs)
     {
         GraphItDataLuaPro g = kv.Value;
         g.mCurrentIndex = 0;
         foreach (KeyValuePair <string, GraphItDataInternalLuaPro> entry in g.mData)
         {
             GraphItDataInternalLuaPro gdi = entry.Value;
             gdi.mDataInfos.Clear();
         }
     }
 }
    public static void DrawGraphs(Rect rect, EditorWindow window)
    {
        if (GraphItLuaPro.Instance)
        {
            //string num_format = "###,###,###,##0.###";
            //for (int i = 0; i < precision_slider; i++)
            //{
            //    num_format += "#";
            //}
            InitializeStyles();
            CreateLineMaterial();

            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();
            float scrolled_y_pos = y_offset - mScrollPos.y;
            float scrolled_x_pos = x_offset - mScrollPos.x;
            if (Event.current.type == EventType.Repaint)
            {
                //Draw Lines
                foreach (KeyValuePair <string, GraphItDataLuaPro> kv in GraphItLuaPro.Instance.Graphs)
                {
                    if (kv.Value.GetHidden())
                    {
                        continue;
                    }
                    graph_index++;

                    float height = kv.Value.GetHeight();
                    mRectMaterial.SetFloat("_BottomLineHeight", scrolled_y_pos + height);
                    mRectMaterial.SetFloat("_LineHeight", height);

                    mRectMaterial.SetFloat("_DataHeightMaxLimit", getDataHeightMaxLimit(kv.Value.mName));
                    mLineMaterial.SetPass(0);
                    DrawGraphGridLines(scrolled_y_pos, mWidth, height, graph_index == mMouseOverGraphIndex);
                    if (kv.Value.GraphLength() > 0)
                    {
                        bool isShowLeftSideTips = true;
                        foreach (KeyValuePair <string, GraphItDataInternalLuaPro> entry in kv.Value.mData)
                        {
                            GraphItDataInternalLuaPro g = entry.Value;

                            float y_min = 0;
                            float y_max = kv.Value.GetMax(entry.Key);
                            y_max = getDataHeightMaxLimit(kv.Value.mName);

                            float y_range = Mathf.Max(y_max - y_min, 0.00001f);
                            GL.Begin(GL.LINES);
                            //draw the 0 line
                            if (y_max > 0.0f && y_min < 0.0f)
                            {
                                GL.Color(g.mColor * 0.5f);
                                float y = scrolled_y_pos + height * (1 - (0.0f - y_min) / y_range);
                                Plot(x_offset, y, x_offset + mWidth, y);
                            }
                            GL.End();
                            float previous_value = 0;
                            int   len            = kv.Value.GraphLength();
                            for (int i = 0; i < len; ++i)
                            {
                                float value = 0;
                                if (i >= 1)
                                {
                                    float x0 = x_offset + (i - 1) * XStep + scrolled_x_pos;
                                    if (x0 <= -XStep * 2)
                                    {
                                        continue;
                                    }
                                    if (x0 >= mWidth + XStep * 2)
                                    {
                                        break;
                                    }
                                    value = g.mDataInfos[i].GraphNum;
                                    float y0 = scrolled_y_pos + height * (1 - (previous_value - y_min) / y_range);

                                    float x1 = x_offset + i * XStep + scrolled_x_pos;
                                    float y1 = scrolled_y_pos + height * (1 - (value - y_min) / y_range);
                                    DrawDataRect(x0, y0, x1, y1, scrolled_y_pos + height, g.mColor);

                                    if (EditorApplication.isPaused && MouseXOnPause > 0 && g.mDataInfos[i].FrameID == FrameIDOnPause)
                                    {
                                        Rect r = new Rect();
                                        r.position = new Vector2(x0 + 10, 0);
                                        r.width    = 35;
                                        r.height   = 15;
                                        Color bg2 = Color.white;
                                        bg2.a = 0.2f;
                                        Handles.DrawSolidRectangleWithOutline(r, bg2, bg2);
                                        GUI.Label(r, FrameIDOnPause.ToString(), HoverText);


                                        Rect r2 = new Rect();
                                        y1 -= 20;
                                        y1  = Mathf.Max(y1, 0);
                                        if (isShowLeftSideTips)
                                        {
                                            x0 -= 60;
                                        }
                                        else
                                        {
                                            x0 += 10;
                                        }
                                        r2.position = new Vector2(x0, y1);
                                        r2.width    = 60;
                                        r2.height   = 15;
                                        Color bg = g.mColor;
                                        bg.a = 0.5f;
                                        Handles.DrawSolidRectangleWithOutline(r2, bg, bg);


                                        string afterFix = null;
                                        if (kv.Key.Equals(HanoiData.GRAPH_TIMECONSUMING))
                                        {
                                            afterFix = "ms";
                                        }
                                        else
                                        {
                                            afterFix = "%";
                                        }
                                        string text = value.ToString(num_format) + afterFix;
                                        HoverText.normal.textColor = Color.black;
                                        GUI.Label(r2, text, HoverText);
                                    }
                                }
                                previous_value = value;
                            }
                            isShowLeftSideTips = !isShowLeftSideTips;
                        }
                    }
                    scrolled_y_pos += (height + y_gap);
                }
            }

            graph_index = 0;
            if (Event.current.type == EventType.Repaint)
            {
                mMouseOverGraphIndex = -1; //clear it out every repaint to ensure when the mouse leaves we don't leave the pointer around
            }
            foreach (KeyValuePair <string, GraphItDataLuaPro> kv in GraphItLuaPro.Instance.Graphs)
            {
                if (kv.Value.GetHidden())
                {
                    continue;
                }
                graph_index++;


                mWidth = window.position.width - x_offset;

                float height = kv.Value.GetHeight();
                float width  = kv.Value.GraphLength() * XStep;
                if (width < mWidth)
                {
                    width = mWidth - x_offset * 2;
                }
                else
                {
                    if (!EditorApplication.isPaused)
                    {
                        mScrollPos.x = width - mWidth;
                    }
                }

                Rect r = EditorGUILayout.BeginVertical();
                r.height = height;

                //Determine if we can fit all of the text
                float row_size        = 18;
                float text_block_size = row_size * 4;
                if (kv.Value.mData.Count == 1)
                {
                    text_block_size = row_size * 3;
                }
                bool show_full_text = (kv.Value.mData.Count * text_block_size + row_size) < height;

                string fu_str = " " + (kv.Value.mFixedUpdate ? "(FixedUpdate)" : "");
                //skip subgraph title if only one, and it's the same.
                if (show_full_text)
                {
                    NameLabel.normal.textColor = Color.white;
                    EditorGUILayout.LabelField(kv.Key + fu_str, NameLabel);
                }

                foreach (KeyValuePair <string, GraphItDataInternalLuaPro> entry in kv.Value.mData)
                {
                    GraphItDataInternalLuaPro g = entry.Value;
                    if (!show_full_text)
                    {
                        //fit each line manually or drop it
                        height -= row_size;
                        if (height >= 0)
                        {
                            if (kv.Value.mData.Count > 1)
                            {
                                NameLabel.normal.textColor = g.mColor;
                            }
                            else
                            {
                                NameLabel.normal.textColor = Color.white;
                            }
                            string text = entry.Key;
                            if (text == GraphItLuaPro.BASE_GRAPH)
                            {
                                text = kv.Key;
                            }
                            EditorGUILayout.LabelField(text + fu_str, NameLabel);
                        }
                        height -= row_size;
                        if (height >= 0)
                        {
                            EditorGUILayout.LabelField("-", SmallLabel);
                        }
                    }
                }

                //Respond to mouse input!
                if (Event.current.type == EventType.MouseDrag && r.Contains(Event.current.mousePosition - Event.current.delta))
                {
                    if (Event.current.type == EventType.MouseDrag)
                    {
                        if (Event.current.button == 1)
                        {
                            mScrollPos.x += Event.current.delta.x;
                            MouseXOnPause = -1;
                        }
                        window.Repaint();
                    }
                }
                else if (Event.current.type != EventType.Layout && r.Contains(Event.current.mousePosition))
                {
                    if (Event.current.type == EventType.Repaint || (Event.current.type == EventType.MouseDown && Event.current.button == 0))
                    {
                        mMouseOverGraphIndex = graph_index;
                        mMouseX = Event.current.mousePosition.x;
                        float offsetMouseX = mMouseX - x_offset + XStep * 2;
                        if (kv.Value.GraphLength() > 0)
                        {
                            foreach (KeyValuePair <string, GraphItDataInternalLuaPro> entry in kv.Value.mData)
                            {
                                GraphItDataInternalLuaPro g = entry.Value;

                                for (int i = 0; i < kv.Value.GraphLength(); ++i)
                                {
                                    if (i >= 1)
                                    {
                                        //float value = g.mDataInfos[i - 1].GraphNum;
                                        float interval  = g.mDataInfos[i - 1].FrameInterval;
                                        int   frameID   = g.mDataInfos[i - 1].FrameID;
                                        float frameTime = g.mDataInfos[i - 1].FrameTime;
                                        float x0        = x_offset + (i - 1) * XStep + scrolled_x_pos;
                                        float x1        = x_offset + i * XStep + scrolled_x_pos;
                                        if (x0 < offsetMouseX && offsetMouseX <= x1)
                                        {
                                            if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                                            {
                                                MouseXOnPause  = x0;
                                                FrameIDOnPause = frameID;
                                                LuaProfilerWindow myWindow = (LuaProfilerWindow)EditorWindow.GetWindow(typeof(LuaProfilerWindow));
                                                myWindow.setFrameTimeOnPause(frameTime);
                                                myWindow.setViewPointToGlobalTime(0, interval, mMouseX);
                                                myWindow.m_isTestCallLua   = false;
                                                EditorApplication.isPaused = true;
                                                break;
                                            }
                                            else
                                            {
                                                Vector2 position = Event.current.mousePosition + new Vector2(10, -10);
                                                Vector2 size     = new Vector2(45, 15);
                                                Rect    back     = new Rect(position, size);
                                                Color   bg       = Color.grey;
                                                Handles.DrawSolidRectangleWithOutline(back, bg, bg);

                                                //string text = value.ToString(num_format);
                                                Rect tooltip_r = new Rect(position, size);
                                                HoverText.normal.textColor = Color.white;
                                                GUI.Label(tooltip_r, frameID.ToString(), HoverText);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (Event.current.type == EventType.MouseMove)
                    {
                        window.Repaint();
                    }
                }
                EditorGUILayout.EndVertical();
                float preScrollPosX = mScrollPos.x;
                mScrollPos = EditorGUILayout.BeginScrollView(mScrollPos, GUILayout.Width(mWidth), GUILayout.Height(height + y_gap));
                if (preScrollPosX != mScrollPos.x)
                {
                    MouseXOnPause = -1;
                }
                GUILayout.Label("", GUILayout.Width(width), GUILayout.Height(0));
                EditorGUILayout.EndScrollView();
            }
        }
    }