public override void OnInspectorGUI() { base.OnInspectorGUI(); float minX = serializedObject.FindProperty("minX").floatValue; float maxX = serializedObject.FindProperty("maxX").floatValue; float minY = serializedObject.FindProperty("minY").floatValue; float maxY = serializedObject.FindProperty("maxY").floatValue; ChartOrigins originType = serializedObject.FindProperty("useTopLeftOrigin").boolValue ? ChartOrigins.TopLeft : ChartOrigins.BottomLeft; Color bgColor = serializedObject.FindProperty("backgroundColor").colorValue; Color axesColor = serializedObject.FindProperty("axesColor").colorValue; Color gridColor = serializedObject.FindProperty("gridColor").colorValue; float gridCellHorSize = serializedObject.FindProperty("gridCellHorizontalSize").floatValue; float gridCellVerSize = serializedObject.FindProperty("gridCellVerticalSize").floatValue; GUILayout.BeginHorizontal(EditorStyles.helpBox); GUIChartEditor.BeginChart(10, 100, 100, 100, bgColor, GUIChartEditorOptions.ChartBounds(minX, maxX, minY, maxY), GUIChartEditorOptions.SetOrigin(originType), GUIChartEditorOptions.ShowAxes(axesColor), GUIChartEditorOptions.ShowGrid(gridCellHorSize, gridCellVerSize, gridColor, true) /*,GUIChartEditorOptions.ShowLabels("0.##", 1f, 1f, -0.1f, 1f, -0.075f, 1f)*/); // Draws lines SerializedProperty[] functions = new SerializedProperty[serializedObject.FindProperty("functions").arraySize]; for (int i = 0; i < functions.Length; i++) { functions[i] = serializedObject.FindProperty("functions").GetArrayElementAtIndex(i); Vector2[] points = new Vector2[functions[i].FindPropertyRelative("points").arraySize]; Color functionColor = functions[i].FindPropertyRelative("funColor").colorValue; for (int j = 0; j < points.Length; j++) { points[j] = functions[i].FindPropertyRelative("points").GetArrayElementAtIndex(j).vector2Value; } GUIChartEditor.PushLineChart(points, functionColor); } // Additional test: draws a lambda-defined function. GUIChartEditor.PushFunction(x => x * x * x, -10f, 10f, new Color(0f, 1f, 0f, 0.5f)); GUIChartEditor.EndChart(); GUILayout.EndHorizontal(); }
void Start() { float f(float x) { return(x * x * x); } var rend = GetComponent <MeshRenderer>(); rend.material.hideFlags = HideFlags.HideAndDontSave; rend.material.shader.hideFlags = HideFlags.HideAndDontSave; Texture2D tex = new Texture2D(300, 150); GUIChartEditor.BeginChart(new Rect(0, 0, 300, 150), Color.black, GUIChartEditorOptions.ChartBounds(-0.5f, 1.5f, -0.25f, 1.25f), GUIChartEditorOptions.SetOrigin(ChartOrigins.BottomLeft), GUIChartEditorOptions.ShowAxes(Color.white), GUIChartEditorOptions.ShowGrid(0.25f, 0.25f, Color.grey, true), GUIChartEditorOptions.DrawToTexture(tex, filtering, compression)); GUIChartEditor.PushFunction(f, -0.5f, 1.5f, Color.green); GUIChartEditor.EndChart(); rend.material.SetTexture("_MainTex", tex); }
private void WriteGraph() { GUIChartEditor.BeginChart(480, 480, 260, 260, Color.black, GUIChartEditorOptions.ChartBounds(-3, 50, -10, 106), GUIChartEditorOptions.SetOrigin(ChartOrigins.BottomLeft), GUIChartEditorOptions.ShowAxes(Color.white), GUIChartEditorOptions.ShowGrid(4, 20, new Color(0.2f, 0.2f, 0.2f, 1f), false) , GUIChartEditorOptions.ShowLabels("#", 20, -1, 22, 40, -1, 42, 60, -1, 62, 80, -1, 82, 100, -1, 102, 18, 1, -3, 19, 5, -3, 20, 29, -3, 20, 1.5f, -7, 24, 5.2f, -7, 4, 9.2f, -7, 8, 13.2f, -7, 12, 17.2f, -7, 16, 21.2f, -7, 20, 25.2f, -7, 24, 29.2f, -7, 4, 33.2f, -7, 8, 37.2f, -7, 12, 41.2f, -7, 16, 45.2f, -7, 20, 49.2f, -7 ) ); Vector2[] frame1 = new Vector2[] { new Vector2(0, 100f), new Vector2(48, 100), new Vector2(48, 0) }; GUIChartEditor.PushLineChart(frame1, Color.white); Vector2[] frame2 = new Vector2[] { new Vector2(4f, -10f), new Vector2(4f, 100) }; GUIChartEditor.PushLineChart(frame2, Color.white); Vector2[] frame4 = new Vector2[] { new Vector2(28f, -10f), new Vector2(28f, 100) }; GUIChartEditor.PushLineChart(frame4, Color.white); Vector2[] frame5 = new Vector2[] { new Vector2(48f, -10f), new Vector2(48f, 100) }; GUIChartEditor.PushLineChart(frame5, Color.white); Vector2[] frame3 = new Vector2[] { new Vector2(0f, 50), new Vector2(48, 50) }; GUIChartEditor.PushLineChart(frame3, Color.white); Vector2[] nowDtLine = new Vector2[] { new Vector2(_nowLine, -10f), new Vector2(_nowLine, 0f) }; GUIChartEditor.PushLineChart(nowDtLine, Color.red); DrawPublicPoint(); GUIChartEditor.PushLineChart(_userPoint, Color.red); GUIChartEditor.EndChart(); }