NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIWindowCameraManager.cs

117 lines
3.5 KiB
C#
Raw Normal View History

2025-12-29 19:18:24 +08:00
using PhxhSDK;
/// <summary>
/// UI窗口相机管理器
///
/// 核心理念:
/// - 根据窗口栈状态智能管理主相机的开关
/// - 当最上层窗口关闭时,检查下层是否还有需要关闭相机的窗口
/// - 只有当所有需要关闭相机的窗口都关闭后,才重新打开相机
///
/// 管理目标:
/// - 避免相机在多层UI之间频繁开关
/// - 保证相机状态与UI栈状态一致
/// - 处理时机在 UIWindowVisibilityManager 之后
/// </summary>
public class UIWindowCameraManager
{
#region Singleton
2025-12-29 19:18:24 +08:00
private static UIWindowCameraManager _instance;
2025-12-29 19:18:24 +08:00
public static UIWindowCameraManager Instance
{
get
{
if (_instance == null)
{
_instance = new UIWindowCameraManager();
}
2025-12-29 19:18:24 +08:00
return _instance;
}
}
private UIWindowCameraManager()
{
}
2025-12-29 19:18:24 +08:00
#endregion
#region Camera Operations
2025-12-29 19:18:24 +08:00
/// <summary>
/// 处理窗口打开时的相机状态
/// 如果窗口需要关闭相机,则关闭主相机
/// </summary>
/// <param name="newWindow">新打开的窗口</param>
public void HandleCameraOnOpen(UIWindow newWindow)
{
if (newWindow == null)
return;
2026-01-12 13:33:27 +08:00
bool showCamera = CheckTopWindowNeedShow();
CameraManager.Instance.SetMainCameraActive(showCamera);
2025-12-29 19:18:24 +08:00
}
/// <summary>
/// 处理窗口关闭时的相机恢复
/// 检查下层是否还有需要关闭相机的窗口
/// - 如果下层还有 ShutMainCamera 的窗口,则不打开相机
/// - 如果下层没有 ShutMainCamera 的窗口,则需要打开相机
/// </summary>
/// <param name="closingWindow">正在关闭的窗口</param>
public void HandleCameraOnClose(UIWindow closingWindow)
{
if (closingWindow == null)
return;
// 检查是否还有其他需要关闭相机的窗口在显示
bool showCamera = CheckTopWindowNeedShow(closingWindow);
CameraManager.Instance.SetMainCameraActive(showCamera);
2025-12-29 19:18:24 +08:00
}
#endregion
#region Helper Methods
2025-12-29 19:18:24 +08:00
/// <summary>
/// 检查窗口栈顶层界面是否需要开关相机
2025-12-29 19:18:24 +08:00
/// </summary>
/// <param name="excludeWindow">要排除的窗口(正在关闭的窗口)</param>
/// <returns>是否存在其他需要关闭相机的窗口</returns>
2026-01-12 13:33:27 +08:00
private bool CheckTopWindowNeedShow(UIWindow excludeWindow = null)
2025-12-29 19:18:24 +08:00
{
var layerManager = UICanvasLayerManager.Instance;
2025-12-29 19:18:24 +08:00
// 从最高层开始遍历所有层级
for (int layer = (int)UICanvasLayer.Max - 1; layer >= 0; layer--)
{
var windowList = layerManager.GetWindowsInLayer((UICanvasLayer)layer);
2025-12-29 19:18:24 +08:00
foreach (var window in windowList)
{
// 跳过正在关闭的窗口
if (window == null || window == excludeWindow)
continue;
2025-12-29 19:18:24 +08:00
// 只检查逻辑上显示的窗口IsShow=true
if (!window.IsShow())
continue;
2025-12-29 19:18:24 +08:00
// 检查该窗口是否需要关闭相机
var windowConfig = UIManager.Instance.GetWindowInfo(window.WindowName);
// 跳过不管相机的界面
if (windowConfig.CameraMode == UIManagerBase.CameraMode.None)
continue;
return windowConfig.CameraMode == UIManagerBase.CameraMode.Show;
2025-12-29 19:18:24 +08:00
}
}
2025-12-29 19:18:24 +08:00
return false;
}
#endregion
}