少年修仙传客户端代码仓库
client_Wu Xijin
2018-08-15 44687fc1bb2fdaa8205751c0f0a72a88842bf575
提供窗口管理的lua接口
3个文件已修改
258 ■■■■ 已修改文件
Core/Common/ResourcesPath.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/Config/AssetSource.cs 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/WindowBase/WindowCenter.cs 236 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/Common/ResourcesPath.cs
@@ -39,6 +39,7 @@
    public static readonly string CONFIG_FODLER = ResourcesOutPath + "refdata/Config";
    public static readonly string AUDIO_SUFFIX = "Audio/";
    public static readonly string LUA_FODLER = ResourcesOutPath + "Lua";
    #endregion
Core/Config/AssetSource.cs
@@ -144,6 +144,23 @@
            m_UIFromEditor=value;
#endif
        }
    }
    }
    static bool m_LuaFromEditor = false;
    public static bool luaFromEditor {
        get {
#if UNITY_EDITOR
            return LocalSave.GetBool("Asset_LuaFromEditor", true);
#else
            return false;
#endif
        }
        set {
#if UNITY_EDITOR
            LocalSave.SetBool("Asset_LuaFromEditor", value);
#else
            m_LuaFromEditor=value;
#endif
        }
    }
}
System/WindowBase/WindowCenter.cs
@@ -60,8 +60,14 @@
        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)
                {
@@ -71,12 +77,12 @@
                }
                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;
@@ -88,24 +94,38 @@
        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))
@@ -114,7 +134,7 @@
                        {
                            if (_ok)
                            {
                                OpenSingleWindow<T>(_forceSync, _functionalOrder);
                                OpenSingleWindow(_name, _forceSync, _functionalOrder);
                            }
                        });
@@ -122,20 +142,35 @@
                    }
                    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)
                {
@@ -145,13 +180,13 @@
                }
                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;
@@ -159,7 +194,7 @@
                win.Open();
            }
            return (T)win;
            return win;
        }
        public T Get<T>() where T : Window
@@ -177,6 +212,7 @@
        }
        [XLua.LuaCallCSharp]
        public Window Get(string _window)
        {
            if (windows.ContainsKey(_window))
@@ -200,16 +236,42 @@
                }
                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
@@ -240,6 +302,7 @@
            return new List<string>(windows.Keys);
        }
        [XLua.LuaCallCSharp]
        public void CloseAll(CloseAllIgnoreType _ignoreType = CloseAllIgnoreType.System)
        {
            foreach (var window in windows.Values)
@@ -300,7 +363,6 @@
            }
            asyncLoad.StopAllTasks();
        }
        public void CloseOthers(List<string> _windowNames, CloseAllIgnoreType _ignoreType)
@@ -371,20 +433,24 @@
        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);
            }
        }
@@ -426,22 +492,18 @@
            }
        }
        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)
@@ -532,8 +594,22 @@
        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)
                {
@@ -543,15 +619,15 @@
                }
                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;
@@ -559,11 +635,11 @@
                    win.Open();
                }
                return (T)win;
                return win;
            }
            else
            {
                GetWindowInstanceAsync<T>(
                GetWindowInstanceAsync(_name,
                    (bool ok, UnityEngine.Object _object) =>
                    {
                        if (TryGetWindow(out win))
@@ -576,7 +652,7 @@
                            }
                            else
                            {
                                DebugEx.Log(string.Format("{0} 窗口已经打开!", typeof(T)));
                                DebugEx.Log(string.Format("{0} 窗口已经打开!", _name));
                            }
                        }
                    }
@@ -588,12 +664,26 @@
        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
@@ -617,14 +707,26 @@
        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)
@@ -632,22 +734,20 @@
                    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
@@ -655,13 +755,13 @@
            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);
@@ -673,15 +773,15 @@
                    }
                    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);
                    }
                }
@@ -691,7 +791,7 @@
                }
            };
            asyncLoad.PushTask(new WindowAsyncLoad.Task(_windowName, addAction));
            asyncLoad.PushTask(new WindowAsyncLoad.Task(_name, addAction));
        }
        public enum WindowStage