Пример #1
0
        //************************************
        // 打开单个指定面板(不包含子面板)
        //************************************
        public void ShowWindow(string winName, params object[] param)
        {
            if (MainCtrl == null)
            {
                return;
            }
            if (CheckWindowDownloaded(winName) == false)
            {
                return;
            }

            if (ModalWindow != null && ModalWindow.IsShow)
            {
                GameDebug.LogWarning(string.Format("当前有模态窗口{0}打开,所以{1}无法打开", ModalWindow.mWndName, winName));
            }

            if (loadingWindows.ContainsKey(winName))
            {
                GameDebug.Log("当前窗口正在加载中:" + winName);
                if (needCloseWindowsAfterResLoad.Contains(winName))
                {
                    needCloseWindowsAfterResLoad.Remove(winName);
                    SetWindowDynOrder(GetExistingWindow(winName));
                }
                return;
            }

            string info = string.Format("show window: {0}", winName);

            BuglyAgent.PrintLog(LogSeverity.LogInfo, info);

            UIBaseWindow baseWin = null;

            if (mWindows.TryGetValue(winName, out baseWin))
            {
                if (baseWin.WinState == WinowState.ResLoadDone)
                {
                    baseWin.ShowParam = param;
                    if (MainCtrl != null)
                    {
                        MainCtrl.CreateAndCheckMoneyBar(baseWin, baseWin.mUIObject, winName, baseWin.CurrencyScale,
                                                        false);
                        //创建概率公示按钮
                        MainCtrl.CreateAndCheckProbabilityBtn(baseWin, baseWin.mUIObject, winName, baseWin.CurrencyScale, false);
                        //创建七日退款按钮
                        MainCtrl.CreateAndCheckRefundBtn(baseWin, baseWin.mUIObject, winName, baseWin.CurrencyScale, false);
                    }

                    baseWin.Show();
                }
            }
            else
            {
#if !DISABLE_LUA
                string lua_script = "";
                string path       = UIHelper.GetLuaWindowPath(winName);
                if (path.CompareTo(string.Empty) == 0)
                {
                    lua_script = string.Format("newUI.{0}", winName);
                }
                else
                {
                    lua_script = string.Format("newUI.{0}.{1}", path, winName);
                }

                //Debug.Log(lua_script);

                if (IsLuaScriptExist(lua_script))
                {
                    baseWin = new UILuaBaseWindow(winName, lua_script);
                }
                else
#endif
                {
                    System.Type t = System.Type.GetType("xc.ui.ugui." + winName);

                    if (t != null)
                    {
                        if (t.IsSubclassOf(typeof(UIBaseWindow)))
                        {
                            baseWin = (UIBaseWindow)System.Activator.CreateInstance(t);
                        }
                        else
                        {
                            GameDebug.Log("use reflection create ugui panel :" + winName);
                            FieldInfo prefabNameField = t.GetField("mWndName", BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public);
                            if (prefabNameField == null)
                            {
                                Debug.LogError(string.Format("the type {0} should cantains a static string field named mPrefabName", t));
                                return;
                            }
                            string prefabName = prefabNameField.GetValue(null) as string;
                            baseWin = new UIBaseWindow(prefabName);
                        }
                    }
                }
                if (baseWin == null)
                {
                    Debug.LogError("UIManager.CreateWindow error:" + winName);
                    return;
                }

                if (baseWin.WinState == WinowState.ResNoLoad)
                {
                    ///这里如果面板时动态的,则预先计算好动态层级
                    this.SetWindowDynOrder(baseWin);

                    baseWin.ShowParam = param;
                    mWindows.Add(winName, baseWin);
                    baseWin.WinState = WinowState.ResLoading;
                    loadingWindows.Add(winName, true);
                    MainCtrl.StartCoroutine(MainCtrl.CreateWindowFromPrefab(baseWin.mWndName, baseWin));
                }
            }

            if (baseWin != null)
            {
                baseWin.IsSystemWindow = false;
            }

            // 如果之前已经设置为true,而在Pop窗口的时候会又调用ShowWindow
            // 此处需要判断下之前是否设置过
            if (!mOpenedSysWindow.ContainsKey(winName))
            {
                mOpenedSysWindow[winName] = false;
            }
        }