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