// Crest Water System // Copyright © 2024 Wave Harmonic. All rights reserved. using UnityEditor; using UnityEngine; using WaveHarmonic.Crest.Editor; namespace WaveHarmonic.Crest.ShallowWater.Editor { [CustomEditor(typeof(ShallowWaterSimulation))] sealed class ShallowWaterSimulationEditor : Inspector { const string k_SwitchToBaked = "Switch to Baked"; const string k_SwitchToRealTime = "Switch to Real-Time"; protected override void RenderInspectorGUI() { base.RenderInspectorGUI(); EditorGUILayout.Space(); var target = this.target as ShallowWaterSimulation; var padding = GUI.skin.GetStyle("HelpBox").padding; GUI.skin.GetStyle("HelpBox").padding = new(10, 10, 10, 10); EditorGUILayout.HelpBox($"Resolution: {target.Resolution}", MessageType.None); GUI.skin.GetStyle("HelpBox").padding = padding; } protected override void RenderAfterInspectorGUI() { base.RenderAfterInspectorGUI(); var target = this.target as ShallowWaterSimulation; EditorGUILayout.Space(); if (target.Mode == ShallowWaterSimulationMode.RealTime) { if (target._SampleDepthProbeDirectly && target._DepthProbe == null && !target.TryGetComponent(out target._DepthProbe) && GUILayout.Button("Add Depth Probe")) { var probe = Undo.AddComponent(target.gameObject); probe.Managed = true; probe.Scale = new(target._Width, target._Width); probe.OverridePosition = target.Movable; } if (target.DisplacementTarget == ShallowWaterSimulationInjection.Level && target.LevelTexture != null && GUILayout.Button(k_SwitchToBaked)) { Undo.RecordObject(target, k_SwitchToBaked); target._Mode = ShallowWaterSimulationMode.Baked; EditorUtility.SetDirty(target); } if (target.DisplacementTarget == ShallowWaterSimulationInjection.Level && GUILayout.Button("Bake Output")) { target.Bake(); } if (GUILayout.Button("Reset Simulation")) { target.ResetSimulation(); } if (target._DepthProbe != null && GUILayout.Button("Populate Depth Probe & Reset Simulation")) { target._DepthProbe.Populate(); target.ResetSimulation(); } } else { if (GUILayout.Button(k_SwitchToRealTime)) { Undo.RecordObject(target, k_SwitchToRealTime); target._Mode = ShallowWaterSimulationMode.RealTime; EditorUtility.SetDirty(target); } } } } }