private void OnEnable() { this.FindSerializedProperties(); this.ValidateNoise(); this._selectedPreset = (WindComponentEditor.WindPreset) this._preset.intValue; Undo.undoRedoPerformed += new Undo.UndoRedoCallback(this.OnUndoPerformed); }
private void ApplyPreset() { if (this._sourceWindZone.objectReferenceValue != (UnityEngine.Object)null) { if (!EditorUtility.DisplayDialog("Apply Preset?", "The wind settings are driven by a wind zone. Do you want to apply the preset to the source Wind Zone?", "Apply", "Cancel")) { this._selectedPreset = (WindComponentEditor.WindPreset) this._preset.intValue; return; } Undo.RecordObjects(new UnityEngine.Object[2] { this.target, this._sourceWindZone.objectReferenceValue }, "Load Wind Preset"); } else { Undo.RecordObject(this.target, "Load Wind Preset"); } WindComponent target = (WindComponent)this.target; switch (this._selectedPreset) { case WindComponentEditor.WindPreset.Calm: target.Settings = FWindSettings.Calm; break; case WindComponentEditor.WindPreset.Breeze: target.Settings = FWindSettings.Breeze; break; case WindComponentEditor.WindPreset.StrongBreeze: target.Settings = FWindSettings.StrongBreeze; break; case WindComponentEditor.WindPreset.Storm: target.Settings = FWindSettings.Storm; break; } target.Settings = new FWindSettings(target.Settings) { WindDirection = FWindSettings.RotationToDirection(target.transform.rotation) }; this.serializedObject.Update(); if (this._sourceWindZone.objectReferenceValue != (UnityEngine.Object)null) { ((WindComponent)this.target).Settings.ApplyToWindZone((WindZone)this._sourceWindZone.objectReferenceValue); EditorUtility.SetDirty(this._sourceWindZone.objectReferenceValue); } Undo.FlushUndoRecordObjects(); }
public override void OnInspectorGUI() { this.serializedObject.Update(); bool enabled = GUI.enabled; EditorGUI.BeginChangeCheck(); this._selectedPreset = (WindComponentEditor.WindPreset)EditorGUILayout.EnumPopup("Load Preset", (Enum)this._selectedPreset, (GUILayoutOption[])Array.Empty <GUILayoutOption>()); if (EditorGUI.EndChangeCheck() && (uint)this._selectedPreset > 0U) { this.ApplyPreset(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(this._sourceWindZone, (GUILayoutOption[])Array.Empty <GUILayoutOption>()); if (EditorGUI.EndChangeCheck()) { this.serializedObject.ApplyModifiedProperties(); if (this._sourceWindZone.objectReferenceValue != (UnityEngine.Object)null) { ((WindComponent)this.target).Zone = (WindZone)this._sourceWindZone.objectReferenceValue; } } if (this._sourceWindZone.objectReferenceValue != (UnityEngine.Object)null) { EditorGUILayout.HelpBox("Wind settings are loaded from Wind Zone component. Remove the Wind Zone component to manually modify the wind.", MessageType.Info); GUI.enabled = false; } EditorGUI.BeginChangeCheck(); GUILayout.Label("Wind", EditorStyles.boldLabel, (GUILayoutOption[])Array.Empty <GUILayoutOption>()); EditorGUILayout.PropertyField(this._windStrength, (GUILayoutOption[])Array.Empty <GUILayoutOption>()); EditorGUILayout.PropertyField(this._windSpeed, (GUILayoutOption[])Array.Empty <GUILayoutOption>()); EditorGUILayout.PropertyField(this._turbulence, (GUILayoutOption[])Array.Empty <GUILayoutOption>()); GUI.enabled = enabled; GUILayout.Label("Noise", EditorStyles.boldLabel, (GUILayoutOption[])Array.Empty <GUILayoutOption>()); EditorGUILayout.PropertyField(this._gustNoise, (GUILayoutOption[])Array.Empty <GUILayoutOption>()); if (EditorGUI.EndChangeCheck()) { this._selectedPreset = WindComponentEditor.WindPreset.ClickToLoad; this.serializedObject.ApplyModifiedProperties(); ((WindComponent)this.target).Settings.Apply(this._gustNoise.objectReferenceValue as Texture2D); } if (this._selectedPreset == (WindComponentEditor.WindPreset) this._preset.intValue) { return; } this._preset.intValue = (int)this._selectedPreset; this.serializedObject.ApplyModifiedProperties(); }
private void OnUndoPerformed() { this.serializedObject.Update(); this._selectedPreset = (WindComponentEditor.WindPreset) this._preset.intValue; }