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 }
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); }
private static void DrawGraphAttribute(KeyValuePair<string, VarTracerGraphItData> kv) { EditorGUILayout.LabelField(kv.Key,NameLabel); foreach (var varBodyName in GetAllVariableBodyFromChannel(kv.Key)) { NameLabel.normal.textColor = Color.white; EditorGUILayout.LabelField("{" + 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; } EditorGUILayout.LabelField(" [" + entry.Key + "]" + " Value: " + g.mCurrentValue.ToString(VarTracerConst.NUM_FORMAT_2),NameLabel); } } var varBody = VarTracer.Instance.VariableBodys[varBodyName]; foreach (var eventName in varBody.EventInfos.Keys) { //NameLabel.normal.textColor = varBody.EventColors[eventName]; NameLabel.normal.textColor = Color.white; EditorGUILayout.LabelField(" <Event> " + eventName,NameLabel); } } if (kv.Value.mData.Count >= 1) { HoverText.normal.textColor = Color.white; EditorGUILayout.LabelField("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)); } }
public static void DrawGraphs(Rect rect, EditorWindow window) { if (VarTracer.Instance) { bool isEditorPaused = EditorApplication.isPaused; 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 (isEditorPaused) 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 == mMouseOverGraphIndex); 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); } mGraphViewScrollPos = EditorGUILayout.BeginScrollView(mGraphViewScrollPos, GUIStyle.none); graph_index = 0; mWidth = window.position.width - x_offset; 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 (!EditorApplication.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(); float GraphGap = kv.Value.m_maxValue - kv.Value.m_minValue; float unitHeight = GraphGap / VarTracerConst.Graph_Grid_Row_Num; for (int i = 0; i < VarTracerConst.Graph_Grid_Row_Num + 1; i++) { GUILayout.Space(6); if (unitHeight == 0) EditorGUILayout.LabelField("",NameLabel); else EditorGUILayout.LabelField((kv.Value.m_maxValue - i * unitHeight).ToString(VarTracerConst.NUM_FORMAT_1),NameLabel); } 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(); } DrawGraphAttribute(kv); ////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(); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); } }