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

878 lines
26 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2023-11-21 13:31:06 +08:00
using System.Linq;
2023-08-22 19:08:45 +08:00
using Cysharp.Threading.Tasks;
using Framework;
2023-10-19 15:00:19 +08:00
using PhxhSDK;
2025-06-17 13:54:47 +08:00
using PhxhSDK.AOT.Aspect;
2023-08-22 19:08:45 +08:00
using UnityEngine;
2024-01-26 16:06:42 +08:00
public partial class UIManager : Singlenton<UIManager>, IInitable, IUpdatable
2023-08-22 19:08:45 +08:00
{
public const string UI_PREFAB_PATH = "Assets/Art_Out/UI/Prefab/{0}.prefab";
2023-08-22 19:08:45 +08:00
public Dictionary<string, UIWindow> mMemoryWindows = new Dictionary<string, UIWindow>();
private Dictionary<int, LinkedList<UIWindow>> _layerList = new Dictionary<int, LinkedList<UIWindow>>(16);
private ScreenOrientation _currentOrientation;
private Dictionary<string, string> _openingWindows = new Dictionary<string, string>();
2023-12-29 15:09:18 +08:00
private List<UIWindow> _hideCache = new List<UIWindow>();
2024-01-24 15:42:01 +08:00
private UIWindow _curFullScreen;
2023-12-29 15:09:18 +08:00
private Dictionary<GameObject, UIWindow> _uiWindowObjDic = new Dictionary<GameObject, UIWindow>();
public Dictionary<GameObject, UIWindow> UIWindowObjDic => _uiWindowObjDic;
public Vector2 Size;
2025-06-25 17:37:22 +08:00
/// <summary>
/// UI和主相机屏幕缩放
/// </summary>
2025-06-25 17:52:18 +08:00
public Vector2 UIAndMainScreenScale;
2025-06-25 17:37:22 +08:00
/// <summary>
/// UI和UI屏幕缩放
/// </summary>
2025-06-25 17:52:18 +08:00
public Vector2 UIAndUIScreenScale;
2024-07-05 20:28:35 +08:00
/// <summary>
/// 是否响应返回键
/// </summary>
public bool IsEnableBack { get; set; }
2023-08-22 19:08:45 +08:00
public void Init()
{
2024-07-05 20:28:35 +08:00
IsEnableBack = true;
2023-08-22 19:08:45 +08:00
_AllWindowMeta();
if (DeviceHelper.IsFullScreenIOS())
{
SetFullScreenIOS();
}
2023-12-08 18:41:26 +08:00
EventManager.Instance.Register(EventManager.EventName.Android_Click_Back, _OnAndroidClickBack);
EventManager.Instance.Register(EventManager.EventName.HideAllUIExcept, (Action<string[]>)_OnHideAllUIExcept);
EventManager.Instance.Register(EventManager.EventName.ShowAllUIHiden, _OnShowAllUIHiden);
2024-01-24 16:48:01 +08:00
EventManager.Instance.Register(EventManager.EventName.ClearUIStack, (Action<string[]>)ClearHideStack);
2025-06-17 13:54:47 +08:00
OnScreenSizeChange();
AspectManager.Instance.ScreenSizeChange += OnScreenSizeChange;
2023-08-22 19:08:45 +08:00
}
public void Release()
{
2025-06-17 13:54:47 +08:00
AspectManager.Instance.ScreenSizeChange -= OnScreenSizeChange;
2023-12-08 18:41:26 +08:00
EventManager.Instance.Unregister(EventManager.EventName.Android_Click_Back, _OnAndroidClickBack);
EventManager.Instance.Unregister(EventManager.EventName.HideAllUIExcept, (Action<string[]>)_OnHideAllUIExcept);
EventManager.Instance.Unregister(EventManager.EventName.ShowAllUIHiden, _OnShowAllUIHiden);
2024-01-24 16:48:01 +08:00
EventManager.Instance.Unregister(EventManager.EventName.ClearUIStack, (Action<string[]>)ClearHideStack);
2023-08-22 19:08:45 +08:00
}
2024-01-26 16:06:42 +08:00
public void Update(float dt)
{
foreach (var winKv in mMemoryWindows)
{
var window = winKv.Value;
2025-04-16 12:24:10 +08:00
if (window != null && !window.IsClosing)
2024-01-26 16:06:42 +08:00
{
2025-04-16 12:24:10 +08:00
if (window.IsCreated() && window.gameObject)
{
window.Update();
window.Update(dt);
}
2024-01-26 16:06:42 +08:00
}
}
_OnClickUpdate(dt);
2024-01-26 16:06:42 +08:00
}
#region UIWindow Manager
public static void BindWindowObj(UIWindow window, GameObject uiObj)
{
window.gameObject = uiObj.gameObject;
window.transform = uiObj.transform;
window.rectTransform = uiObj.GetComponent<RectTransform>();
window.name = uiObj.name;
}
#endregion
2024-01-24 15:42:01 +08:00
#region OpenWindowAPI
2023-08-22 19:08:45 +08:00
/// <summary>
/// 打开一个UI
/// UIManager.Instance.OpenWindow("Common/GameUI")
/// </summary>
2023-11-15 12:55:00 +08:00
2023-08-22 19:08:45 +08:00
//重载一下传参的Open
public async UniTask<UIWindow> CreateAndOpenWindow(string path, object data = null, ECanvasRoot eCanvasRoot = ECanvasRoot.Static1)
2023-08-22 19:08:45 +08:00
{
DebugUtil.LogP($"打开窗口:{path}");
if (mMemoryWindows.ContainsKey(path))
{
DebugUtil.LogG($"窗口已打开!!!{path}");
2024-10-18 15:06:46 +08:00
//return null;
}
var root = UIRoot.Instance.RootDic[eCanvasRoot];
var window = await _LoadWindow(path, true, eCanvasRoot);
2024-01-26 16:06:42 +08:00
if (window != null)
2023-10-19 15:00:19 +08:00
{
2024-01-24 15:42:01 +08:00
if (window.uiWindowLayer == UIWindowLayer.Normal)
{
if (CheckWindowIsFullScreen(window))
{
int idx = _uiWindowStack.Count - 1;
while (idx >= 0)
{
var latestWindow = _uiWindowStack[idx--];
latestWindow.CloseWindow(UIWindowCloseType.HideAndPush);
if (CheckWindowIsFullScreen(latestWindow))
{
break;
}
}
}
}
for (int i = root.transform.childCount - 1; i >=0; i--)
{
var winGo = root.transform.GetChild(i).gameObject;
if (_uiWindowObjDic.TryGetValue(winGo, out var win))
{
if (win != null)
{
if (win.uiWindowLayer > window.uiWindowLayer)
{
window.transform.SetSiblingIndex(i);
}
}
}
}
window.CreateWindow(data, GetIsNotSetCameraByPath(path));
2024-01-24 15:42:01 +08:00
if (window.uiWindowLayer == UIWindowLayer.Normal)
{
PushWindow(window);
}
2023-10-19 15:00:19 +08:00
}
2023-08-22 19:08:45 +08:00
return window;
}
2024-01-24 15:42:01 +08:00
//先打开后关闭
// public async UniTask<UIWindow> CreateAndOpenWindow(string path, object data = null)
// {
// if (mMemoryWindows.ContainsKey(path))
// {
// DebugUtil.LogError($"窗口已打开!!!{path}");
// //return null;
// }
//
// var window = await _LoadWindow(path, true);
// if (window != null)
// {
// var root = UIRoot.Instance.Root;
// for (int i = root.transform.childCount - 1; i >=0; i--)
// {
// var winGo = root.transform.GetChild(i).gameObject;
// if (_uiWindowObjDic.TryGetValue(winGo, out var win))
// {
// if (win != null)
// {
// if (win.uiWindowLayer > window.uiWindowLayer)
// {
// window.transform.SetSiblingIndex(i);
// }
// }
// }
// }
// window.CreateWindow(data, GetIsNotSetCameraByPath(path));
//
// if (window.uiWindowLayer == UIWindowLayer.Normal)
// {
// if (CheckWindowIsFullScreen(window))
// {
// int idx = _uiWindowStack.Count - 1;
// while (idx >= 0)
// {
// var latestWindow = _uiWindowStack[idx--];
// var bNotSet = latestWindow.IsNotSetMainCamera;
// latestWindow.IsNotSetMainCamera = true;
// latestWindow.CloseWindow(UIWindowCloseType.HideAndPush);
// latestWindow.IsNotSetMainCamera = bNotSet;
// if (CheckWindowIsFullScreen(latestWindow))
// {
// break;
// }
// }
// }
//
// }
//
// if (window.uiWindowLayer == UIWindowLayer.Normal)
// {
// PushWindow(window);
// }
//
// }
//
// return window;
// }
2023-08-22 19:08:45 +08:00
public bool Back()
{
return false;
}
2023-11-21 13:31:06 +08:00
public bool RemoveWindow(string wName)
2023-08-22 19:08:45 +08:00
{
string windowName = wName;
bool result = false;
UIWindow window;
if (mMemoryWindows.TryGetValue(windowName, out window))
{
2023-11-21 13:31:06 +08:00
LayerListRemoveWindow(window);
mMemoryWindows.Remove(windowName);
2023-08-22 19:08:45 +08:00
result = true;
}
return result;
}
2024-08-12 19:31:50 +08:00
public void CloseWindow(string wName, UIWindowCloseType closeType = UIWindowCloseType.HideAndDestroy, int playAnim = 0)
2023-11-21 13:31:06 +08:00
{
var window = GetOpenedWindowByPath<UIWindow>(wName);
2024-01-26 16:06:42 +08:00
if (window != null)
2023-11-21 13:31:06 +08:00
{
2024-08-12 19:31:50 +08:00
window.CloseWindow(closeType, playAnim);
2023-11-21 13:31:06 +08:00
}
}
2023-08-22 19:08:45 +08:00
public T GetOpenedWindowByPath<T>(string uipath) where T : UIWindow
{
2024-07-05 16:04:26 +08:00
var window = GetOpenedWindowByPath(uipath) as T;
//return window.gameObject.activeSelf ? window : null;
return window;
}
public UIWindow GetOpenedWindowByPath(string uipath)
{
if (string.IsNullOrEmpty(uipath))
{
DebugUtil.LogError("UIManager.GetOpenedWindowByPath, uipath is null or empty");
return null;
}
2023-08-22 19:08:45 +08:00
if (mMemoryWindows.ContainsKey(uipath))
{
//return window.gameObject.activeSelf ? window : null;
2024-07-05 16:04:26 +08:00
return mMemoryWindows[uipath];
2023-08-22 19:08:45 +08:00
}
2024-07-05 16:04:26 +08:00
return null;
2023-08-22 19:08:45 +08:00
}
2024-07-05 16:04:26 +08:00
2023-08-22 19:08:45 +08:00
void LayerListInsertWindow(UIWindow window)
{
try
{
if (window != null)
{
LinkedList<UIWindow> currentLayerWindows;
if (_layerList.TryGetValue((int) window.uiWindowLayer, out currentLayerWindows)
&& currentLayerWindows != null
&& currentLayerWindows.Count > 0)
{
if (currentLayerWindows.Remove(window))
{
}
currentLayerWindows.AddLast(window);
2023-10-19 15:00:19 +08:00
//DebugUtil.Log($"{window.WindowName} sibling index is {window.transform.GetSiblingIndex()}");
2023-08-22 19:08:45 +08:00
//return;
}
else
{
if (currentLayerWindows == null)
{
currentLayerWindows = new LinkedList<UIWindow>();
_layerList.Add((int) window.uiWindowLayer, currentLayerWindows);
}
currentLayerWindows.AddLast(window);
}
int siblingIndex = 5; // 让出loading其他想挂在canvas下的奇怪东西
LinkedList<UIWindow> layerWindows;
for (int i = 0; i <= (int) UIWindowLayer.Max; i++)
{
if (_layerList.TryGetValue(i, out layerWindows) && layerWindows != null)
{
if (layerWindows.Count > 0)
{
var e = layerWindows.GetEnumerator();
while (e.MoveNext())
{
2023-10-26 20:20:11 +08:00
var currWindow = e.Current;
if (currWindow != null)
currWindow.transform?.SetSiblingIndex(siblingIndex++);
2023-08-22 19:08:45 +08:00
}
}
}
}
var index = window.transform.GetSiblingIndex();
2023-10-19 15:00:19 +08:00
//DebugUtil.Log($"{window.WindowName} sibling index is {index}");
2023-08-22 19:08:45 +08:00
}
}
catch (Exception e)
{
DebugUtil.LogError(e);
2023-10-19 15:00:19 +08:00
DebugUtil.LogError("{0}.LayerListInsertWindow error, window name = {1}", GetType(), window.name);
2023-08-22 19:08:45 +08:00
}
}
void LayerListRemoveWindow(UIWindow window)
{
try
{
if (window != null)
{
LinkedList<UIWindow> currentLayerWindows;
if (_layerList.TryGetValue((int)window.uiWindowLayer, out currentLayerWindows))
{
currentLayerWindows?.Remove(window);
}
}
}
catch (Exception e)
{
DebugUtil.LogError(e);
}
}
public bool GetTopWindow(out UIWindow window, out UIWindowLayer layer, int banLayerMask)
{
for (int i = (int)UIWindowLayer.Max; i >= 0; i--)
{
if (((1 << i) & banLayerMask) == 0)
{
LinkedList<UIWindow> highLayerWindows;
if (_layerList.TryGetValue(i, out highLayerWindows))
{
if (highLayerWindows.Count > 0)
{
window = highLayerWindows.Last.Value;
if (window != null)
{
layer = (UIWindowLayer)i;
return true;
}
}
}
}
}
window = null;
layer = UIWindowLayer.Max;
return false;
}
public int LayerMask(UIWindowLayer layer)
{
return 1 << ((int)layer);
}
async void SetFullScreenIOS()
{
await UniTask.Delay(670);
// while (true)
// {
// var screenOrientation = DragonNativeBridge.GetScreenOrientation();
// if (screenOrientation != _currentOrientation)
// {
// _currentOrientation = screenOrientation;
// EventDispatcher.Instance.DispatchEvent(new ScreenOrientationChangedEvent(_currentOrientation));
// }
// yield return wait;
// }
}
public async UniTask<UIWindow> LoadWindow(string path, ECanvasRoot eCanvasRoot = ECanvasRoot.Static1)
2023-08-22 19:08:45 +08:00
{
return await _LoadWindow(path, false, eCanvasRoot);
2023-11-16 15:32:40 +08:00
}
private async UniTask<UIWindow> _LoadWindow(string path, bool isActive = false, ECanvasRoot eCanvasRoot = ECanvasRoot.Static1)
2023-11-16 15:32:40 +08:00
{
2023-08-22 19:08:45 +08:00
string uipath = path;
UIWindow window = null;
2023-11-16 15:32:40 +08:00
2023-08-22 19:08:45 +08:00
WindowInfo wInfo;
if (!_windowsInfo.ContainsKey(uipath))
{
//if (_windowsInfo.TryGetValue(uipath, out wInfo))
{
2023-10-19 15:00:19 +08:00
DebugUtil.LogError("Create ui fail: {0}, no windows info inited", uipath);
2023-11-16 15:32:40 +08:00
return window;
2023-08-22 19:08:45 +08:00
}
}
wInfo = _windowsInfo[uipath];
var uiWindowLayer = wInfo.windowLayer;
if (!mMemoryWindows.TryGetValue(uipath, out window))
{
2023-11-16 15:32:40 +08:00
if (_openingWindows.ContainsKey(uipath))
{
return window;
}
_openingWindows.Add(uipath, uipath);
window = await UIRoot.Instance.CreateWindow(uipath, eCanvasRoot);
2023-11-16 15:32:40 +08:00
_openingWindows.Remove(uipath);
2023-08-22 19:08:45 +08:00
if (window != null)
{
mMemoryWindows[uipath] = window;
window.WindowName = uipath;
window.uiWindowLayer = uiWindowLayer;
}
else
{
2023-10-19 15:00:19 +08:00
DebugUtil.LogError("Create ui fail: {0}", uipath);
2023-11-16 15:32:40 +08:00
return window;
2023-08-22 19:08:45 +08:00
}
}
LayerListInsertWindow(window);
2024-01-26 16:06:42 +08:00
if (window == null)
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
DebugUtil.LogError("Create ui fail: {0}", uipath);
2023-11-16 15:32:40 +08:00
return null;
2023-08-22 19:08:45 +08:00
}
if (!isActive)
{
2023-11-16 15:32:40 +08:00
window.gameObject.SetActive(false);
2023-08-22 19:08:45 +08:00
}
2023-11-16 15:32:40 +08:00
_uiWindowObjDic.TryAdd(window.gameObject, window);
2023-11-16 15:32:40 +08:00
return window;
2023-08-22 19:08:45 +08:00
}
2023-11-16 15:32:40 +08:00
2023-08-22 19:08:45 +08:00
//展示全部已加载的NormalUI
public void OpenLoadedNormalUI(string uiName, object data = null)
2023-08-22 19:08:45 +08:00
{
WindowInfo wInfo;
wInfo = _windowsInfo[uiName];
if (mMemoryWindows.ContainsKey(uiName))
2023-08-22 19:08:45 +08:00
{
mMemoryWindows[uiName].CreateWindow(data, wInfo.NotSetMainCamera);
2023-08-22 19:08:45 +08:00
}
}
public void ForeachUI(Action<UIWindow> action)
{
var windowList = mMemoryWindows.ToList();
foreach (var kv in windowList)
{
var window = kv.Value;
if (window != null)
{
action?.Invoke(kv.Value);
}
}
}
2023-11-21 13:31:06 +08:00
public void CloseAllUI(UIWindowCloseType closeType )
2023-08-22 19:08:45 +08:00
{
2023-11-21 13:31:06 +08:00
var windowList = mMemoryWindows.ToList();
foreach (var kv in windowList)
2023-08-22 19:08:45 +08:00
{
var window = kv.Value;
2023-11-21 13:31:06 +08:00
window.CloseWindow(closeType);
2023-08-22 19:08:45 +08:00
}
2023-11-21 13:31:06 +08:00
if (closeType == UIWindowCloseType.HideAndDestroy)
2023-08-22 19:08:45 +08:00
{
mMemoryWindows.Clear();
_layerList.Clear();
2023-11-21 15:12:51 +08:00
ClearHideStack();
2023-08-22 19:08:45 +08:00
}
}
2025-02-25 16:37:51 +08:00
public void CloseAllUIExcept(string path)
{
var windowList = mMemoryWindows.ToList();
foreach (var kv in windowList)
{
var window = kv.Value;
if(window.WindowName != path)
{
window.CloseWindow(UIWindowCloseType.ForceDestroy);
2025-02-25 16:37:51 +08:00
mMemoryWindows.Remove(window.WindowName);
var layer=window.uiWindowLayer;
_layerList[(int)layer].Remove(window);
if(_layerList[(int)layer].Count==0)
{
_layerList.Remove((int)layer);
}
}
}
ClearHideStack();
}
2024-01-24 15:42:01 +08:00
#endregion
2023-08-22 19:08:45 +08:00
2024-05-09 14:37:29 +08:00
#region ShowAndHide
2024-05-17 18:28:31 +08:00
/// <summary>
/// 和ShowAllUI成都调用
/// </summary>
/// <param name="exceptions"></param>
2024-01-03 17:25:13 +08:00
public void HideAllUI(params string[] exceptions)
2023-12-29 15:03:59 +08:00
{
var windowList = mMemoryWindows.ToList();
foreach (var kv in windowList)
{
var window = kv.Value;
2024-05-16 14:56:45 +08:00
if (window.uiWindowLayer > UIWindowLayer.Normal)
{
continue;
}
2024-01-03 17:25:13 +08:00
if (window.gameObject.activeInHierarchy && !exceptions.Contains(window.WindowName))
2023-12-29 15:09:18 +08:00
{
_hideCache.Add(window);
window.HideWindow(true);
}
2023-12-29 15:03:59 +08:00
}
}
2024-05-17 18:28:31 +08:00
/// <summary>
/// 和HideAllUI成对调用
/// </summary>
2023-12-29 15:03:59 +08:00
public void ShowAllUI()
{
2023-12-29 15:09:18 +08:00
foreach (var v in _hideCache)
2023-12-29 15:03:59 +08:00
{
2023-12-29 15:09:18 +08:00
var window = v;
2024-01-03 17:25:13 +08:00
if (window != null)
window.ShowWindow();
2023-12-29 15:03:59 +08:00
}
2023-12-29 15:09:18 +08:00
_hideCache.Clear();
2023-12-29 15:03:59 +08:00
}
2024-06-03 19:38:34 +08:00
/// <summary>
/// 展示界面
/// </summary>
/// <param name="path"></param>
/// <param name="isMainCameraClose"></param> 展示界面时是否关闭场景主相机
public void Show(string path, bool isMainCameraClose = false)
2024-01-15 15:33:10 +08:00
{
if (mMemoryWindows.TryGetValue(path, out var window))
{
if (!window.gameObject.activeInHierarchy)
{
window.ShowWindow();
2024-06-03 19:38:34 +08:00
if (isMainCameraClose)
{
var curCameraActive = CameraManager.Instance.CheckMainCameraIsActive();
if (curCameraActive)
{
CameraManager.Instance.SetMainCameraActive(false);
}
}
2024-01-15 15:33:10 +08:00
}
}
}
2024-06-03 19:38:34 +08:00
/// <summary>
/// 隐藏
/// </summary>
/// <param name="path"></param>
/// <param name="isOnlyHide"></param>
/// <param name="isMainCameraActive"></param> 隐藏界面时是否打开场景主相机
public void Hide(string path, bool isOnlyHide = false, bool isMainCameraActive = false)
2024-01-15 15:33:10 +08:00
{
if (mMemoryWindows.TryGetValue(path, out var window))
{
if (window.gameObject.activeInHierarchy)
{
window.HideWindow(isOnlyHide);
2024-06-03 19:38:34 +08:00
if (isMainCameraActive)
{
var curCameraActive = CameraManager.Instance.CheckMainCameraIsActive();
if (!curCameraActive)
{
CameraManager.Instance.SetMainCameraActive(true);
}
}
2024-01-15 15:33:10 +08:00
}
}
}
2023-08-22 19:08:45 +08:00
public async void ShowUITips(string uiName, string content, int showTime = 1500)
{
//放到最上层
if (!_windowsInfo.ContainsKey(uiName))
{
return;
}
2023-11-21 13:31:06 +08:00
2024-05-16 12:40:15 +08:00
var window = await CreateAndOpenWindow(uiName, content);
2023-08-22 19:08:45 +08:00
await UniTask.Delay(showTime);
2024-01-15 15:33:10 +08:00
window.CloseWindow();
2023-08-22 19:08:45 +08:00
}
public async void ShowClickShield(string uiPath, int time = 0)
{
//放到最上层
if (!_windowsInfo.ContainsKey(uiPath))
{
return;
}
2023-11-21 13:31:06 +08:00
2024-05-16 12:40:15 +08:00
CreateAndOpenWindow(uiPath);
mMemoryWindows.TryGetValue(uiPath, out var window);
2023-08-22 19:08:45 +08:00
if (time > 0)
{
await UniTask.Delay(time);
2023-11-21 13:31:06 +08:00
window.CloseWindow(UIWindowCloseType.HideAndDestroy);
2023-08-22 19:08:45 +08:00
}
}
public void CloseClickShield(string uiPath)
{
if (mMemoryWindows.ContainsKey(uiPath))
{
2023-11-21 13:31:06 +08:00
var window = mMemoryWindows[uiPath];
window.CloseWindow(UIWindowCloseType.HideAndDestroy);
2023-08-22 19:08:45 +08:00
}
}
2024-05-09 14:37:29 +08:00
private void _OnHideAllUIExcept(params string[] exceptions)
{
HideAllUI(exceptions);
}
private void _OnShowAllUIHiden()
{
ShowAllUI();
}
#endregion
2023-08-22 19:08:45 +08:00
2023-11-21 13:24:42 +08:00
//根据路径判断UI界面是否打开
2023-08-22 19:08:45 +08:00
public bool IsWindowOpening(string uiPath)
{
string windowName;
if (_openingWindows.TryGetValue(uiPath, out windowName))
{
if (windowName != null)
{
return true;
}
}
return false;
}
2024-03-08 12:59:24 +08:00
/// <summary>
/// 关掉所有Normal层已打开的界面保留传参的界面
/// </summary>
/// <param name="path"></param>
2024-08-12 19:31:50 +08:00
public void CloseAllNormalExcept(string path, bool isShowAnim = true)
2023-11-21 13:24:42 +08:00
{
var windowsL = _GetLayerWindowList(UIWindowLayer.Normal);
if (!mMemoryWindows.ContainsKey(path))
{
DebugUtil.LogError("请检查Home返回方法传入UI窗口路径参数{0}", path);
return;
}
List<UIWindow> toBeRemoved = new List<UIWindow>();
2025-05-12 16:10:30 +08:00
// UIWindow lastWindow = null;
// if (isShowAnim)
// {
// lastWindow = PopWindow();
// }
2024-08-12 19:31:50 +08:00
2023-11-21 13:24:42 +08:00
if (windowsL.Count > 0)
{
var node = windowsL.First;
while (node != null)
{
var window = node.Value;
2023-11-21 16:22:19 +08:00
if (window.WindowName != path)
{
toBeRemoved.Add(window);
}
2023-11-21 13:24:42 +08:00
if (node == windowsL.Last)
{
break;
}
node = node.Next;
}
}
string[] strL = { path };
ClearHideStack(strL);
2025-05-12 16:10:30 +08:00
// if (isShowAnim && lastWindow != null && lastWindow.WindowName != path)
// {
// lastWindow.CloseWindow();
// }
2024-08-12 19:31:50 +08:00
if (toBeRemoved.Count > 0)
{
for (int i = toBeRemoved.Count - 2; i >= 0; i--)
{
CloseWindow(toBeRemoved[i].WindowName, UIWindowCloseType.ForceDestroy, -1);
}
}
if (CheckIsWindowInStack(mMemoryWindows[path]))
{
mMemoryWindows[path].CreateWindow(null, GetIsNotSetCameraByPath(path));
2023-11-21 13:24:42 +08:00
}
}
2025-03-21 12:55:24 +08:00
public void CloseAllNormalExcept(params string[] paths)
{
bool isShowAnim = true;
var windowsL = _GetLayerWindowList(UIWindowLayer.Normal);
foreach (var path in paths)
{
if (!mMemoryWindows.ContainsKey(path))
{
DebugUtil.LogError("请检查Home返回方法传入UI窗口路径参数{0}", path);
return;
}
}
List<UIWindow> toBeRemoved = new List<UIWindow>();
2025-05-12 16:10:30 +08:00
// UIWindow lastWindow = null;
// if (isShowAnim)
// {
// lastWindow = PopWindow();
// }
2025-03-21 12:55:24 +08:00
if (windowsL.Count > 0)
{
var node = windowsL.First;
while (node != null)
{
var window = node.Value;
if (!paths.Contains(window.WindowName))
{
toBeRemoved.Add(window);
}
if (node == windowsL.Last)
{
break;
}
node = node.Next;
}
}
//string[] strL = { path };
ClearHideStack(paths);
2025-05-12 16:10:30 +08:00
// if (isShowAnim && lastWindow != null && !paths.Contains(lastWindow.WindowName))
// {
// lastWindow.CloseWindow();
// }
2025-03-21 12:55:24 +08:00
if (toBeRemoved.Count > 0)
{
for (int i = toBeRemoved.Count - 2; i >= 0; i--)
{
CloseWindow(toBeRemoved[i].WindowName, UIWindowCloseType.ForceDestroy, -1);
}
}
foreach (var path in paths)
{
if (CheckIsWindowInStack(mMemoryWindows[path]))
{
mMemoryWindows[path].CreateWindow(null, GetIsNotSetCameraByPath(path));
}
}
}
2023-11-21 13:24:42 +08:00
2024-01-24 15:42:01 +08:00
public bool CheckWindowIsFullScreen(UIWindow window)
{
if (_windowsInfo.TryGetValue(window.WindowName, out var windowInfo))
{
if (windowInfo.UIOpenType == UIOpenType.FullScreen)
{
return true;
}
}
return false;
}
2023-12-08 18:41:26 +08:00
private async void _OnAndroidClickBack()
2023-11-21 13:24:42 +08:00
{
2024-07-05 20:28:35 +08:00
if (!IsEnableBack)
return;
2024-03-27 17:07:43 +08:00
if (_uiWindowStack.Count > 0)
2023-12-08 18:41:26 +08:00
{
2024-03-27 17:07:43 +08:00
var window = _uiWindowStack.Last();
if (await window.OnBack())
2024-02-23 14:42:45 +08:00
{
return;
}
2023-11-21 13:24:42 +08:00
}
if (!CheckWindowCreated(UINameConst.UIBackReturn))
{
await CreateAndOpenWindow(UINameConst.UIBackReturn);
}
2023-11-21 13:24:42 +08:00
}
public bool CheckWindowLoaded(string uiPath)
{
if (mMemoryWindows.TryGetValue(uiPath, out var window))
{
return true;
}
return false;
}
2024-05-16 12:40:15 +08:00
public bool CheckWindowCreated(string uiPath)
{
if (mMemoryWindows.TryGetValue(uiPath, out var window))
{
return window.IsCreated();
}
return false;
}
2025-06-17 13:54:47 +08:00
private async void OnScreenSizeChange()
{
await UniTask.NextFrame(); // 必须等待一帧等RectTransform大小刷新后获取
RectTransform rectTrans = UIRoot.Instance.Root.GetComponent<RectTransform>();
Size = new(rectTrans.sizeDelta.x, rectTrans.sizeDelta.y);
2025-06-25 17:37:22 +08:00
UIAndMainScreenScale = new Vector3(Size.x / Screen.width, Size.y / Screen.height);
2025-06-25 17:52:18 +08:00
UIAndUIScreenScale = new Vector3(Size.x / AspectManager.Instance.ScreenSize.x, Size.y / AspectManager.Instance.ScreenSize.y);
2025-06-17 13:54:47 +08:00
}
2023-08-22 19:08:45 +08:00
}