From 9b9f329a71e7783fed555bd9911418e4653bbace Mon Sep 17 00:00:00 2001
From: client_Wu Xijin <364452445@qq.com>
Date: 星期六, 02 二月 2019 11:26:46 +0800
Subject: [PATCH] 3335 重构窗口管理
---
System/WindowBase/Windows.cs | 435 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 428 insertions(+), 7 deletions(-)
diff --git a/System/WindowBase/Windows.cs b/System/WindowBase/Windows.cs
index a7ccbdd..9ea7f04 100644
--- a/System/WindowBase/Windows.cs
+++ b/System/WindowBase/Windows.cs
@@ -5,11 +5,46 @@
namespace Snxxz.UI
{
- public class WindowController : SingletonMonobehaviour<WindowController>
+ public class WindowCenter : SingletonMonobehaviour<WindowCenter>
{
+ public event Action<Window> windowBeforeOpenEvent;
+ public event Action<Window> windowAfterOpenEvent;
+ public event Action<Window> windowBeforeCloseEvent;
+ public event Action<Window> windowAfterCloseEvent;
+ public event Action<Window> jumpWindowCloseEvent;
+
+ List<string> closeAllIgnoreWindows = new List<string>() {
+ "MessageWin", "NewBieWin", "NewItemGetWin", "AttributePromoteShowWin" ,"DungeonBeginCoolDownWin","DungeonFightWin","StatusTipWin"
+ ,"ScrollTipWin","MarqueeWin","ExperienceOpenWin","TrumpetWin","BattlePrepareCoolDownWin","DungeonGradeWin","BattleHintWin",
+ "TreasureDungeonMissionHintWin","FairyGrabBossHintWin","DungeonFairyFeastHintWin","PetAndMountPushWin","UpgradeWin","DungeonFairyLandWin"
+ ,"GatherSoulDungeonHintWin"
+ };
+
+ UIRoot m_UIRoot;
+ public UIRoot uiRoot
+ {
+ get
+ {
+ if (m_UIRoot == null)
+ {
+ var prefab = BuiltInLoader.LoadPrefab("UIRoot");
+ var instance = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity);
+ instance.name = "UIRoot";
+ m_UIRoot = instance.GetComponent<UIRoot>();
+ if (Application.isPlaying)
+ {
+ GameObject.DontDestroyOnLoad(instance);
+ }
+ }
+ return m_UIRoot;
+ }
+ }
+
WindowAsyncLoad m_AnyncLoad;
- public WindowAsyncLoad asyncLoad {
- get {
+ public WindowAsyncLoad asyncLoad
+ {
+ get
+ {
if (m_AnyncLoad == null)
{
var gameObject = new GameObject("WindowAnyncLoad");
@@ -25,6 +60,33 @@
List<OpenCommand> openCommands = new List<OpenCommand>();
List<CloseCommand> closeCommands = new List<CloseCommand>();
+
+ public T Get<T>() where T : Window
+ {
+ T win = null;
+ if (TryGetWindow(out win))
+ {
+ return win;
+ }
+ else
+ {
+ DebugEx.LogFormat("娌℃湁鎵惧埌绐楀彛:{0}", typeof(T).Name);
+ return null;
+ }
+
+ }
+
+ public Window Get(string name)
+ {
+ if (windows.ContainsKey(name))
+ {
+ return windows[name];
+ }
+ else
+ {
+ return null;
+ }
+ }
public void OpenFromLocal<T>() where T : Window
{
@@ -128,8 +190,23 @@
public void Close<T>() where T : Window
{
- var name = typeof(T).Name;
+ PushCloseCommand(new CloseCommand()
+ {
+ name = typeof(T).Name,
+ });
+ }
+ public void Close(string name)
+ {
+ PushCloseCommand(new CloseCommand()
+ {
+ name = name,
+ });
+ }
+
+ private void PushCloseCommand(CloseCommand command)
+ {
+ var name = command.name;
var index = openCommands.FindIndex((x) => { return x.name == name; });
if (index != -1)
{
@@ -139,12 +216,339 @@
var exist = closeCommands.Exists((x) => { return x.name == name; });
if (!exist)
{
- closeCommands.Add(new CloseCommand()
+ closeCommands.Add(command);
+ }
+ }
+
+ public List<string> GetAll()
+ {
+ return new List<string>(windows.Keys);
+ }
+
+ public void CloseAll(CloseAllIgnoreType ignoreType = CloseAllIgnoreType.System)
+ {
+ foreach (var window in windows.Values)
+ {
+ if (window == null)
{
- name = name,
- });
+ continue;
+ }
+
+ var isIgnore = false;
+ switch (ignoreType)
+ {
+ case CloseAllIgnoreType.Base:
+ isIgnore = window.windowInfo.windowType <= WindowType.Base;
+ break;
+ case CloseAllIgnoreType.BaseAndCustom:
+ isIgnore = window.windowInfo.windowType <= WindowType.Base || closeAllIgnoreWindows.Contains(window.name);
+ break;
+ case CloseAllIgnoreType.System:
+ isIgnore = window.windowInfo.windowType >= WindowType.System;
+ break;
+ case CloseAllIgnoreType.Custom:
+ isIgnore = closeAllIgnoreWindows.Contains(window.name);
+ break;
+ case CloseAllIgnoreType.SystemAndCustom:
+ isIgnore = window.windowInfo.windowType >= WindowType.System || closeAllIgnoreWindows.Contains(window.name);
+ break;
+ }
+
+ if (!isIgnore)
+ {
+ if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
+ {
+ window.CloseImmediately();
+ }
+ }
}
+ asyncLoad.StopAllTasks();
+ }
+
+ public void CloseOthers<T>() where T : Window
+ {
+ foreach (var name in windows.Keys)
+ {
+ var window = windows[name];
+ if (window is T)
+ {
+ continue;
+ }
+
+ if (window != null)
+ {
+ if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
+ {
+ Close(name);
+ }
+ }
+ }
+
+ asyncLoad.StopAllTasks();
+ }
+
+ public void CloseOthers(List<string> windowNames, CloseAllIgnoreType ignoreType)
+ {
+ foreach (var name in windows.Keys)
+ {
+ var window = windows[name];
+ if (window == null)
+ {
+ continue;
+ }
+
+ var isIgnore = false;
+ switch (ignoreType)
+ {
+ case CloseAllIgnoreType.Base:
+ isIgnore = windowNames.Contains(name) || window.windowInfo.windowType <= WindowType.Base;
+ break;
+ case CloseAllIgnoreType.BaseAndCustom:
+ isIgnore = windowNames.Contains(name) || window.windowInfo.windowType <= WindowType.Base || closeAllIgnoreWindows.Contains(name);
+ break;
+ case CloseAllIgnoreType.System:
+ isIgnore = windowNames.Contains(name) || window.windowInfo.windowType >= WindowType.System;
+ break;
+ case CloseAllIgnoreType.Custom:
+ isIgnore = windowNames.Contains(name) || closeAllIgnoreWindows.Contains(name);
+ break;
+ case CloseAllIgnoreType.SystemAndCustom:
+ isIgnore = windowNames.Contains(name) || window.windowInfo.windowType >= WindowType.System || closeAllIgnoreWindows.Contains(name);
+ break;
+ }
+
+ if (!isIgnore)
+ {
+ if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
+ {
+ Close(name);
+ }
+ }
+ }
+
+ asyncLoad.StopAllTasks();
+ }
+
+ public void DestoryWinsByStage(WindowStage _windowStage)
+ {
+ switch (_windowStage)
+ {
+ case WindowStage.Launch:
+ DestroyWin<DownLoadWin>();
+ DestroyWin<VersionUpdateWin>();
+ DestroyWin<LaunchWin>();
+ break;
+ case WindowStage.Login:
+ DestroyWin<LoginWin>();
+ DestroyWin<ServerListWin>();
+ break;
+ case WindowStage.SelectRole:
+ DestroyWin<CreateRoleWin>();
+ DestroyWin<SelectRoleWin>();
+ DestroyWin<LaunchBackGroundWin>();
+ break;
+ default:
+ break;
+ }
+
+ UnLoadAssetBundle(_windowStage);
+ }
+
+ public void DestroyWin<T>() where T : Window
+ {
+ DestroyWin(typeof(T).Name);
+ }
+
+ public void DestroyWin(string name)
+ {
+ if (windows.ContainsKey(name))
+ {
+ var win = windows[name];
+ win.CloseImmediately();
+ GameObject.Destroy(win.gameObject);
+ MonoBehaviour.Destroy(win);
+ windows[name] = null;
+ windows.Remove(name);
+ }
+ else
+ {
+ DebugEx.LogFormat("{0} 绐楀彛鏃犳硶鑾峰緱锛�", name);
+ }
+ }
+
+ public void UnLoadAssetBundle(WindowStage windowStage)
+ {
+ if (!AssetSource.uiFromEditor)
+ {
+ switch (windowStage)
+ {
+ case WindowStage.Launch:
+ break;
+ case WindowStage.Login:
+ AssetBundleUtility.Instance.UnloadAsset("ui/prioritywindow", "LoginWin");
+ AssetBundleUtility.Instance.UnloadAsset("ui/prioritywindow", "ServerListWin");
+ break;
+ case WindowStage.SelectRole:
+ AssetBundleUtility.Instance.UnloadAsset("ui/prioritywindow", "CreateRoleWin");
+ AssetBundleUtility.Instance.UnloadAsset("ui/prioritywindow", "SelectRoleWin");
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ public bool IsOpen<T>() where T : Window
+ {
+ T win = null;
+ if (TryGetWindow(out win))
+ {
+ var open = win.windowState == Window.WindowState.Opened
+ || win.windowState == Window.WindowState.Opening;
+
+ return open;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public bool IsOpen(string name)
+ {
+ if (windows.ContainsKey(name) && windows[name] != null)
+ {
+ var window = windows[name];
+ return window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public bool ExitAnyFullScreenOrMaskWin()
+ {
+ bool exist = false;
+ foreach (var window in windows.Values)
+ {
+ if (window.windowInfo.needMask || window.windowInfo.fullScreen)
+ {
+ if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
+ {
+ exist = true;
+ break;
+ }
+ }
+ }
+
+ return exist;
+ }
+
+ /// <summary>
+ /// 鏄惁瀛樺湪澶т簬鎴栫瓑浜庤繖涓眰绾х殑鍏ㄥ睆鎴栨湁妯$硦鑳屾櫙鐨勭晫闈�
+ /// </summary>
+ /// <param name="windowType"></param>
+ /// <returns></returns>
+ public bool ExitAnyFullScreenOrMaskWinLEqual(WindowType windowType)
+ {
+ bool exist = false;
+ foreach (var window in windows.Values)
+ {
+ if ((window.windowInfo.needMask || window.windowInfo.fullScreen) && window.windowInfo.windowType >= windowType)
+ {
+ if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
+ {
+ exist = true;
+ break;
+ }
+ }
+ }
+
+ return exist;
+ }
+
+ internal void NotifyBeforeOpen<T>(T window) where T : Window
+ {
+ if (windowBeforeOpenEvent != null)
+ {
+ windowBeforeOpenEvent(window);
+ }
+ }
+
+ internal void NotifyAfterOpen<T>(T window) where T : Window
+ {
+ if (windowAfterOpenEvent != null)
+ {
+ windowAfterOpenEvent(window);
+ }
+ }
+
+ internal void NotifyBeforeClose<T>(T window) where T : Window
+ {
+ if (windowBeforeCloseEvent != null)
+ {
+ windowBeforeCloseEvent(window);
+ }
+ }
+
+ internal void NotifyAfterClose<T>(T window) where T : Window
+ {
+ if (windowAfterCloseEvent != null)
+ {
+ windowAfterCloseEvent(window);
+ }
+ }
+
+ internal void JumpNotifyAfterClose<T>(T window) where T : Window
+ {
+ if (jumpWindowCloseEvent != null)
+ {
+ jumpWindowCloseEvent(window);
+ }
+ }
+
+ private bool TryGetWindow<T>(out T win) where T : Window
+ {
+ var name = typeof(T).Name;
+ Window window = null;
+ if (TryGetWindow(name, out window))
+ {
+ win = windows[name] as T;
+ return win != null;
+ }
+ else
+ {
+ win = null;
+ return false;
+ }
+ }
+
+ private bool TryGetWindow(string name, out Window win)
+ {
+ WindowTrim(name);
+ if (windows.ContainsKey(name))
+ {
+ win = windows[name];
+ return win != null;
+ }
+ else
+ {
+ win = null;
+ return false;
+ }
+ }
+
+ private void WindowTrim(string name)
+ {
+ if (windows.ContainsKey(name))
+ {
+ if (windows[name] == null || windows[name].gameObject == null)
+ {
+ windows.Remove(name);
+ }
+ }
}
private void LateUpdate()
@@ -288,6 +692,23 @@
public string name;
}
+ public enum WindowStage
+ {
+ Launch,
+ Login,
+ SelectRole,
+ Other,
+ }
+
+ public enum CloseAllIgnoreType
+ {
+ Base = 1,
+ System = 2,
+ Custom = 3,
+ BaseAndCustom = 4,
+ SystemAndCustom = 5,
+ }
+
}
}
--
Gitblit v1.8.0