| | |
| | | public void OpenFromLocal<T>() where T : Window
|
| | | {
|
| | | var windowName = typeof(T).Name;
|
| | | T win = null;
|
| | | if (TryGetWindow(out win))
|
| | | OpenFromLocal(windowName);
|
| | | }
|
| | |
|
| | | [XLua.LuaCallCSharp]
|
| | | public void OpenFromLocal(string _name)
|
| | | {
|
| | | Window win = null;
|
| | | if (TryGetWindow(_name, out win))
|
| | | {
|
| | | if (win.windowState == Window.WindowState.Closed)
|
| | | {
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | DebugEx.Log(string.Format("{0} 窗口已经打开!", typeof(T)));
|
| | | DebugEx.LogFormat("{0} 窗口已经打开!", _name);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | win = GetWindowInstance<T>(true);
|
| | | win = GetWindowInstance(_name, true);
|
| | | if (win != null)
|
| | | {
|
| | | win.functionOrder = 0;
|
| | |
| | |
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
|
| | | [XLua.LuaCallCSharp]
|
| | | public Window Open(string _name, bool _forceSync = false, int _functionalOrder = 0)
|
| | | {
|
| | | if (VersionConfig.Get().isBanShu)
|
| | | {
|
| | | if (typeof(T) == typeof(VipRechargeWin))
|
| | | if (_name == "VipRechargeWin")
|
| | | {
|
| | | SysNotifyMgr.Instance.ShowTip("FuncNoOpen_VIP");
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | var windowName = typeof(T).Name;
|
| | | string childWindow = string.Empty;
|
| | | var childWindow = string.Empty;
|
| | | if (_forceSync || AssetSource.uiFromEditor)
|
| | | {
|
| | | return OpenSingleWindow<T>(_forceSync, _functionalOrder);
|
| | | return OpenSingleWindow(_name, _forceSync, _functionalOrder);
|
| | | }
|
| | | else
|
| | | {
|
| | | if (WindowConfig.Get().FindChildWindow(windowName, _functionalOrder, out childWindow))
|
| | | if (WindowConfig.Get().FindChildWindow(_name, _functionalOrder, out childWindow))
|
| | | {
|
| | | WindowTrim(childWindow);
|
| | | if (!windows.ContainsKey(childWindow))
|
| | |
| | | {
|
| | | if (_ok)
|
| | | {
|
| | | OpenSingleWindow<T>(_forceSync, _functionalOrder);
|
| | | OpenSingleWindow(_name, _forceSync, _functionalOrder);
|
| | | }
|
| | | });
|
| | |
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | return OpenSingleWindow<T>(_forceSync, _functionalOrder);
|
| | | return OpenSingleWindow(_name, _forceSync, _functionalOrder);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | return OpenSingleWindow<T>(_forceSync, _functionalOrder);
|
| | | return OpenSingleWindow(_name, _forceSync, _functionalOrder);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public T OpenWithoutAnimation<T>() where T : Window
|
| | | {
|
| | | T win = null;
|
| | | if (TryGetWindow(out win))
|
| | | var name = typeof(T).Name;
|
| | | var window = OpenWithoutAnimation(name);
|
| | | if (window != null)
|
| | | {
|
| | | return window as T;
|
| | | }
|
| | | else
|
| | | {
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | [XLua.LuaCallCSharp]
|
| | | public Window OpenWithoutAnimation(string _name)
|
| | | {
|
| | | Window win = null;
|
| | | if (TryGetWindow(_name, out win))
|
| | | {
|
| | | if (win.windowState == Window.WindowState.Closed)
|
| | | {
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | DebugEx.Log(string.Format("{0} 窗口已经打开!", typeof(T)));
|
| | | DebugEx.LogFormat("{0} 窗口已经打开!", _name);
|
| | | }
|
| | |
|
| | | return (T)win;
|
| | | return win;
|
| | | }
|
| | |
|
| | | win = GetWindowInstance<T>(false);
|
| | | win = GetWindowInstance(_name, false);
|
| | | if (win != null)
|
| | | {
|
| | | win.functionOrder = 0;
|
| | |
| | | win.Open();
|
| | | }
|
| | |
|
| | | return (T)win;
|
| | | return win;
|
| | | }
|
| | |
|
| | | public T Get<T>() where T : Window
|
| | |
| | |
|
| | | }
|
| | |
|
| | | [XLua.LuaCallCSharp]
|
| | | public Window Get(string _window)
|
| | | {
|
| | | if (windows.ContainsKey(_window))
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | DebugEx.Log(string.Format("{0} 窗口已经关闭!", typeof(T)));
|
| | | DebugEx.LogFormat("{0} 窗口已经关闭!", typeof(T));
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | asyncLoad.StopTask(typeof(T).Name);
|
| | | DebugEx.Log(string.Format("{0} 窗口无法获得!", typeof(T)));
|
| | | DebugEx.LogFormat("{0} 窗口无法获得!", typeof(T));
|
| | | }
|
| | |
|
| | | return win;
|
| | | }
|
| | |
|
| | | [XLua.LuaCallCSharp]
|
| | | public Window Close(string _name)
|
| | | {
|
| | | if (windows.ContainsKey(_name))
|
| | | {
|
| | | 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
|
| | |
| | | return new List<string>(windows.Keys);
|
| | | }
|
| | |
|
| | | [XLua.LuaCallCSharp]
|
| | | public void CloseAll(CloseAllIgnoreType _ignoreType = CloseAllIgnoreType.System)
|
| | | {
|
| | | foreach (var window in windows.Values)
|
| | |
| | | }
|
| | |
|
| | | asyncLoad.StopAllTasks();
|
| | |
|
| | | }
|
| | |
|
| | | public void CloseOthers(List<string> _windowNames, CloseAllIgnoreType _ignoreType)
|
| | |
| | |
|
| | | public void DestroyWin<T>() where T : Window
|
| | | {
|
| | | T win = null;
|
| | | if (TryGetWindow<T>(out win))
|
| | | DestroyWin(typeof(T).Name);
|
| | | }
|
| | |
|
| | | [XLua.LuaCallCSharp]
|
| | | public void DestroyWin(string _name)
|
| | | {
|
| | | if (windows.ContainsKey(_name))
|
| | | {
|
| | | var win = windows[_name];
|
| | | win.CloseImmediately();
|
| | | GameObject.Destroy(win.gameObject);
|
| | | MonoBehaviour.Destroy(win);
|
| | |
|
| | | var name = typeof(T).Name;
|
| | | windows[name] = null;
|
| | | windows.Remove(typeof(T).Name);
|
| | | windows[_name] = null;
|
| | | windows.Remove(_name);
|
| | | }
|
| | | else
|
| | | {
|
| | | DebugEx.Log(string.Format("{0} 窗口无法获得!", typeof(T)));
|
| | | DebugEx.LogFormat("{0} 窗口无法获得!", _name);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public bool CheckOpen(string _windowName)
|
| | | [XLua.LuaCallCSharp]
|
| | | public bool CheckOpen(string _name)
|
| | | {
|
| | | if (windows.ContainsKey(_windowName) && windows[_windowName] != null)
|
| | | if (windows.ContainsKey(_name) && windows[_name] != null)
|
| | | {
|
| | | var window = windows[_windowName];
|
| | | var window = windows[_name];
|
| | | return window.windowState == Window.WindowState.Opened || window.windowState == Window.WindowState.Opening;
|
| | | }
|
| | | else
|
| | | {
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | public void PreCreateWindows()
|
| | | {
|
| | | m_PreCreateWindowNum = 0;
|
| | | }
|
| | |
|
| | | private void AsyncLoadWindowCallBack(bool _ok, UnityEngine.Object _object)
|
| | |
| | |
|
| | | private T OpenSingleWindow<T>(bool _forceSync, int _functionalOrder) where T : Window
|
| | | {
|
| | | T win = null;
|
| | | if (TryGetWindow(out win))
|
| | | 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)
|
| | | {
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | DebugEx.Log(string.Format("{0} 窗口已经打开!", typeof(T)));
|
| | | DebugEx.LogFormat("{0} 窗口已经打开!", _name);
|
| | | }
|
| | |
|
| | | return (T)win;
|
| | | return win;
|
| | | }
|
| | |
|
| | | if (_forceSync || AssetSource.uiFromEditor)
|
| | | {
|
| | | win = GetWindowInstance<T>(false);
|
| | | win = GetWindowInstance(_name, false);
|
| | | if (win != null)
|
| | | {
|
| | | win.functionOrder = _functionalOrder;
|
| | |
| | | win.Open();
|
| | | }
|
| | |
|
| | | return (T)win;
|
| | | return win;
|
| | | }
|
| | | else
|
| | | {
|
| | | GetWindowInstanceAsync<T>(
|
| | | GetWindowInstanceAsync(_name,
|
| | | (bool ok, UnityEngine.Object _object) =>
|
| | | {
|
| | | if (TryGetWindow(out win))
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | DebugEx.Log(string.Format("{0} 窗口已经打开!", typeof(T)));
|
| | | DebugEx.Log(string.Format("{0} 窗口已经打开!", _name));
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | private bool TryGetWindow<T>(out T _win) where T : Window
|
| | | {
|
| | | var windowName = typeof(T).Name;
|
| | | WindowTrim(windowName);
|
| | |
|
| | | if (windows.ContainsKey(windowName))
|
| | | var name = typeof(T).Name;
|
| | | Window window = null;
|
| | | if (TryGetWindow(name, out window))
|
| | | {
|
| | | _win = (T)windows[windowName];
|
| | | _win = window as T;
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | _win = null;
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | private bool TryGetWindow(string _name, out Window _win)
|
| | | {
|
| | | WindowTrim(_name);
|
| | | if (windows.ContainsKey(_name))
|
| | | {
|
| | | _win = windows[_name];
|
| | | return true;
|
| | | }
|
| | | else
|
| | |
| | | private T GetWindowInstance<T>(bool _fromLocal) where T : Window
|
| | | {
|
| | | var prefabName = typeof(T).Name;
|
| | |
|
| | | if (windows.ContainsKey(prefabName))
|
| | | var window = GetWindowInstance(prefabName, _fromLocal);
|
| | | if (window != null)
|
| | | {
|
| | | return windows[prefabName] as T;
|
| | | return window as T;
|
| | | }
|
| | | else
|
| | | {
|
| | | var prefab = _fromLocal ? Resources.Load<GameObject>(StringUtility.Contact("UI/Prefabs/", prefabName)) : UILoader.LoadWindow(prefabName);
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | private Window GetWindowInstance(string _name, bool _fromLocal)
|
| | | {
|
| | | if (windows.ContainsKey(_name))
|
| | | {
|
| | | return windows[_name];
|
| | | }
|
| | | else
|
| | | {
|
| | | var prefab = _fromLocal ? Resources.Load<GameObject>(StringUtility.Contact("UI/Prefabs/", _name)) : UILoader.LoadWindow(_name);
|
| | | prefab.SetActive(false);
|
| | | var instance = GameObject.Instantiate(prefab);
|
| | | if (AssetSource.uiFromEditor)
|
| | |
| | | prefab.SetActive(true);
|
| | | }
|
| | |
|
| | | UILoader.UnLoadWindowAsset(prefabName);
|
| | | instance.name = prefabName;
|
| | | var window = instance.GetComponent<T>();
|
| | | UILoader.UnLoadWindowAsset(_name);
|
| | | instance.name = _name;
|
| | | var window = instance.GetComponent<Window>();
|
| | | if (window != null)
|
| | | {
|
| | | var windowName = typeof(T).Name;
|
| | | windows[windowName] = window;
|
| | | windows[_name] = window;
|
| | | }
|
| | | else
|
| | | {
|
| | | DebugEx.LogFormat("无法获得 {0} 的资源!", prefabName);
|
| | | DebugEx.LogFormat("无法获得 {0} 的资源!", _name);
|
| | | }
|
| | |
|
| | | return window;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | private void GetWindowInstanceAsync<T>(Action<bool, UnityEngine.Object> _callBack) where T : Window
|
| | |
| | | GetWindowInstanceAsync(typeof(T).Name, _callBack);
|
| | | }
|
| | |
|
| | | private void GetWindowInstanceAsync(string _windowName, Action<bool, UnityEngine.Object> _callBack)
|
| | | private void GetWindowInstanceAsync(string _name, Action<bool, UnityEngine.Object> _callBack)
|
| | | {
|
| | | Action<bool, UnityEngine.Object> addAction = (bool _ok, UnityEngine.Object _object) =>
|
| | | {
|
| | | var prefabName = _windowName;
|
| | | var prefabName = _name;
|
| | | Window window = null;
|
| | | if (!windows.ContainsKey(_windowName))
|
| | | if (!windows.ContainsKey(_name))
|
| | | {
|
| | | var prefab = _object as GameObject;
|
| | | prefab.SetActive(false);
|
| | |
| | | }
|
| | |
|
| | | UILoader.UnLoadWindowAsset(prefabName);
|
| | | instance.name = _windowName;
|
| | | window = (Window)instance.GetComponent(_windowName);
|
| | | instance.name = _name;
|
| | | window = (Window)instance.GetComponent(_name);
|
| | | if (window != null)
|
| | | {
|
| | | windows[_windowName] = (Window)window;
|
| | | windows[_name] = (Window)window;
|
| | | }
|
| | | else
|
| | | {
|
| | | Debug.LogFormat("无法获得 {0} 的资源!", _windowName);
|
| | | Debug.LogFormat("无法获得 {0} 的资源!", _name);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | };
|
| | |
|
| | | asyncLoad.PushTask(new WindowAsyncLoad.Task(_windowName, addAction));
|
| | | asyncLoad.PushTask(new WindowAsyncLoad.Task(_name, addAction));
|
| | | }
|
| | |
|
| | | public enum WindowStage
|