private void OnGUI() { ValidateState(); graphX = position.width * graphXStartMult; graphY = graphX * graphYStartMult; float graphWidth = graphWidthMult * position.width; float graphHeight = graphWidth * graphHeightMult; float labelWidth = position.width * 0.1f; float labelHeight = 20.0f; int graphCount = telemetryGraphs.Length; int currGraph = 0; scrollPosition = GUI.BeginScrollView(new Rect(0.0f, 0.0f, position.width, position.height), scrollPosition, new Rect(0.0f, 0.0f, position.width, scrollViewHeight), false, true); scrollViewHeight = 100.0f; for (int y = 0; y < 512; ++y) //if there's more than 1024 graphs we gots problems { graphX = position.width * graphXStartMult; bool anyVisible = false; for (int x = 0; x < 2; ++x) { Rect graphRect = new Rect(graphX, graphY, graphWidth, graphHeight); TelemetryGraphData graphData = telemetryGraphs[currGraph]; if (!graphData.visible) { graphRect = new Rect(graphX, graphY, graphWidth, labelHeight); } else { anyVisible = true; } GUILayout.BeginArea(graphRect); GUILayout.Box("", GUILayout.Width(graphWidth), GUILayout.Height(graphHeight)); //draw markings Handles.color = Color.grey; Handles.DrawLine(new Vector3(0.0f, graphHeight * 0.5f, 0.0f), new Vector3(graphWidth, graphHeight * 0.5f, 0)); //draw label GUILayout.BeginArea(new Rect((graphWidth * 0.5f) - (labelWidth * 0.5f), 0.0f, labelWidth, labelHeight)); GUILayout.Label(graphData.valueName, GUILayout.Width(labelWidth), GUILayout.Height(labelHeight)); GUILayout.EndArea(); float buttonWidth = labelHeight; float buttonHeight = labelHeight; GUILayout.BeginArea(new Rect(graphRect.width - buttonWidth, 0.0f, buttonWidth, labelHeight)); if (GUILayout.Button(graphData.visible ? "X" : "O", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight))) { graphData.visible = !graphData.visible; SortGraphData(); } GUILayout.EndArea(); if (graphData.visible) { //draw max value GUILayout.BeginArea(new Rect(0.0f, 0.0f, labelWidth, labelHeight)); GUILayout.Label("" + graphData.maxValue, GUILayout.Width(labelWidth), GUILayout.Height(labelHeight)); GUILayout.EndArea(); //draw min value GUILayout.BeginArea(new Rect(0.0f, graphHeight - labelHeight, labelWidth, labelHeight)); GUILayout.Label("" + graphData.minValue, GUILayout.Width(labelWidth), GUILayout.Height(labelHeight)); GUILayout.EndArea(); if (SimFeedbackUnity.Instance != null) { graphData.AdjustMinMax(SimFeedbackUnity.Instance.GetRawTelemetryHistory()); graphData.AdjustMinMax(SimFeedbackUnity.Instance.GetFilteredTelemetryHistory()); DrawGraph(graphData, SimFeedbackUnity.Instance.GetRawTelemetryHistory(), Color.red, graphWidth, graphHeight); DrawGraph(graphData, SimFeedbackUnity.Instance.GetFilteredTelemetryHistory(), Color.green, graphWidth, graphHeight); } } GUILayout.EndArea(); graphX += graphWidth + (graphSpacingXMult * position.width); graphCount--; if (graphCount <= 0) { break; } currGraph++; } if (graphCount <= 0) { break; } float yHeightIncrement; if (anyVisible) { yHeightIncrement = graphHeight + ((graphSpacingXMult * position.width) * graphSpacingYMult); } else { yHeightIncrement = labelHeight + ((graphSpacingXMult * position.width) * graphSpacingYMult); } graphY += yHeightIncrement; scrollViewHeight += yHeightIncrement; } GUI.EndScrollView(); }