193 lines
5.3 KiB
C#
193 lines
5.3 KiB
C#
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
public partial class UIManager
|
|
{
|
|
private List<UIWindow> _uiWindowStack = new List<UIWindow>(8);
|
|
public List<UIWindow> UiWindowStack => _uiWindowStack;
|
|
|
|
#region StackAPI
|
|
|
|
public bool CheckIsWindowInStack(UIWindow window)
|
|
{
|
|
if (_uiWindowStack.Contains(window))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public UIWindow GetLast()
|
|
{
|
|
if (_uiWindowStack.Count > 0)
|
|
{
|
|
return _uiWindowStack.Last();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public UIWindow GetLastFullScreen()
|
|
{
|
|
if (_uiWindowStack.Count > 0)
|
|
{
|
|
for (int i = _uiWindowStack.Count - 1; i >= 0; i--)
|
|
{
|
|
if (CheckWindowIsFullScreen(_uiWindowStack[i]))
|
|
{
|
|
return _uiWindowStack[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void PushWindow(UIWindow window)
|
|
{
|
|
if (window)
|
|
{
|
|
if (_uiWindowStack.Contains(window))
|
|
{
|
|
DebugUtil.LogError($"{window.WindowName} exists in UIWindowStack!!!");
|
|
return;
|
|
}
|
|
_uiWindowStack.Add(window);
|
|
}
|
|
}
|
|
|
|
public UIWindow PopWindow()
|
|
{
|
|
if (_uiWindowStack.Count > 0)
|
|
{
|
|
var window = _uiWindowStack.Last();
|
|
_uiWindowStack.Remove(window);
|
|
return window;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public UIWindow PopWindow(string checkWindowName)
|
|
{
|
|
if (_uiWindowStack.Count > 0)
|
|
{
|
|
var window = _uiWindowStack.Last();
|
|
if (string.IsNullOrEmpty(checkWindowName) || checkWindowName.Equals(window.WindowName))
|
|
{
|
|
_uiWindowStack.Remove(window);
|
|
return window;;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void ForceRemoveWindow(UIWindow window)
|
|
{
|
|
if (_uiWindowStack.Contains(window))
|
|
{
|
|
_uiWindowStack.Remove(window);
|
|
}
|
|
}
|
|
|
|
public void ClearHideStack(params string[] windowName)
|
|
{
|
|
for(int i = _uiWindowStack.Count - 1; i >=0 ; i--)
|
|
{
|
|
if (!windowName.Contains(_uiWindowStack[i].WindowName))
|
|
{
|
|
_uiWindowStack[i].CloseWindow(UIWindowCloseType.ForceDestroy);
|
|
_uiWindowStack.RemoveAt(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ClearHideStack()
|
|
{
|
|
for(int i = 0; i < _uiWindowStack.Count; i++)
|
|
{
|
|
_uiWindowStack[i].CloseWindow(UIWindowCloseType.ForceDestroy);
|
|
}
|
|
_uiWindowStack.Clear();
|
|
}
|
|
#endregion
|
|
|
|
public static async UniTask<UIWindow> AnimSwitchWindow(UIWindow hideWindow, UIWindowCloseType closeType, string showWindowName, object data = null)
|
|
{
|
|
if (hideWindow != null)
|
|
{
|
|
await hideWindow.AnimHide();
|
|
}
|
|
|
|
var showWindow = await UIManager.Instance.OpenWindow(showWindowName, data);
|
|
|
|
|
|
if (showWindow != null)
|
|
{
|
|
await showWindow.AnimShow();
|
|
}
|
|
|
|
|
|
if (hideWindow != null)
|
|
{
|
|
hideWindow.CloseWindow(closeType);
|
|
}
|
|
|
|
return showWindow;
|
|
}
|
|
|
|
public static async UniTask<UIWindow> AnimSwitchWindow(UIWindow hideWindow, UIWindowCloseType closeType, UIWindow showWindow, object data = null)
|
|
{
|
|
if (hideWindow != null)
|
|
{
|
|
await hideWindow.AnimHide();
|
|
}
|
|
|
|
if (showWindow != null)
|
|
{
|
|
if (showWindow.IsOpen())
|
|
{
|
|
showWindow.OpenWindow(data);
|
|
}
|
|
else
|
|
{
|
|
showWindow.ShowWindow();
|
|
}
|
|
await showWindow.AnimShow();
|
|
}
|
|
|
|
if (hideWindow != null)
|
|
{
|
|
hideWindow.CloseWindow(closeType);
|
|
}
|
|
|
|
return showWindow;
|
|
}
|
|
|
|
//常规的关闭一个最后打开的界面
|
|
public static async UniTask NormalCloseWindow(UIWindow hideWindow, String showWindowStr, Object data = null)
|
|
{
|
|
var window = Instance.PopWindow();
|
|
if (!window)
|
|
{
|
|
hideWindow.OnBack();
|
|
return;
|
|
}
|
|
await AnimSwitchWindow(hideWindow, UIWindowCloseType.HideAndDestroy, showWindowStr, data);
|
|
}
|
|
|
|
public static async UniTask NormalCloseWindow(UIWindow hideWindow, Object data = null)
|
|
{
|
|
var showWindow = Instance.PopWindow();
|
|
if (!showWindow)
|
|
{
|
|
hideWindow.OnBack();
|
|
return;
|
|
}
|
|
await AnimSwitchWindow(hideWindow, UIWindowCloseType.HideAndDestroy, showWindow, data);
|
|
}
|
|
}
|