From 80cb7598e60c9dcd1a9ef67073f2a3f0c38554ca Mon Sep 17 00:00:00 2001 From: yangbear Date: Fri, 10 Jul 2026 04:41:26 +0800 Subject: [PATCH] Fix VideoPanel reference, automatically find Canvas/VideoPanel and add components if missing --- .../Scripts/Interaction/PingClickHandler.cs | 15 +++++++++- .../Scripts/Interaction/ShoseClickHandler.cs | 29 +++++++++++++++++++ Assets/Scripts/UI/PageController.cs | 11 +++++++ Assets/Scripts/UI/VideoController.cs | 3 ++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Interaction/PingClickHandler.cs b/Assets/Scripts/Interaction/PingClickHandler.cs index f9107b0..466a0d0 100644 --- a/Assets/Scripts/Interaction/PingClickHandler.cs +++ b/Assets/Scripts/Interaction/PingClickHandler.cs @@ -134,9 +134,22 @@ public class PingClickHandler : MonoBehaviour // 隐藏视频面板 var videoController = FindObjectOfType(true); - if (videoController != null) + if (videoController == null) + { + var allT = Resources.FindObjectsOfTypeAll(); + foreach (var t in allT) + { + if (t.name == "VideoPanel" && t.parent != null && t.parent.name == "Canvas") + { + t.gameObject.SetActive(false); + break; + } + } + } + else { videoController.StopVideo(); + videoController.gameObject.SetActive(false); } } } diff --git a/Assets/Scripts/Interaction/ShoseClickHandler.cs b/Assets/Scripts/Interaction/ShoseClickHandler.cs index 24a9fca..e7c5dc0 100644 --- a/Assets/Scripts/Interaction/ShoseClickHandler.cs +++ b/Assets/Scripts/Interaction/ShoseClickHandler.cs @@ -151,11 +151,28 @@ public class ShoseClickHandler : MonoBehaviour // 显示 VideoPanel 并播放视频 var videoController = FindObjectOfType(true); + if (videoController == null) + { + var allT = Resources.FindObjectsOfTypeAll(); + foreach (var t in allT) + { + if (t.name == "VideoPanel" && t.parent != null && t.parent.name == "Canvas") + { + videoController = t.gameObject.AddComponent(); + break; + } + } + } + if (videoController != null) { videoController.gameObject.SetActive(true); videoController.PlayVideo("tuoXieZi.mp4"); } + else + { + Debug.LogError("[ShoseClick] 未找到 VideoPanel,无法播放视频"); + } } public void ResetState() @@ -178,6 +195,18 @@ public class ShoseClickHandler : MonoBehaviour videoController.StopVideo(); videoController.gameObject.SetActive(false); } + else + { + var allT = Resources.FindObjectsOfTypeAll(); + foreach (var t in allT) + { + if (t.name == "VideoPanel" && t.parent != null && t.parent.name == "Canvas") + { + t.gameObject.SetActive(false); + break; + } + } + } var cam2 = GameObject.Find("camera2"); var cam3 = GameObject.Find("camera3"); diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index d51faf0..e38e77c 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -409,6 +409,17 @@ public class PageController : MonoBehaviour float waitTime = 1f; // 默认等1秒 var am = FindObjectOfType(); + // --- 新增:强制隐藏视频面板 --- + var allT = Resources.FindObjectsOfTypeAll(); + foreach (var t in allT) + { + if (t.name == "VideoPanel" && t.parent != null && t.parent.name == "Canvas") + { + t.gameObject.SetActive(false); + } + } + // ------------------------------ + // 实验刚开始,立刻激活鞋子,不等语音播完 var shose = GameObject.Find("Shose"); if (shose == null) diff --git a/Assets/Scripts/UI/VideoController.cs b/Assets/Scripts/UI/VideoController.cs index 8a82975..9ca1bba 100644 --- a/Assets/Scripts/UI/VideoController.cs +++ b/Assets/Scripts/UI/VideoController.cs @@ -18,7 +18,10 @@ public class VideoController : MonoBehaviour private void Awake() { if (_rawImage == null) _rawImage = GetComponent(); + if (_rawImage == null) _rawImage = gameObject.AddComponent(); + if (_videoPlayer == null) _videoPlayer = GetComponentInChildren(); + if (_videoPlayer == null) _videoPlayer = gameObject.AddComponent(); if (_videoPlayer != null) {