void DrawCurve(DBG_DataCollector _DataCollector, int _SliceIteration, int _SliceCount, float _Opacity) { //Draw the curve for the given DataCollector float XPosAsRatio = 0.0f; float value = 0.0f; List <Vector3> ViewPortBuffer = new List <Vector3>(); Color TheColor = _DataCollector.VariableColor; if (_Opacity < 1.0f) { TheColor = new Color(TheColor.r, TheColor.g, TheColor.b, _Opacity); } for (int i = 0; i < _DataCollector.Data.Count; i++) { value = _DataCollector.Data[i]; //Determining the XPos as a ratio for the screen if (this.MarginSide == eMarginSide.RightSide) { XPosAsRatio = Mathf.Lerp(0.0f, 1.0f - MarginWidth, (float)i / (_DataCollector.Data.Count - 1)); } else if (this.MarginSide == eMarginSide.LeftSide) { XPosAsRatio = Mathf.Lerp(MarginWidth, 1.0f, (float)i / (_DataCollector.Data.Count - 1)); } else { XPosAsRatio = Mathf.Lerp(0.0f, 1.0f, (float)i / (_DataCollector.Data.Count - 1)); } //Determining the YPos as a ratio for the screen, according to Stacked layout and AbsoluteMode: float YPosAsRatio = 0.0f; if (this.AbsoluteMode) { if (_DataCollector.MaximumValue != 0.0f) { YPosAsRatio = value / _DataCollector.MaximumValue; } } else { float Max = 1.0f; if (Mathf.Abs(_DataCollector.MinimumValue) > _DataCollector.MaximumValue) { if (_DataCollector.MinimumValue != 0.0f) { Max = Mathf.Abs(_DataCollector.MinimumValue); } } else { if (_DataCollector.MaximumValue != 0.0f) { Max = _DataCollector.MaximumValue; } } YPosAsRatio = Mathf.Abs(value) / Max; if (value >= 0.0f) { YPosAsRatio = 0.5f + (YPosAsRatio * 0.5f); } else { YPosAsRatio = 0.5f - (YPosAsRatio * 0.5f); } } if (this.LayoutMode == eLayoutMode.Stacked) { YPosAsRatio = (1f / _SliceCount) * _SliceIteration + (YPosAsRatio * (1f / _SliceCount)); } Vector3 Point2D_Value = new Vector3(XPosAsRatio, YPosAsRatio, Camera.main.nearClipPlane * 2); ViewPortBuffer.Add(Point2D_Value); if (i > 0) { Vector3 Point3D_ValuePrevious = Camera.main.ViewportToWorldPoint(ViewPortBuffer[i - 1]); Vector3 Point3D_Value = Camera.main.ViewportToWorldPoint(Point2D_Value); Debug.DrawLine(Point3D_ValuePrevious, Point3D_Value, TheColor, 0f); //duration à 0f(seconds) => 1 frame } } }
void OnGUI() { //If No Margin is selected, exiting. if (this.MarginSide == eMarginSide.NoMargin) { return; } float FontHeight = 18.0f; float PanelWidth = MarginWidth * Screen.width; float XPos = 0.0f; if (this.MarginSide == eMarginSide.RightSide) { XPos = Screen.width - (PanelWidth); } if (this.MarginSide == eMarginSide.LeftSide) { XPos = 0.0f; } float SlicedPanelHeight = (1f / this.WatchDict.Keys.Count) * Screen.height; // Displaying values analysis in Margin #region ValueAnalysis int VariableIteration = 1; foreach (KeyValuePair <string, DBG_DataCollector> kvp in this.WatchDict) { int LineIteration = 1; float YPos = Screen.height - SlicedPanelHeight * VariableIteration; DBG_DataCollector current = kvp.Value; GUIStyle TextStyle = new GUIStyle(); TextStyle.normal.textColor = current.VariableColor; GUI.Label(new Rect(XPos, YPos + FontHeight * LineIteration, (MarginWidth * Screen.width), FontHeight), "[" + current.Field.Name + "]", TextStyle); LineIteration++; GUI.Label(new Rect(XPos, YPos + FontHeight * LineIteration, (MarginWidth * Screen.width), FontHeight), "[Cur=" + current.getCurrentValue().ToString() + "]", TextStyle); LineIteration++; GUI.Label(new Rect(XPos, YPos + FontHeight * LineIteration, (MarginWidth * Screen.width), FontHeight), "[Min=" + current.MinimumValue.ToString() + "]", TextStyle); LineIteration++; GUI.Label(new Rect(XPos, YPos + FontHeight * LineIteration, (MarginWidth * Screen.width), FontHeight), "[Max=" + current.MaximumValue.ToString() + "]", TextStyle); LineIteration++; GUI.Label(new Rect(XPos, YPos + FontHeight * LineIteration, (MarginWidth * Screen.width), FontHeight), "[Avrg=" + current.Average.ToString() + "]", TextStyle); LineIteration++; LineIteration++; VariableIteration++; } #endregion #region Footer this.Opacity = GUI.HorizontalSlider(new Rect(XPos, Screen.height - FontHeight * 3, PanelWidth, FontHeight), this.Opacity, 0.0f, 1.0f); if (GUI.Button(new Rect(XPos, Screen.height - FontHeight * 2, PanelWidth * 0.5f, FontHeight), this.LayoutMode.ToString())) { if (this.LayoutMode == eLayoutMode.Stacked) { this.LayoutMode = eLayoutMode.Overlapped; } else { this.LayoutMode = eLayoutMode.Stacked; } } if (GUI.Button(new Rect(XPos + PanelWidth * 0.5f, Screen.height - FontHeight * 2, PanelWidth * 0.5f, FontHeight), "Abs")) { this.AbsoluteMode = !this.AbsoluteMode; } if (GUI.Button(new Rect(XPos, Screen.height - FontHeight, PanelWidth, FontHeight), "Clear")) { foreach (KeyValuePair <string, DBG_DataCollector> kvp in this.WatchDict) { kvp.Value.clearData(); } } #endregion }