113 lines
2.9 KiB
C#
113 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class RaycastManager : MonoBehaviour
|
|
{
|
|
private ClueBoardManager cm;
|
|
private EyeTransitionManager em;
|
|
|
|
public List<GraphicRaycaster> graphicRaycasters = new List<GraphicRaycaster>();
|
|
|
|
// 是否开启 ClueBoard 和 DeepView
|
|
public bool isClueBoardIn = false;
|
|
public bool isDeepViewIn = false;
|
|
|
|
void Start()
|
|
{
|
|
// 查找 ClueBoardManager 和 EyeTransitionManager
|
|
cm = FindObjectOfType<ClueBoardManager>();
|
|
em = FindObjectOfType<EyeTransitionManager>();
|
|
|
|
// 订阅事件
|
|
if (cm != null)
|
|
{
|
|
Debug.Log("Successfully found ClueBoardManager and subscribed to events.");
|
|
cm.OnClueBoardOpen += HandleClueBoardOpen;
|
|
cm.OnClueBoardClose += HandleClueBoardClose;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("EyeTransitionManager not found!");
|
|
}
|
|
|
|
if (em != null)
|
|
{
|
|
Debug.Log("Successfully found EyeTransitionManager and subscribed to events.");
|
|
em.OnGetMainView += HandleGetMainView;
|
|
em.OnGetDeepView += HandleGetDeepView;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("EyeTransitionManager not found!");
|
|
}
|
|
|
|
// 获取所有的 Raycastable Canvas 组件
|
|
}
|
|
|
|
// ClueBoard 打开时处理
|
|
private void HandleClueBoardOpen()
|
|
{
|
|
Debug.Log("打开ClueBoard");
|
|
isClueBoardIn = true;
|
|
UpdateRaycastStatus();
|
|
}
|
|
|
|
// ClueBoard 关闭时处理
|
|
private void HandleClueBoardClose()
|
|
{
|
|
Debug.Log("关闭ClueBoard");
|
|
isClueBoardIn = false;
|
|
UpdateRaycastStatus();
|
|
}
|
|
|
|
// MainView 激活时处理
|
|
private void HandleGetMainView()
|
|
{
|
|
Debug.Log("回到MainView");
|
|
isDeepViewIn = false;
|
|
UpdateRaycastStatus();
|
|
}
|
|
|
|
// DeepView 激活时处理
|
|
private void HandleGetDeepView()
|
|
{
|
|
Debug.Log("去到DeepView");
|
|
isDeepViewIn = true;
|
|
UpdateRaycastStatus();
|
|
}
|
|
|
|
// 更新 Raycast 组件的状态
|
|
private void UpdateRaycastStatus()
|
|
{
|
|
// 如果 ClueBoard 或 DeepView 开启,禁用所有 GraphicRaycaster
|
|
foreach (var raycaster in graphicRaycasters)
|
|
{
|
|
if (isClueBoardIn || isDeepViewIn)
|
|
{
|
|
raycaster.enabled = false;
|
|
}
|
|
else
|
|
{
|
|
raycaster.enabled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 确保在场景切换时销毁 RaycastManager
|
|
private void OnDestroy()
|
|
{
|
|
if (cm != null)
|
|
{
|
|
cm.OnClueBoardOpen -= HandleClueBoardOpen;
|
|
cm.OnClueBoardClose -= HandleClueBoardClose;
|
|
}
|
|
|
|
if (em != null)
|
|
{
|
|
em.OnGetMainView -= HandleGetMainView;
|
|
em.OnGetDeepView -= HandleGetDeepView;
|
|
}
|
|
}
|
|
} |