using AibisDream.UI; using UnityEditor; using UnityEngine; namespace AibisDream.UI.Editor { [CustomEditor(typeof(DreamTerminalUI))] [CanEditMultipleObjects] internal sealed class DreamTerminalUIEditor : UnityEditor.Editor { void OnEnable() { EditorApplication.update += OnEditorUpdate; RefreshAllTargets(); } void OnDisable() { EditorApplication.update -= OnEditorUpdate; } void OnEditorUpdate() { if (Application.isPlaying) return; RefreshAllTargets(); } public override void OnInspectorGUI() { serializedObject.Update(); EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); bool changed = EditorGUI.EndChangeCheck(); serializedObject.ApplyModifiedProperties(); if (changed) RefreshAllTargets(); EditorGUILayout.Space(); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("Preview / Frame Only")) ApplyPreset(PreviewPreset.FrameOnly); if (GUILayout.Button("Preview / Waiting Input")) ApplyPreset(PreviewPreset.WaitingInput); } if (GUILayout.Button("Preview / Clear")) ApplyPreset(PreviewPreset.Clear); } enum PreviewPreset { FrameOnly, WaitingInput, Clear } void ApplyPreset(PreviewPreset preset) { Undo.RecordObjects(targets, "Dream Terminal Preview Preset"); foreach (Object o in targets) { var ui = (DreamTerminalUI)o; SerializedObject so = new SerializedObject(ui); switch (preset) { case PreviewPreset.FrameOnly: so.FindProperty("previewInEditor").boolValue = true; so.FindProperty("previewStage").enumValueIndex = (int)DreamTerminalUI.PreviewStage.FrameOnly; so.FindProperty("previewAlpha").floatValue = 1f; so.FindProperty("previewMorphProgress").floatValue = 0.65f; break; case PreviewPreset.WaitingInput: so.FindProperty("previewInEditor").boolValue = true; so.FindProperty("previewStage").enumValueIndex = (int)DreamTerminalUI.PreviewStage.WaitingInput; so.FindProperty("previewAlpha").floatValue = 1f; so.FindProperty("previewMorphProgress").floatValue = 1f; break; case PreviewPreset.Clear: so.FindProperty("previewInEditor").boolValue = false; break; } so.ApplyModifiedProperties(); ui.EditorRunPreviewTick(); } } void RefreshAllTargets() { foreach (Object o in targets) { var ui = o as DreamTerminalUI; if (ui != null) ui.EditorRunPreviewTick(); } } } }