Fix VideoPanel reference, automatically find Canvas/VideoPanel and add components if missing
This commit is contained in:
@@ -134,9 +134,22 @@ public class PingClickHandler : MonoBehaviour
|
||||
|
||||
// 隐藏视频面板
|
||||
var videoController = FindObjectOfType<VideoController>(true);
|
||||
if (videoController != null)
|
||||
if (videoController == null)
|
||||
{
|
||||
var allT = Resources.FindObjectsOfTypeAll<Transform>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,11 +151,28 @@ public class ShoseClickHandler : MonoBehaviour
|
||||
|
||||
// 显示 VideoPanel 并播放视频
|
||||
var videoController = FindObjectOfType<VideoController>(true);
|
||||
if (videoController == null)
|
||||
{
|
||||
var allT = Resources.FindObjectsOfTypeAll<Transform>();
|
||||
foreach (var t in allT)
|
||||
{
|
||||
if (t.name == "VideoPanel" && t.parent != null && t.parent.name == "Canvas")
|
||||
{
|
||||
videoController = t.gameObject.AddComponent<VideoController>();
|
||||
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<Transform>();
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user