protected virtual void HeaderGUI() { SplineUser user = (SplineUser)target; Undo.RecordObject(user, "Inspector Change"); SplineComputer lastSpline = (SplineComputer)spline.objectReferenceValue; EditorGUILayout.PropertyField(spline); SplineComputer newSpline = (SplineComputer)spline.objectReferenceValue; if (lastSpline != (SplineComputer)spline.objectReferenceValue) { for (int i = 0; i < users.Length; i++) { if (lastSpline != null) { lastSpline.Unsubscribe(users[i]); } if (newSpline != null) { newSpline.Subscribe(users[i]); } } user.Rebuild(); } if (user.spline == null) { EditorGUILayout.HelpBox("No SplineComputer is referenced. Link a SplineComputer to make this SplineUser work.", MessageType.Error); } settingsFoldout = EditorGUILayout.Foldout(settingsFoldout, "User Configuration", foldoutHeaderStyle); if (settingsFoldout) { EditorGUI.indentLevel++; if (showClip) { InspectorClipEdit(); } if (showUpdateMethod) { EditorGUILayout.PropertyField(updateMethodProperty); } EditorGUILayout.PropertyField(autoUpdateProperty, new GUIContent("Auto Rebuild")); if (showMultithreading) { EditorGUILayout.PropertyField(multithreadedProperty); } EditorGUILayout.PropertyField(buildOnAwakeProperty); EditorGUILayout.PropertyField(buildOnEnableProperty); EditorGUI.indentLevel--; } }
protected virtual void OnDestroy() { SplineUser user = (SplineUser)target; if (Application.isEditor && !Application.isPlaying) { if (user == null) { OnDelete(); //The object or the component is being deleted } else if (user.spline != null) { user.Rebuild(); } } SplineComputerEditor.hold = false; }
protected virtual void HeaderGUI() { SplineUser user = (SplineUser)target; bool isClosed = true; bool loopSamples = true; for (int i = 0; i < users.Length; i++) { if (users[i].spline == null) { isClosed = false; } else if (!users[i].spline.isClosed) { isClosed = false; } else if (!users[i].loopSamples) { loopSamples = false; } } Undo.RecordObject(user, "Inspector Change"); SplineComputer lastSpline = (SplineComputer)spline.objectReferenceValue; EditorGUILayout.PropertyField(spline); SplineComputer newSpline = (SplineComputer)spline.objectReferenceValue; if (lastSpline != (SplineComputer)spline.objectReferenceValue) { for (int i = 0; i < users.Length; i++) { if (lastSpline != null) { lastSpline.Unsubscribe(users[i]); } if (newSpline != null) { newSpline.Subscribe(users[i]); } } user.Rebuild(); } //if (GUI.changed) serializedObject.ApplyModifiedProperties(); if (user.spline == null) { EditorGUILayout.HelpBox("No SplineComputer is referenced. Link a SplineComputer to make this SplineUser work.", MessageType.Error); } if (showClip) { float clipFrom = 0f, clipTo = 1f; clipFrom = this.clipFrom.floatValue; clipTo = this.clipTo.floatValue; float lastFrom = clipFrom, lastTo = clipTo; EditorGUI.BeginChangeCheck(); if (isClosed && loopSamples) { EditorGUILayout.BeginHorizontal(); if (EditButton(_editIndex == 0)) { if (_editIndex == 0) { _editIndex = -1; } else { _editIndex = 0; } } EditorGUILayout.BeginVertical(); clipFrom = EditorGUILayout.Slider("Clip From", clipFrom, 0f, 1f); clipTo = EditorGUILayout.Slider("Clip To", clipTo, 0f, 1f); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal(); if (EditButton(_editIndex == 0)) { if (_editIndex == 0) { _editIndex = -1; } else { _editIndex = 0; } } EditorGUIUtility.labelWidth = 80f; EditorGUILayout.MinMaxSlider(new GUIContent("Clip Range:"), ref clipFrom, ref clipTo, 0f, 1f); EditorGUIUtility.labelWidth = 0f; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(30)); clipFrom = EditorGUILayout.FloatField(clipFrom); clipTo = EditorGUILayout.FloatField(clipTo); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { this.clipFrom.floatValue = clipFrom; this.clipTo.floatValue = clipTo; } SplineComputerEditor.hold = _editIndex >= 0; if (isClosed) { EditorGUILayout.PropertyField(this.loopSamples, new GUIContent("Loop Samples")); } if (!this.loopSamples.boolValue || !isClosed) { if (this.clipFrom.floatValue > this.clipTo.floatValue) { float temp = this.clipTo.floatValue; this.clipTo.floatValue = this.clipFrom.floatValue; this.clipFrom.floatValue = temp; } } } settings = EditorGUILayout.Foldout(settings, "Settings"); if (settings) { EditorGUI.indentLevel++; if (showUpdateMethod) { EditorGUILayout.PropertyField(updateMethod); } EditorGUILayout.PropertyField(autoUpdate, new GUIContent("Auto Rebuild")); if (showMultithreading) { EditorGUILayout.PropertyField(multithreaded); } EditorGUILayout.PropertyField(buildOnAwake); EditorGUILayout.PropertyField(buildOnEnable); EditorGUI.indentLevel--; } }