From 628795e89590ad0e0e6f35213c2a6c60b0f8ebf2 Mon Sep 17 00:00:00 2001
From: client_Wu Xijin <364452445@qq.com>
Date: 星期二, 12 二月 2019 11:54:53 +0800
Subject: [PATCH] 3335 窗口重构完整提交。
---
System/WindowBase/WindowCenter.cs | 775 ++++++++++++++++++++++++++++-------------------------------
1 files changed, 370 insertions(+), 405 deletions(-)
diff --git a/System/WindowBase/WindowCenter.cs b/System/WindowBase/WindowCenter.cs
index 916b305..22be9e0 100644
--- a/System/WindowBase/WindowCenter.cs
+++ b/System/WindowBase/WindowCenter.cs
@@ -1,24 +1,25 @@
-锘縰sing System.Collections.Generic;
+锘縰sing System.Collections;
+using System.Collections.Generic;
using UnityEngine;
using System;
namespace Snxxz.UI
{
[XLua.LuaCallCSharp]
- public class WindowCenter : Singleton<WindowCenter>
-
+ 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"
- };
+ "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 {
@@ -52,151 +53,9 @@
}
}
- int m_PreCreateWindowNum = 0;
- public bool isPreCreating {
- get {
- return m_PreCreateWindowNum > 0;
- }
- }
-
- Dictionary<string, Window> windows = new Dictionary<string, Window>();
-
- public void OpenFromLocal<T>() where T : Window
- {
- var windowName = typeof(T).Name;
- OpenFromLocal(windowName);
- }
-
- public void OpenFromLocal(string _name)
- {
- Window win = null;
- if (TryGetWindow(_name, out win))
- {
- if (win.windowState == Window.WindowState.Closed)
- {
- win.functionOrder = 0;
- win.playAnimation = true;
- win.Open();
- }
- else
- {
- DebugEx.LogFormat("{0} 绐楀彛宸茬粡鎵撳紑锛�", _name);
- }
- }
- else
- {
- win = GetWindowInstance(_name, true);
- if (win != null)
- {
- win.functionOrder = 0;
- win.playAnimation = true;
- win.Open();
- }
- }
- }
-
- public T Open<T>(bool _forceSync = false, int _functionalOrder = 0) where T : Window
- {
- var name = typeof(T).Name;
- var window = Open(name, _forceSync, _functionalOrder);
- if (window != null)
- {
- return window as T;
- }
- else
- {
- return null;
- }
- }
-
- public Window Open(string _name, bool _forceSync = false, int _functionalOrder = 0)
- {
- if (VersionConfig.Get().isBanShu)
- {
- if (_name == "VipRechargeWin")
- {
- SysNotifyMgr.Instance.ShowTip("FuncNoOpen_VIP");
- return null;
- }
- }
-
- var childWindow = string.Empty;
- if (_forceSync || AssetSource.uiFromEditor)
- {
- return OpenSingleWindow(_name, _forceSync, _functionalOrder);
- }
- else
- {
- if (WindowConfig.Get().FindChildWindow(_name, _functionalOrder, out childWindow))
- {
- WindowTrim(childWindow);
- if (!windows.ContainsKey(childWindow))
- {
- GetWindowInstanceAsync(childWindow, (bool _ok, UnityEngine.Object _object) =>
- {
- if (_ok)
- {
- OpenSingleWindow(_name, _forceSync, _functionalOrder);
- }
- });
-
- return null;
- }
- else
- {
- return OpenSingleWindow(_name, _forceSync, _functionalOrder);
- }
- }
- else
- {
- return OpenSingleWindow(_name, _forceSync, _functionalOrder);
- }
- }
- }
-
- public T OpenWithoutAnimation<T>() where T : Window
- {
- var name = typeof(T).Name;
- var window = OpenWithoutAnimation(name);
- if (window != null)
- {
- return window as T;
- }
- else
- {
- return null;
- }
- }
-
- public Window OpenWithoutAnimation(string _name)
- {
- Window win = null;
- if (TryGetWindow(_name, out win))
- {
- if (win.windowState == Window.WindowState.Closed)
- {
- win.functionOrder = 0;
- win.playAnimation = false;
- win.Open();
- }
- else
- {
- DebugEx.LogFormat("{0} 绐楀彛宸茬粡鎵撳紑锛�", _name);
- }
-
- return win;
- }
-
- win = GetWindowInstance(_name, false);
- if (win != null)
- {
- win.functionOrder = 0;
- win.playAnimation = false;
- win.Open();
- }
-
- return win;
- }
+ Windows windows = new Windows();
+ List<OpenCommand> openCommands = new List<OpenCommand>();
+ List<CloseCommand> closeCommands = new List<CloseCommand>();
public T Get<T>() where T : Window
{
@@ -213,11 +72,11 @@
}
- public Window Get(string _window)
+ public Window Get(string name)
{
- if (windows.ContainsKey(_window))
+ if (windows.ContainsKey(name))
{
- return windows[_window];
+ return windows[name];
}
else
{
@@ -225,75 +84,127 @@
}
}
- public T Close<T>() where T : Window
+ public void OpenFromLocal<T>() where T : Window
{
- T win = null;
- if (TryGetWindow<T>(out win))
+ var command = new OpenCommand()
{
- if (win.windowState != Window.WindowState.Closed)
- {
- win.CloseImmediately();
- }
- else
- {
- DebugEx.LogFormat("{0} 绐楀彛宸茬粡鍏抽棴锛�", typeof(T));
- }
+ name = typeof(T).Name,
+ sync = true,
+ playAnimatioin = false,
+ fromBuiltIn = true,
+ functionOrder = 0
+ };
+
+ PushOpenCommand(command);
+ }
+
+ public void OpenFromLocal(string name)
+ {
+ var command = new OpenCommand()
+ {
+ name = name,
+ sync = true,
+ playAnimatioin = false,
+ fromBuiltIn = true,
+ functionOrder = 0
+ };
+
+ PushOpenCommand(command);
+ }
+
+ public void Open<T>(bool forceSync = false, int functionOrder = 0) where T : Window
+ {
+ var command = new OpenCommand()
+ {
+ name = typeof(T).Name,
+ sync = forceSync,
+ playAnimatioin = true,
+ fromBuiltIn = false,
+ functionOrder = functionOrder
+ };
+
+ PushOpenCommand(command);
+ }
+
+ public void Open(string name, bool forceSync = false, int functionOrder = 0)
+ {
+ var command = new OpenCommand()
+ {
+ name = name,
+ sync = forceSync,
+ playAnimatioin = true,
+ fromBuiltIn = false,
+ functionOrder = functionOrder
+ };
+
+ PushOpenCommand(command);
+ }
+
+ private void PushOpenCommand(OpenCommand command)
+ {
+ var name = command.name;
+ var index = closeCommands.FindIndex((x) => { return x.name == name; });
+ if (index != -1)
+ {
+ closeCommands.RemoveAt(index);
+ }
+
+ var exist = openCommands.Exists((x) => { return x.name == name; });
+ if (!exist)
+ {
+ openCommands.Add(command);
+ }
+ }
+
+ public void Close<T>() where T : Window
+ {
+ PushCloseCommand(new CloseCommand()
+ {
+ name = typeof(T).Name,
+ });
+ }
+
+ public void Close(string name)
+ {
+ if (WindowConfig.Get().IsChildWindow(name))
+ {
+ CloseImmediately(name);
}
else
{
- asyncLoad.StopTask(typeof(T).Name);
- DebugEx.LogFormat("{0} 绐楀彛鏃犳硶鑾峰緱锛�", typeof(T));
+ PushCloseCommand(new CloseCommand()
+ {
+ name = name,
+ });
}
-
- return win;
}
- public Window Close(string _name)
+ public void CloseImmediately(string name)
{
- if (windows.ContainsKey(_name))
+ Window window;
+ if (windows.TryGetValue(name, out window))
{
- var window = windows[_name];
if (window.windowState != Window.WindowState.Closed)
{
window.CloseImmediately();
}
- else
- {
- DebugEx.LogFormat("{0} 绐楀彛宸茬粡鍏抽棴锛�", _name);
- }
-
- return window;
}
- else
- {
- asyncLoad.StopTask(_name);
- DebugEx.LogFormat("{0} 绐楀彛鏃犳硶鑾峰緱锛�", _name);
- return null;
- }
-
}
- public T CloseImmediately<T>() where T : Window
+ private void PushCloseCommand(CloseCommand command)
{
- T win = null;
- if (TryGetWindow<T>(out win))
+ var name = command.name;
+ var index = openCommands.FindIndex((x) => { return x.name == name; });
+ if (index != -1)
{
- if (win.windowState != Window.WindowState.Closed)
- {
- win.CloseImmediately();
- }
- else
- {
- DebugEx.LogFormat("{0} 绐楀彛宸茬粡鍏抽棴锛�", typeof(T));
- }
- }
- else
- {
- asyncLoad.StopTask(typeof(T).Name);
- DebugEx.LogFormat("{0} 绐楀彛鏃犳硶鑾峰緱锛�", typeof(T));
+ openCommands.RemoveAt(index);
}
- return win;
+ var exist = closeCommands.Exists((x) => { return x.name == name; });
+ if (!exist)
+ {
+ closeCommands.Add(command);
+ }
}
public List<string> GetAll()
@@ -301,40 +212,43 @@
return new List<string>(windows.Keys);
}
- public void CloseAll(CloseAllIgnoreType _ignoreType = CloseAllIgnoreType.System)
+ public void CloseAll(CloseAllIgnoreType ignoreType = CloseAllIgnoreType.System)
{
- foreach (var window in windows.Values)
+ for (var i = windows.Keys.Count - 1; i >= 0; i--)
{
+ var name = windows.Keys[i];
+ var window = windows[name];
if (window == null)
{
continue;
}
var isIgnore = false;
- switch (_ignoreType)
+ 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);
+ isIgnore = window.windowInfo.windowType <= WindowType.Base || closeAllIgnoreWindows.Contains(name);
break;
case CloseAllIgnoreType.System:
isIgnore = window.windowInfo.windowType >= WindowType.System;
break;
case CloseAllIgnoreType.Custom:
- isIgnore = closeAllIgnoreWindows.Contains(window.name);
+ isIgnore = closeAllIgnoreWindows.Contains(name);
break;
case CloseAllIgnoreType.SystemAndCustom:
- isIgnore = window.windowInfo.windowType >= WindowType.System || closeAllIgnoreWindows.Contains(window.name);
+ isIgnore = window.windowInfo.windowType >= WindowType.System || closeAllIgnoreWindows.Contains(name);
break;
}
+ isIgnore = isIgnore || WindowConfig.Get().IsChildWindow(name);
if (!isIgnore)
{
if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
{
- window.CloseImmediately();
+ Close(name);
}
}
}
@@ -344,9 +258,17 @@
public void CloseOthers<T>() where T : Window
{
- foreach (var window in windows.Values)
+ for (var i = windows.Keys.Count - 1; i >= 0; i--)
{
- if (window is T)
+ var name = windows.Keys[i];
+ var window = windows[name];
+ if (window == null || window is T)
+ {
+ continue;
+ }
+
+ var isIgnore = closeAllIgnoreWindows.Contains(name) || WindowConfig.Get().IsChildWindow(name);
+ if (isIgnore)
{
continue;
}
@@ -355,7 +277,7 @@
{
if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
{
- window.CloseImmediately();
+ Close(name);
}
}
}
@@ -363,40 +285,44 @@
asyncLoad.StopAllTasks();
}
- public void CloseOthers(List<string> _windowNames, CloseAllIgnoreType _ignoreType)
+ public void CloseOthers(List<string> windowNames, CloseAllIgnoreType ignoreType)
{
- foreach (var window in windows.Values)
+ for (var i = windows.Keys.Count - 1; i >= 0; i--)
{
+ var name = windows.Keys[i];
+ var window = windows[name];
if (window == null)
{
continue;
}
var isIgnore = false;
- switch (_ignoreType)
+ switch (ignoreType)
{
case CloseAllIgnoreType.Base:
- isIgnore = _windowNames.Contains(window.name) || window.windowInfo.windowType <= WindowType.Base;
+ isIgnore = windowNames.Contains(name) || window.windowInfo.windowType <= WindowType.Base;
break;
case CloseAllIgnoreType.BaseAndCustom:
- isIgnore = _windowNames.Contains(window.name) || window.windowInfo.windowType <= WindowType.Base || closeAllIgnoreWindows.Contains(window.name);
+ isIgnore = windowNames.Contains(name) || window.windowInfo.windowType <= WindowType.Base || closeAllIgnoreWindows.Contains(name);
break;
case CloseAllIgnoreType.System:
- isIgnore = _windowNames.Contains(window.name) || window.windowInfo.windowType >= WindowType.System;
+ isIgnore = windowNames.Contains(name) || window.windowInfo.windowType >= WindowType.System;
break;
case CloseAllIgnoreType.Custom:
- isIgnore = _windowNames.Contains(window.name) || closeAllIgnoreWindows.Contains(window.name);
+ isIgnore = windowNames.Contains(name) || closeAllIgnoreWindows.Contains(name);
break;
case CloseAllIgnoreType.SystemAndCustom:
- isIgnore = _windowNames.Contains(window.name) || window.windowInfo.windowType >= WindowType.System || closeAllIgnoreWindows.Contains(window.name);
+ isIgnore = windowNames.Contains(name) || window.windowInfo.windowType >= WindowType.System || closeAllIgnoreWindows.Contains(name);
break;
}
+
+ isIgnore = isIgnore || WindowConfig.Get().IsChildWindow(name);
if (!isIgnore)
{
if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
{
- window.CloseImmediately();
+ Close(name);
}
}
}
@@ -404,9 +330,9 @@
asyncLoad.StopAllTasks();
}
- public void DestoryWinsByStage(WindowStage _windowStage)
+ public void DestoryWinsByStage(WindowStage windowStage)
{
- switch (_windowStage)
+ switch (windowStage)
{
case WindowStage.Launch:
DestroyWin<DownLoadWin>();
@@ -426,7 +352,7 @@
break;
}
- UnLoadAssetBundle(_windowStage);
+ UnLoadAssetBundle(windowStage);
}
public void DestroyWin<T>() where T : Window
@@ -434,28 +360,28 @@
DestroyWin(typeof(T).Name);
}
- public void DestroyWin(string _name)
+ public void DestroyWin(string name)
{
- if (windows.ContainsKey(_name))
+ if (windows.ContainsKey(name))
{
- var win = windows[_name];
+ var win = windows[name];
win.CloseImmediately();
GameObject.Destroy(win.gameObject);
MonoBehaviour.Destroy(win);
- windows[_name] = null;
- windows.Remove(_name);
+ windows[name] = null;
+ windows.Remove(name);
}
else
{
- DebugEx.LogFormat("{0} 绐楀彛鏃犳硶鑾峰緱锛�", _name);
+ DebugEx.LogFormat("{0} 绐楀彛鏃犳硶鑾峰緱锛�", name);
}
}
- public void UnLoadAssetBundle(WindowStage _windowStage)
+ public void UnLoadAssetBundle(WindowStage windowStage)
{
if (!AssetSource.uiFromEditor)
{
- switch (_windowStage)
+ switch (windowStage)
{
case WindowStage.Launch:
break;
@@ -489,11 +415,11 @@
}
}
- public bool IsOpen(string _name)
+ public bool IsOpen(string name)
{
- if (windows.ContainsKey(_name) && windows[_name] != null)
+ if (windows.ContainsKey(name) && windows[name] != null)
{
- var window = windows[_name];
+ var window = windows[name];
return window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening;
}
else
@@ -502,296 +428,299 @@
}
}
- public bool ExitAnyFullScreenOrMaskWin()
+ public bool ExistAnyFullScreenOrMaskWin()
{
- bool exit = false;
- foreach (var window in windows.Values)
+ var exist = false;
+ foreach (var name in windows.Keys)
{
+ var window = windows[name];
if (window.windowInfo.needMask || window.windowInfo.fullScreen)
{
if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
{
- exit = true;
+ exist = true;
break;
}
}
}
- return exit;
+ return exist;
}
/// <summary>
/// 鏄惁瀛樺湪澶т簬鎴栫瓑浜庤繖涓眰绾х殑鍏ㄥ睆鎴栨湁妯$硦鑳屾櫙鐨勭晫闈�
/// </summary>
- /// <param name="_windowType"></param>
+ /// <param name="windowType"></param>
/// <returns></returns>
- public bool ExitAnyFullScreenOrMaskWinLEqual(WindowType _windowType)
+ public bool ExistAnyFullScreenOrMaskWinLEqual(WindowType windowType)
{
- bool exit = false;
- foreach (var window in windows.Values)
+ var exist = false;
+ foreach (var name in windows.Keys)
{
- if ((window.windowInfo.needMask || window.windowInfo.fullScreen) && window.windowInfo.windowType >= _windowType)
+ var window = windows[name];
+ if ((window.windowInfo.needMask || window.windowInfo.fullScreen) && window.windowInfo.windowType >= windowType)
{
if (window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening)
{
- exit = true;
+ exist = true;
break;
}
}
}
- return exit;
+ return exist;
}
- internal void NotifyBeforeOpen<T>(T _window) where T : Window
+ internal void NotifyBeforeOpen<T>(T window) where T : Window
{
if (windowBeforeOpenEvent != null)
{
- windowBeforeOpenEvent(_window);
+ windowBeforeOpenEvent(window);
}
}
- internal void NotifyAfterOpen<T>(T _window) where T : Window
+ internal void NotifyAfterOpen<T>(T window) where T : Window
{
if (windowAfterOpenEvent != null)
{
- windowAfterOpenEvent(_window);
+ windowAfterOpenEvent(window);
}
}
- internal void NotifyBeforeClose<T>(T _window) where T : Window
+ internal void NotifyBeforeClose<T>(T window) where T : Window
{
if (windowBeforeCloseEvent != null)
{
- windowBeforeCloseEvent(_window);
+ windowBeforeCloseEvent(window);
}
}
- internal void NotifyAfterClose<T>(T _window) where T : Window
+ internal void NotifyAfterClose<T>(T window) where T : Window
{
if (windowAfterCloseEvent != null)
{
- windowAfterCloseEvent(_window);
+ windowAfterCloseEvent(window);
}
}
- internal void JumpNotifyAfterClose<T>(T _window) where T : Window
+ internal void JumpNotifyAfterClose<T>(T window) where T : Window
{
if (jumpWindowCloseEvent != null)
{
- jumpWindowCloseEvent(_window);
+ jumpWindowCloseEvent(window);
}
}
- private T OpenSingleWindow<T>(bool _forceSync, int _functionalOrder) where T : Window
- {
- var name = typeof(T).Name;
- var window = OpenSingleWindow(name, _forceSync, _functionalOrder);
- if (window != null)
- {
- return window as T;
- }
- else
- {
- return null;
- }
- }
-
- private Window OpenSingleWindow(string _name, bool _forceSync, int _functionalOrder)
- {
- Window win = null;
- if (TryGetWindow(_name, out win))
- {
- if (win.windowState == Window.WindowState.Closed)
- {
- win.functionOrder = _functionalOrder;
- win.playAnimation = true;
- win.Open();
- }
- else
- {
- DebugEx.LogFormat("{0} 绐楀彛宸茬粡鎵撳紑锛�", _name);
- }
-
- return win;
- }
-
- if (_forceSync || AssetSource.uiFromEditor)
- {
- win = GetWindowInstance(_name, false);
- if (win != null)
- {
- win.functionOrder = _functionalOrder;
- win.playAnimation = true;
- win.Open();
- }
-
- return win;
- }
- else
- {
- GetWindowInstanceAsync(_name,
- (bool ok, UnityEngine.Object _object) =>
- {
- if (TryGetWindow(_name, out win))
- {
- if (win.windowState == Window.WindowState.Closed)
- {
- win.functionOrder = _functionalOrder;
- win.playAnimation = true;
- win.Open();
- }
- else
- {
- DebugEx.Log(string.Format("{0} 绐楀彛宸茬粡鎵撳紑锛�", _name));
- }
- }
- }
- );
-
- return null;
- }
- }
-
- private bool TryGetWindow<T>(out T _win) where T : 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;
+ win = windows[name] as T;
+ return win != null;
}
else
{
- _win = null;
+ win = null;
return false;
}
}
- private bool TryGetWindow(string _name, out Window _win)
+ private bool TryGetWindow(string name, out Window win)
{
- WindowTrim(_name);
- if (windows.ContainsKey(_name))
+ WindowTrim(name);
+ if (windows.ContainsKey(name))
{
- _win = windows[_name];
- return _win != null;
+ win = windows[name];
+ return win != null;
}
else
{
- _win = null;
+ win = null;
return false;
}
}
- private void WindowTrim(string _windowName)
+ private void WindowTrim(string name)
{
- if (windows.ContainsKey(_windowName))
+ if (windows.ContainsKey(name))
{
- if (windows[_windowName] == null || windows[_windowName].gameObject == null)
+ if (windows[name] == null || windows[name].gameObject == null)
{
- windows.Remove(_windowName);
+ windows.Remove(name);
}
}
}
- private T GetWindowInstance<T>(bool _fromLocal) where T : Window
+ float checkTimer = 0f;
+ private void LateUpdate()
{
- var prefabName = typeof(T).Name;
- var window = GetWindowInstance(prefabName, _fromLocal);
- if (window != null)
+ while (closeCommands.Count > 0)
{
- return window as T;
+ var command = closeCommands[0];
+ closeCommands.RemoveAt(0);
+ Window window = null;
+ if (windows.TryGetValue(command.name, out window))
+ {
+ if (window.windowState != Window.WindowState.Closed)
+ {
+ window.CloseImmediately();
+ }
+ }
+
+ asyncLoad.StopTask(command.name);
+ }
+
+ while (openCommands.Count > 0)
+ {
+ var command = openCommands[0];
+ openCommands.RemoveAt(0);
+ Window window = null;
+ if (windows.TryGetValue(command.name, out window))
+ {
+ if (window.windowState == Window.WindowState.Closed)
+ {
+ window.playAnimation = command.playAnimatioin;
+ window.functionOrder = command.functionOrder;
+ window.Open();
+ }
+ else
+ {
+ DebugEx.LogFormat("{0} 绐楀彛宸茬粡鎵撳紑锛�", command.name);
+ }
+ }
+ else
+ {
+ ExecuteFirstOpen(command);
+ }
+
+ }
+
+ checkTimer += Time.deltaTime;
+ if (checkTimer > 2f)
+ {
+ checkTimer = 0f;
+ if (!StageLoad.Instance.isLoading)
+ {
+ var exceptOpen = StageLoad.Instance.stageType == Stage.E_StageType.Dungeon
+ && !ExistAnyFullScreenOrMaskWinLEqual(WindowType.Base)
+ && !IsOpen("DefaultDialogueBoxWin")
+ && !IsOpen("DialogueDuidanceWin")
+ && !IsOpen("TaskBoxBGMWin");
+
+ if (exceptOpen != IsOpen("MainInterfaceWin"))
+ {
+ if (exceptOpen)
+ {
+ Open("MainInterfaceWin", true);
+ }
+ else
+ {
+ Close("MainInterfaceWin");
+ }
+ }
+ }
+ }
+
+ }
+
+ private void ExecuteFirstOpen(OpenCommand command)
+ {
+ GetWindowPrefab(command, (bool ok, GameObject prefab) =>
+ {
+ if (ok)
+ {
+ CreateWindowInstance(command, prefab);
+ Window window = null;
+ if (windows.TryGetValue(command.name, out window))
+ {
+ window.playAnimation = command.playAnimatioin;
+ window.functionOrder = command.functionOrder;
+ window.Open();
+ }
+ }
+ });
+ }
+
+ private void GetWindowPrefab(OpenCommand command, Action<bool, GameObject> callBack)
+ {
+ if (command.sync)
+ {
+ var name = command.name;
+ var fromBuiltIn = command.fromBuiltIn;
+ var prefab = fromBuiltIn ? BuiltInLoader.LoadPrefab(name) : UILoader.LoadWindow(name);
+
+ if (callBack != null)
+ {
+ callBack(prefab != null, prefab);
+ }
}
else
{
- return null;
+ var name = command.name;
+ var task = new WindowAsyncLoad.Task(name, (bool ok, UnityEngine.Object @object) =>
+ {
+ var prefab = @object as GameObject;
+ if (callBack != null)
+ {
+ callBack(prefab != null, prefab);
+ }
+ });
+
+ asyncLoad.PushTask(task);
}
}
- private Window GetWindowInstance(string _name, bool _fromLocal)
+ private void CreateWindowInstance(OpenCommand command, GameObject prefab)
{
- if (windows.ContainsKey(_name))
+ var name = command.name;
+ Window window = null;
+ if (!windows.ContainsKey(name))
{
- return windows[_name];
- }
- else
- {
- var prefab = _fromLocal ? BuiltInLoader.LoadPrefab(_name) : UILoader.LoadWindow(_name);
prefab.SetActive(false);
var instance = GameObject.Instantiate(prefab);
- instance.name = _name;
+
if (AssetSource.uiFromEditor)
{
prefab.SetActive(true);
}
- if (_fromLocal)
+ if (command.fromBuiltIn)
{
- BuiltInLoader.UnLoadPrefab(_name);
+ BuiltInLoader.UnLoadPrefab(name);
}
else
{
- UILoader.UnLoadWindowAsset(_name);
+ UILoader.UnLoadWindowAsset(name);
}
- var window = instance.GetComponent<Window>();
+ window = instance.GetComponent<Window>();
+ var typeName = window.GetType().Name;
+ instance.name = typeName;
if (window != null)
{
- windows[_name] = window;
+ windows[typeName] = window;
}
else
{
- DebugEx.LogFormat("鏃犳硶鑾峰緱 {0} 鐨勮祫婧愶紒", _name);
+ Debug.LogFormat("鏃犳硶鑾峰緱 {0} 鐨勮祫婧愶紒", name);
}
-
- return window;
}
}
- private void GetWindowInstanceAsync<T>(Action<bool, UnityEngine.Object> _callBack) where T : Window
+ public struct OpenCommand
{
- GetWindowInstanceAsync(typeof(T).Name, _callBack);
+ public string name;
+ public bool sync;
+ public int functionOrder;
+ public bool playAnimatioin;
+ public bool fromBuiltIn;
}
- private void GetWindowInstanceAsync(string _name, Action<bool, UnityEngine.Object> _callBack)
+ public struct CloseCommand
{
- Action<bool, UnityEngine.Object> addAction = (bool _ok, UnityEngine.Object _object) =>
- {
- var prefabName = _name;
- Window window = null;
- if (!windows.ContainsKey(_name))
- {
- var prefab = _object as GameObject;
- prefab.SetActive(false);
- var instance = GameObject.Instantiate(prefab);
-
- if (AssetSource.uiFromEditor)
- {
- prefab.SetActive(true);
- }
-
- UILoader.UnLoadWindowAsset(prefabName);
- window = instance.GetComponent<Window>();
- var typeName = window.GetType().Name;
- instance.name = typeName;
- if (window != null)
- {
- windows[typeName] = window;
- }
- else
- {
- Debug.LogFormat("鏃犳硶鑾峰緱 {0} 鐨勮祫婧愶紒", _name);
- }
- }
-
- if (_callBack != null)
- {
- _callBack(_ok && window != null, _object);
- }
- };
-
- asyncLoad.PushTask(new WindowAsyncLoad.Task(_name, addAction));
+ public string name;
}
public enum WindowStage
@@ -811,7 +740,43 @@
SystemAndCustom = 5,
}
+ class Windows
+ {
+ Dictionary<string, Window> windows = new Dictionary<string, Window>();
+ List<string> windowKeys = new List<string>();
+
+ public Window this[string key] {
+ get { return windows[key]; }
+ set {
+ windows[key] = value;
+ if (!windowKeys.Contains(key))
+ {
+ windowKeys.Add(key);
+ }
+ }
+ }
+
+ public List<string> Keys { get { return windowKeys; } }
+
+ public bool ContainsKey(string key)
+ {
+ return windowKeys.Contains(key);
+ }
+
+ public bool TryGetValue(string key, out Window window)
+ {
+ return windows.TryGetValue(key, out window);
+ }
+
+ public void Remove(string key)
+ {
+ windows.Remove(key);
+ windowKeys.Remove(key);
+ }
+
+ }
+
}
-
}
+
--
Gitblit v1.8.0