/// <summary> /// Renders content to the inspector panel /// </summary> public override void OnInspectorGUI() { // Pulls variables from runtime so we have the latest values. mSplineSO.Update(); // Allow the loop EditorGUI.BeginChangeCheck(); bool lNewLoop = EditorGUILayout.Toggle(new GUIContent("Loop", ""), mSpline.Loop); if (EditorGUI.EndChangeCheck() && lNewLoop != mSpline.Loop) { mIsDirty = true; Undo.RecordObject(mSpline, "Spine Loop"); mSpline.Loop = lNewLoop; } // Allow the segments to change EditorGUI.BeginChangeCheck(); int lNewSegments = EditorGUILayout.IntField(new GUIContent("Segments", ""), mSpline.Segments); if (EditorGUI.EndChangeCheck() && lNewSegments != mSpline.Segments) { mIsDirty = true; Undo.RecordObject(mSpline, "Spine Segments"); mSpline.Segments = lNewSegments; } // Draw all the curve points for (int i = 0; i < mSpline.ControlPointCount; i++) { EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); Vector3 lOldPoint = mSpline.GetControlPoint(i); Vector3 lNewPoint = EditorGUILayout.Vector3Field(new GUIContent("Control Point " + i.ToString(), ""), lOldPoint); if (EditorGUI.EndChangeCheck() && lNewPoint != lOldPoint) { mIsDirty = true; Undo.RecordObject(mSpline, "Spline Point Move"); mSpline.SetControlPoint(i, lNewPoint); } GUILayout.Space(5); int lOldConstraint = mSpline.GetControlPointConstraint(i); int lNewConstraint = EditorGUILayout.IntField(new GUIContent("", ""), lOldConstraint, GUILayout.Width(20)); if (lOldConstraint != lNewConstraint) { mIsDirty = true; Undo.RecordObject(mSpline, "Spline Point Constraint"); mSpline.SetControlPointConstraint(i, lNewConstraint); } EditorGUILayout.EndHorizontal(); } // Create a button for adding a new point if (GUILayout.Button("Add Point")) { mIsDirty = true; mSpline.AddControlPoint(); mSelectedControlPointIndex = mSpline.ControlPointCount - 1; } // Create a button for adding a new point if (GUILayout.Button("Insert Point")) { mIsDirty = true; mSpline.InsertControlPoint(mSelectedControlPointIndex); } // Create a button for deleting a point if (GUILayout.Button("Delete Point")) { mIsDirty = true; mSpline.DeleteControlPoint(mSelectedControlPointIndex); mSelectedControlPointIndex = -1; } // If there is a change... update. if (mIsDirty) { // Flag the object as needing to be saved EditorUtility.SetDirty(mSpline); #if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 EditorApplication.MarkSceneDirty(); #else if (!EditorApplication.isPlaying) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } #endif // Pushes the values back to the runtime so it has the changes mSplineSO.ApplyModifiedProperties(); // Clear out the dirty flag mIsDirty = false; } }