private static void DrawPoint(Vector2 pos) { // 1. make a Cross around zero Vector2 _pointA = new Vector2(0.0f, -1.0f); Vector2 _pointB = new Vector2(0.0f, 1.0f); Vector2 _pointC = new Vector2(1.0f, 0.0f); Vector2 _pointD = new Vector2(-1.0f, 0.0f); // 2. move the cross into place // Y: value // X: Position Vector2 _a = _pointA + pos; Vector2 _b = _pointB + pos; Vector2 _c = _pointC + pos; Vector2 _d = _pointD + pos; UnityRandomEditorDraw.DrawLine(_a, _b, Color.blue, 1.0f, true); UnityRandomEditorDraw.DrawLine(_c, _d, Color.blue, 1.0f, true); }
// OnGUI void OnGUI() { // SAMPLING SIZE switch (_randomType) { case RandomType.NUMBER: max_samplig_size = 10000; break; case RandomType.VECTOR_2D: max_samplig_size = 5000; break; case RandomType.VECTOR_3D: max_samplig_size = 1000; break; case RandomType.COLOR: max_samplig_size = 400; break; case RandomType.DICE: max_samplig_size = 5000; break; default: max_samplig_size = 5000; break; } // ADJUST CURRENT SIZE if (samplig_size > max_samplig_size) { samplig_size = max_samplig_size; } // DRAWING AREA GUILayout.BeginArea(new Rect(_area_margin, _area_margin, _graph_area_width, _graph_area_height)); GUILayout.Box("", GUILayout.Width(_graph_area_width), GUILayout.Height(_graph_area_height)); if (randomList != null && randomList.Count > 0) { switch (_randomType) { case RandomType.NUMBER: switch (_randomNumberType) { case RandomNumberType.VALUE: UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height); break; case RandomNumberType.RANGE: UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, _range_min, _range_max); break; default: UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, true); break; } break; case RandomType.VECTOR_2D: UnityRandomEditorDraw.DrawV2Plot(randomList, _graph_area_width, _graph_area_height, _randomVector2DType); break; case RandomType.VECTOR_3D: UnityRandomEditorDraw.DrawV3Plot(randomList, _graph_area_width, _graph_area_height, _randomVector3DType, alpha, beta); break; case RandomType.COLOR: UnityRandomEditorDraw.DrawColorPlot(randomList, _graph_area_width, _graph_area_height); break; case RandomType.DICE: // generate a new ArrayList with the Sum, then send to DrawXYPlot ArrayList sums = RandomDiceSums(); sums.Sort(); UnityRandomEditorDraw.DrawXYPlot(sums, _graph_area_width, _graph_area_height, true); break; case RandomType.SHUFFLEBAG: UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, shufflebag[0], shufflebag[shufflebag.Length - 1]); break; case RandomType.WEIGHTEDBAG: UnityRandomEditorDraw.DrawXYPlot(randomList, _graph_area_width, _graph_area_height, 1, 10); break; default: // defailt is no drawing break; } } GUILayout.EndArea(); // SAMPLE RANDOM BUTTON GUILayout.BeginArea(new Rect(_area_margin, _area_margin + _area_margin + _graph_area_height, _graph_area_width, 60)); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Generate Random Numbers", GUILayout.Height(60))) { this.SampleRandom(); } EditorGUILayout.EndHorizontal(); GUILayout.EndArea(); // CONTROL PANEL RIGHT BOX GUILayout.BeginArea(new Rect(_area_margin + _area_margin + _graph_area_width, _area_margin, _editor_area_width, _editor_area_height)); // TITLE EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("CHOOSE TYPE OF RANDOM TYPE: "); _randomType = (RandomType)EditorGUILayout.EnumPopup(_randomType, GUILayout.Width(100)); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); switch (_randomType) { case RandomType.NUMBER: RandomNumbersGUI(); break; case RandomType.VECTOR_2D: RandomVector2DGUI(); break; case RandomType.VECTOR_3D: RandomVector3DGUI(); break; case RandomType.COLOR: RandomColorGUI(); break; case RandomType.DICE: RandomDiceGUI(); break; case RandomType.SHUFFLEBAG: ShuffleBagGUI(); break; case RandomType.WEIGHTEDBAG: ShuffleBagGUI(); break; default: break; } EditorGUILayout.BeginVertical("box"); samplig_size = EditorGUILayout.IntSlider("Sampling Size:", samplig_size, 1, max_samplig_size); EditorGUILayout.EndVertical(); if (randomList != null && randomList.Count > 0) { EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("SAVE", GUILayout.Width(100))) { this.Save(); } GUILayout.FlexibleSpace(); filename = EditorGUILayout.TextField(filename); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } // 3D VIEWS BUTTONS if (randomList != null && randomList.Count > 0 && _randomType == RandomType.VECTOR_3D && (_randomVector3DType == RandomVector3DType.INSPHERE || _randomVector3DType == RandomVector3DType.ONSPHERE || _randomVector3DType == RandomVector3DType.ONCAP || _randomVector3DType == RandomVector3DType.ONRING)) { EditorGUILayout.BeginVertical("box"); String rotationLabel = rotation ? "STOP ROTATE VIEW" : "START ROTATE VIEW"; if (GUILayout.Button(rotationLabel, GUILayout.Height(60))) { rotation = !rotation; } EditorGUILayout.EndVertical(); } GUILayout.EndArea(); // if GUI has changed empty the Array if (GUI.changed && randomList != null && randomList.Count != 0) { CleanList(); this.Repaint(); } // if Array is empty stop rotation and reset alpha/beta if (randomList == null || randomList.Count == 0) { rotation = false; alpha = beta = 0; } }