diff --git a/Assets/Scripts/MiniGame/Peipei/Eye/EyeSystem.cs b/Assets/Scripts/MiniGame/Peipei/Eye/EyeSystem.cs index 3e01c9b1c..abf78d9df 100644 --- a/Assets/Scripts/MiniGame/Peipei/Eye/EyeSystem.cs +++ b/Assets/Scripts/MiniGame/Peipei/Eye/EyeSystem.cs @@ -65,6 +65,23 @@ namespace AibisDream Init(); } + private bool EnsureMouseFollowAndZoom() + { + if (mouseFollowAndZoom != null) + { + return true; + } + + mouseFollowAndZoom = FindObjectOfType(true); + if (mouseFollowAndZoom == null) + { + Debug.LogError("[EyeSystem] MouseFollowAndZoom 未找到,无法进入视觉模块。", this); + return false; + } + + return true; + } + public void Init() { FixSystemCenter.SystemDic.Register(this); @@ -81,6 +98,8 @@ namespace AibisDream { cameraManager.gameObject.SetActive(false); } + + EnsureMouseFollowAndZoom(); } private void LoadData(EyeData eyedata) @@ -90,6 +109,11 @@ namespace AibisDream public void OnEnter() { + if (!EnsureMouseFollowAndZoom()) + { + return; + } + // 先激活 ViewCamera if (cameraManager != null) { @@ -127,7 +151,11 @@ namespace AibisDream eyeStateEffect?.CleanupEffect(CurrentTarget); } - mouseFollowAndZoom.SetIsActive(false); + if (EnsureMouseFollowAndZoom()) + { + mouseFollowAndZoom.SetIsActive(false); + } + currentTarget = null; // 先关闭 EyeView CloseEyeView(); @@ -144,7 +172,7 @@ namespace AibisDream { SetEyeColorState(_eyeData.currentState); - mouseFollowAndZoom = FindObjectOfType(); + EnsureMouseFollowAndZoom(); } public EyeTarget FindEyeTargetByName(string name) @@ -166,6 +194,11 @@ namespace AibisDream [YarnCommand("set_Eyetarget")] public IEnumerator SetTargetCoroutine(string targetName, bool startDialogue = true) { + if (!EnsureMouseFollowAndZoom()) + { + yield break; + } + mouseFollowAndZoom.SetIsLock(true); EyeTarget target = FindEyeTargetByName(targetName); if (target == null) @@ -209,6 +242,11 @@ namespace AibisDream [YarnCommand("Set_MouseMovementLockState")] public void SetMouseMovementLockState(bool isActive) { + if (!EnsureMouseFollowAndZoom()) + { + return; + } + mouseFollowAndZoom.SetIsLock(isActive); } @@ -503,4 +541,4 @@ namespace AibisDream yield break; } } -} \ No newline at end of file +}