Пример #1
0
        public static bool OpenWindow(string winName, params object[] pars)
        {
            System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
            w.Start();
            if (Instance._curOpenWindow == winName)
            {
                return(false);
            }

            if (Instance._openingHoverWindow.Contains(winName))
            {
                return(false);
            }

            UIWindow win = null;

            if (!Instance._windowCache.ContainsKey(winName))
            {
                Type type = Type.GetType("GameLogic." + winName);
                if (type != null)
                {
                    win = Activator.CreateInstance(type) as UIWindow;
                    if (win != null)
                    {
                        WindowConfig winCfg = DataManager.Instance.windowConfigDatas.GetUnit(winName);
                        if (winCfg != null)
                        {
                            win.ConfigData = winCfg;
                            Instance._windowCache.Add(winName, win);
                        }
                        else
                        {
                            Debugger.LogError("Open : " + winName + " window fail, the WindowConfig " + winName + " don't exist!");
                            return(false);
                        }
                    }
                    else
                    {
                        Debugger.LogError("Open : " + winName + " window fail, create class " + winName + " fail!");
                        return(false);
                    }
                }
                else
                {
                    Debugger.LogError("Open : " + winName + " window fail, the class " + winName + " don't exist!");
                    return(false);
                }
            }

            win = Instance._windowCache[winName];
            if (!win.ConfigData.IsHover)
            {
                bool find = UpdateOpenList(winName);
                CloseCurOpenWindow(find);
                Instance._curOpenWindow = winName;
            }
            else
            {
                Instance._openingHoverWindow.Add(winName);
            }

            if (win.Root == null)
            {
                GameObject root = LoadUIWindow(win);
                if (root)
                {
                    win.Init();
                }
                else
                {
                    Debugger.LogError("Open : " + winName + " window fail, load prefab " + win.ConfigData.PrefabName + " fail!");
                    return(false);
                }
            }

            bool rsl = win.Open(pars);

            //             LogOpenWindowStack();

            w.Stop();
            if (UnityDefine.UnityEditor)
            {
                Debugger.Log("Open " + winName + " finish. Use time : " + w.ElapsedMilliseconds + " ms");
            }
            return(rsl);
        }
        static UIWindow OpenWindow(Type type, params object[] pars)
        {
            string winName = type.ToString();

#if UNITY_EDITOR
            System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
            w.Start();
#endif
            if (Instance._curOpenWindow == winName)
            {
                return(null);
            }

            UIWindow win = GetCacheWindow(winName);
            if (win == null)
            {
                win = Activator.CreateInstance(type) as UIWindow;
                if (win != null)
                {
                    AddCacheWindow(win);
                }
                else
                {
                    Debugger.LogError("Open : " + winName + " window fail, create class " + winName + " fail!");
                    return(null);
                }
            }
            else if (win.IsOpening)
            {
                Debugger.LogError("Then Window : " + winName + " is Already Opened");
                return(null);
            }

            if (!win.Settings.IsHover)
            {
                bool find = UpdateOpenList(winName);
                CloseCurOpenWindow(find);
                Instance._curOpenWindow = winName;
            }
            else
            {
                Instance._openingHoverWindow.Add(win);
            }

            if (win.Root == null)
            {
                GameObject root = LoadUIWindow(win);
                if (root)
                {
                    win.Init();
                }
                else
                {
                    Debugger.LogError("Open : " + winName + " window fail, load prefab " + win.Settings.PrefabName + " fail!");
                    return(null);
                }
            }

            bool rsl = win.Open(pars);
            if (!rsl)
            {
                return(null);
            }

#if UNITY_EDITOR
            w.Stop();
            Debugger.Log("Open " + winName + " finish. Use time : " + w.ElapsedMilliseconds + " ms");
#endif
            return(win);
        }