/// <summary> /// Draw inspector elements and UI /// </summary> public override void OnInspectorGUI() { _spline = target as Spline; //Set up the box style if null if (_menuBoxStyle == null) { _menuBoxStyle = new GUIStyle(GUI.skin.box); _menuBoxStyle.normal.textColor = GUI.skin.label.normal.textColor; _menuBoxStyle.fontStyle = FontStyle.Bold; _menuBoxStyle.alignment = TextAnchor.UpperLeft; } EditorGUI.BeginChangeCheck(); SMR_Theme theme = (SMR_Theme)EditorGUILayout.ObjectField("Theme", _spline.Theme, typeof(ScriptableObject), false); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Changed Theme"); MarkSceneAlteration(); _spline.Theme = theme; } EditorGUI.BeginChangeCheck(); _selectedMenuIndex = GUILayout.Toolbar(_selectedMenuIndex, _toolbarMenuOptions); if (EditorGUI.EndChangeCheck()) { GUI.FocusControl(null); } GUILayout.BeginVertical(_menuBoxStyle); if (_selectedMenuIndex == (int)SplineInspectorMenu.CurveSettings) { #region Curve Settings /* * Curve Settings */ GUILayout.Label("Curve Settings", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); bool loop = EditorGUILayout.Toggle("Close Loop", _spline.Loop); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Toggle Loop"); MarkSceneAlteration(); _spline.Loop = loop; } EditorGUI.BeginChangeCheck(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("New Curve Length"); int newCurveLength = Mathf.Abs(EditorGUILayout.IntField((int)_spline.newCurveLength, GUILayout.MaxWidth(100))); GUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Change Curve Length"); MarkSceneAlteration(); _spline.newCurveLength = newCurveLength < 3 ? 3 : newCurveLength; } /* * Curve Operations */ GUILayout.Label("Curve Operations", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); if (GUILayout.Button(_btnAddNewCurve)) { AddCurve(); } if (GUILayout.Button(_btnTurnLeft)) { TurnCurve_Left(); } if (GUILayout.Button(_btnTurnUpwards)) { TurnCurve_Upwards(); } GUILayout.EndVertical(); GUILayout.BeginVertical(); if (GUILayout.Button(_btnRemoveCurve)) { RemoveCurve(); } if (GUILayout.Button(_btnTurnRight)) { TurnCurve_Right(); } if (GUILayout.Button(_btnTurnDownwards)) { TurnCurve_Downwards(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button(_btnResetCurve)) { ResetCurve(); } GUILayout.EndHorizontal(); //Ignore first/last controlpoints and bezier handles using (new EditorGUI.DisabledScope(((_selectedIndex == 0) || (_selectedIndex == (_spline.ControlPointCount - 1))) || (_selectedIndex % 3 != 0))) { GUILayout.BeginHorizontal(); if (GUILayout.Button(_btnSubdivideCurve)) { Undo.RecordObject(_spline, "Subdivide Curve"); _spline.SubdivideCurve(_selectedIndex); MarkSceneAlteration(); } if (GUILayout.Button(_btnDissolveCurve)) { Undo.RecordObject(_spline, "Dissolve Curve"); _spline.DissolveCurve(_selectedIndex); MarkSceneAlteration(); } GUILayout.EndHorizontal(); } #endregion } else if (_selectedMenuIndex == (int)SplineInspectorMenu.SplineSettings) { #region Spline Settings /* * Spline Settings */ GUILayout.Label("Spline Settings", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); bool followTerrain = EditorGUILayout.Toggle("Follow Terrain", _spline.FollowTerrain); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Follow Terrain Property"); MarkSceneAlteration(); _spline.FollowTerrain = followTerrain; } EditorGUI.BeginChangeCheck(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Terrain Check Distance"); float terrainCheckDistance = EditorGUILayout.FloatField(_spline.TerrainCheckDistance, GUILayout.MaxWidth(100)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Terrain Check Distance"); MarkSceneAlteration(); _spline.TerrainCheckDistance = Mathf.Abs(terrainCheckDistance); } GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); SplineUpwardsDirection splineUpwardsDirection = (SplineUpwardsDirection)EditorGUILayout.EnumPopup("Custom Upwards Direction", _spline.SplineUpwardsDirection); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Custom Upwards Direction"); MarkSceneAlteration(); _spline.SplineUpwardsDirection = splineUpwardsDirection; } /* * Spline Operations */ GUILayout.Label("Spline Operations", EditorStyles.boldLabel); using (new EditorGUI.DisabledScope(((_selectedIndex == 0) || (_selectedIndex == (_spline.ControlPointCount - 1))) || (_selectedIndex % 3 != 0))) { GUILayout.BeginHorizontal(); if (GUILayout.Button(_btnSplitSpline)) { Undo.RecordObject(_spline, "Split Spline"); _spline.SplitSpline(_selectedIndex); MarkSceneAlteration(); } } if (GUILayout.Button(_btnAppendSpline)) { Undo.RecordObject(_spline, "Append"); Selection.activeGameObject = _spline.AppendSpline(); MarkSceneAlteration(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button(_btnFlatten)) { Undo.RecordObject(_spline, "Flatten"); _spline.Flatten(); MarkSceneAlteration(); } if (GUILayout.Button(_btnResetRotations)) { Undo.RecordObject(_spline, "Reset Rotations"); _spline.ResetRotations(); MarkSceneAlteration(); } if (GUILayout.Button(_btnResetSpline)) { Undo.RecordObject(_spline, "Reset"); _spline.Reset(); MarkSceneAlteration(); } GUILayout.EndHorizontal(); #endregion } else if (_selectedMenuIndex == (int)SplineInspectorMenu.HandlesSettings) { #region Handles Settings /* * Handles Settings */ GUILayout.Label("Handles Settings", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); HandlesVisibility selectedHandlesVisibility = (HandlesVisibility)EditorGUILayout.EnumPopup("Handles Visibility", _spline.HandlesVisibility); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Handle Visibility Changed"); MarkSceneAlteration(); _spline.HandlesVisibility = selectedHandlesVisibility; } EditorGUI.BeginChangeCheck(); float autoHandleSpacing = EditorGUILayout.Slider("Automatic Handles Spacing", _spline.AutoHandleSpacing, 0f, 1f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(_spline, "Automatic Handles Spacing"); MarkSceneAlteration(); _spline.AutoHandleSpacing = autoHandleSpacing; } /* * Selected Handle */ if (_selectedIndex >= 0 && _selectedIndex < _spline.ControlPointCount) { DrawSelectedPointInspector(); } else { GUILayout.Label(string.Format("No Handle Selected{0}Click on a handle to select it", System.Environment.NewLine), EditorStyles.boldLabel); } #endregion } GUILayout.EndVertical(); }