#if UNITY_EDITOR using UnityEditor; using UnityEngine; namespace AibisDream { [CustomEditor(typeof(EyeSystem))] public class EyeSystemEditor : Editor { private bool editorOverlayPreview; private float editorBlinkPreview = 1f; public override void OnInspectorGUI() { serializedObject.Update(); DrawPropertiesExcluding(serializedObject, "m_Script", "visualSettings", "replayFocusedEffectOnSettingsChange"); SerializedProperty visualSettings = serializedObject.FindProperty("visualSettings"); SerializedProperty replayOnChange = serializedObject.FindProperty("replayFocusedEffectOnSettingsChange"); if (visualSettings != null) { EditorGUILayout.Space(6f); EditorGUILayout.LabelField("Visual Tuning", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(visualSettings, includeChildren: true); bool visualChanged = EditorGUI.EndChangeCheck(); EditorGUILayout.Space(4f); EditorGUILayout.PropertyField(replayOnChange); EditorGUILayout.HelpBox( "常驻视线 = 椭圆(eyeWidth / eyeHeight)。\n" + "眨眼 = 同一椭圆纵向压扁(BlinkOpen 1→0),不是另一套眼皮形状。\n" + "用「BlinkOpen 预览」滑条看闭合;eyeWidth / eyeHeight 在 BlinkOpen=1 时调。", MessageType.Info); DrawViewportOverlayControls(visualChanged); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("立即应用(Idle 预览)")) { serializedObject.ApplyModifiedProperties(); GetEyeSystem().ApplyVisualSettingsNow(previewIdleState: true); } if (GUILayout.Button("重播当前目标效果")) { serializedObject.ApplyModifiedProperties(); GetEyeSystem().ApplyVisualSettingsNow(replayFocusedEffect: true); } EditorGUILayout.EndHorizontal(); if (visualChanged) { serializedObject.ApplyModifiedProperties(); var system = GetEyeSystem(); system.ApplyVisualSettingsNow( previewIdleState: !Application.isPlaying, replayFocusedEffect: Application.isPlaying && replayOnChange.boolValue); if (editorOverlayPreview) { RefreshEditorOverlayPreview(system); } return; } } else { EditorGUILayout.HelpBox( "visualSettings 未找到。请确认 EyeSystem.cs 已编译通过。", MessageType.Warning); } serializedObject.ApplyModifiedProperties(); } private void DrawViewportOverlayControls(bool visualChanged) { EditorGUILayout.Space(4f); EditorGUILayout.LabelField("Viewport Overlay 预览", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); editorOverlayPreview = EditorGUILayout.Toggle("Edit 模式预览遮罩", editorOverlayPreview); if (EditorGUI.EndChangeCheck() || visualChanged) { serializedObject.ApplyModifiedProperties(); var system = GetEyeSystem(); if (editorOverlayPreview) { RefreshEditorOverlayPreview(system); } else { EnsureOverlay(system).ExitEditorPreview(); editorBlinkPreview = 1f; } } GUI.enabled = editorOverlayPreview; EditorGUI.BeginChangeCheck(); editorBlinkPreview = EditorGUILayout.Slider("BlinkOpen 预览(眨眼)", editorBlinkPreview, 0f, 1f); if (EditorGUI.EndChangeCheck()) { var overlay = EnsureOverlay(GetEyeSystem()); overlay.SetBlinkOpenPreview(editorBlinkPreview); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("BlinkOpen = 睁开")) { editorBlinkPreview = 1f; EnsureOverlay(GetEyeSystem()).SetBlinkOpenPreview(1f); } if (GUILayout.Button("BlinkOpen = 闭合")) { editorBlinkPreview = 0f; EnsureOverlay(GetEyeSystem()).SetBlinkOpenPreview(0f); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; EditorGUILayout.BeginHorizontal(); GUI.enabled = Application.isPlaying; if (GUILayout.Button("测试眨眼动画")) { serializedObject.ApplyModifiedProperties(); var overlay = EnsureOverlay(GetEyeSystem()); editorBlinkPreview = 1f; overlay.SetBlinkOpenPreview(1f); overlay.PlayBlink(); } GUI.enabled = true; if (GUILayout.Button("刷新遮罩参数")) { serializedObject.ApplyModifiedProperties(); RefreshEditorOverlayPreview(GetEyeSystem()); } EditorGUILayout.EndHorizontal(); } private void RefreshEditorOverlayPreview(EyeSystem system) { var overlay = EnsureOverlay(system); overlay.EnterEditorPreview(system.VisualSettings); overlay.SetBlinkOpenPreview(editorBlinkPreview); } private static EyeViewportOverlay EnsureOverlay(EyeSystem system) { var overlay = system.GetComponentInChildren(true); if (overlay == null) { overlay = system.gameObject.AddComponent(); } return overlay; } private EyeSystem GetEyeSystem() { return (EyeSystem)target; } private void OnDisable() { if (!editorOverlayPreview || target == null) { return; } editorOverlayPreview = false; editorBlinkPreview = 1f; var system = target as EyeSystem; system?.GetComponentInChildren(true)?.ExitEditorPreview(); } } } #endif