Пример #1
0
        /// <summary>
        /// 从当前UI列表缓存中卸载UI窗体
        /// </summary>
        /// <param name="uiName"></param>
        private void UnLoadParallelUI(string uiName, bool isDestroy = false)
        {
            BaseUI baseUI;

            //当前UI显示列表中没有记录或者总表中没有记录则直接返回
            _dictCurrentShowUIs.TryGetValue(uiName, out baseUI);
            if (baseUI == null)
            {
                _dictLoadedAllUIs.TryGetValue(uiName, out baseUI);
                if (baseUI == null)
                {
                    return;
                }
            }
            else
            {
                //隐藏窗口并从列表中移除
                _dictCurrentShowUIs.Remove(uiName);
            }

            baseUI.Close(isDestroy: isDestroy);

            //如果需要清空已有 popup 窗口
            if (baseUI.CurrentUIType.isClearPopUp)
            {
                ClearPopUpStackArray();
            }

            if (baseUI.CurrentUIType.uiNodeType == UINodeTypeEnum.PopUp)
            {
                //正在显示的窗口和栈缓存的窗口再次进行显示处理
                //判断栈里是否有窗口,有则冻结响应
                if (_stackCurrentUI.Count > 0)
                {
                    BaseUI topUI = _stackCurrentUI.Peek();
                    if (!topUI.AssetsName.Equals(uiName))
                    {
                        topUI.OnEnabled(true);
                        if (!topUI.IsShowing)
                        {
                            topUI.OnShow();
                        }
                        topUI.CheckMask();
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 加载当前窗体到当前窗体集合
        /// </summary>
        /// <param name="uiName"></param>
        private void LoadParallelUI(string uiName)
        {
            BaseUI baseUI;

            //判断栈里是否有窗口,有则冻结响应
            if (_stackCurrentUI.Count > 0)
            {
                BaseUI topUI = _stackCurrentUI.Peek();
                if (!topUI.AssetsName.Equals(uiName))
                {
                    topUI.OnDisabled(true);
                }
            }

            _dictCurrentShowUIs.TryGetValue(uiName, out baseUI);
            if (baseUI != null)
            {
                if (baseUI.IsShowing)
                {
                    baseUI.OnShow();
                }
                else
                {
                    if (baseUI.IsInitOver)
                    {
                        baseUI.OnEnabled(false);
                    }
                    baseUI.Show();
                }

                return;
            }

            //加载当前窗体到当前显示集合
            _dictLoadedAllUIs.TryGetValue(uiName, out baseUI);
            if (baseUI != null)
            {
                _dictCurrentShowUIs.Add(uiName, baseUI);
                if (baseUI.IsInitOver)
                {
                    baseUI.OnEnabled(false);
                }
                baseUI.Show();
            }
        }
Пример #3
0
        public void Uninstall()
        {
            while (_stackCurrentUI.Count > 0)
            {
                BaseUI ui = _stackCurrentUI.Pop();
                ui.Close(true);
            }

            if (_dictLoadedAllUIs != null)
            {
                var list = _dictLoadedAllUIs.ToList();
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    Close(list[i].Key, true);
                }
                list = null;
            }
            _allRegisterUIDict.Clear();
            _stackCurrentUI.Clear();
            _dictCurrentShowUIs.Clear();

            TransFixed  = null;
            TransPopUp  = null;
            TransRoot   = null;
            TransNormal = null;
            TransGlobal = null;

            RectransGlobal = null;
            RectransFixed  = null;
            RectransNormal = null;
            RectransPopUp  = null;
            RectransRoot   = null;

            _stackCurrentUI     = null;
            _allRegisterUIDict  = null;
            _dictLoadedAllUIs   = null;
            _dictCurrentShowUIs = null;

            DelHideCallBack  = null;
            LoadResourceFunc = null;

            Resources.UnloadUnusedAssets();
        }
Пример #4
0
        /// <summary>
        /// 弹出窗口,出栈
        /// </summary>
        /// <param name="uiName"></param>
        private void UnLoadStackUI(string uiName, bool isDestroy = false)
        {
            //有两个以上弹窗出现时
            if (_stackCurrentUI.Count >= 2)
            {
                //第一个出栈
                BaseUI topUI = _stackCurrentUI.Pop();
                topUI.Close(isDestroy: isDestroy);

                //第二个重新显示
                BaseUI nextUI = _stackCurrentUI.Peek();
                nextUI.Show(true);
            }
            //当前只有一个弹窗
            else if (_stackCurrentUI.Count == 1)
            {
                //出栈的窗体进行隐藏
                BaseUI topUI = _stackCurrentUI.Pop();
                topUI.Close(isDestroy: isDestroy);
            }
        }
Пример #5
0
        /// <summary>
        /// 弹出窗口,入栈
        /// 先冻结栈中窗口,再将此窗口入栈
        /// </summary>
        /// <param name="uiName"></param>
        private void LoadStackUI(string uiName)
        {
            BaseUI baseUI;

            //判断栈里是否有窗口,有则冻结响应
            if (_stackCurrentUI.Count > 0)
            {
                BaseUI topUI = _stackCurrentUI.Peek();
                if (!topUI.AssetsName.Equals(uiName))
                {
                    topUI.Close(freeze: true);
                }
            }

            //获取当前UI,进行展示处理
            _dictLoadedAllUIs.TryGetValue(uiName, out baseUI);
            if (baseUI != null)
            {
                if (baseUI.IsShowing)
                {
                    baseUI.OnShow();
                }
                else
                {
                    if (baseUI.IsInitOver)
                    {
                        baseUI.OnEnabled(false);
                    }
                    baseUI.Show();
                }

                if (!_stackCurrentUI.Contains(baseUI))
                {
                    //该弹出UI入栈
                    _stackCurrentUI.Push(baseUI);
                }
                else
                //对于栈内存在,则将其提升至栈顶
                {
                    while (_stackCurrentUI.Count > 0)
                    {
                        var ui = _stackCurrentUI.Pop();
                        if (ui != baseUI)
                        {
                            _backStack.Push(ui);
                        }
                    }

                    while (_backStack.Count > 0)
                    {
                        _stackCurrentUI.Push(_backStack.Pop());
                    }

                    _stackCurrentUI.Push(baseUI);
                }
            }
            else
            {
                throw new Exception("UIManager catch an error");
            }
        }
Пример #6
0
        /// <summary>
        /// 加载指定名称UI
        /// 功能:
        /// 1、根据名称加载预制体
        /// 2、根据UI类型加载到不同节点下
        /// 3、隐藏创建的UI克隆体
        /// 4、把克隆体加入到所有窗体列表
        /// </summary>
        /// <param name="uiName">窗体名称</param>
        /// <returns></returns>
        private BaseUI LoadUI(string uiName)
        {
            //加载的UI预制体
            BaseUI     baseUI    = null;
            GameObject prefClone = null;

            //加载预制体
            if (!string.IsNullOrEmpty(uiName))
            {
                prefClone = LoadResourceFunc != null?LoadResourceFunc(uiName) : null;
            }
            if (prefClone == null)
            {
                throw new Exception("未指定UI预制件加载方法或UI预制件路径指定错误 ==>" + uiName);
            }
            prefClone = GameObject.Instantiate(prefClone);

            //设置父节点
            if (TransRoot != null && prefClone != null)
            {
                if (_allRegisterUIDict.ContainsKey(uiName))
                {
                    //获取Unity编辑器程序集
                    var assembly = Assembly.Load("Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
                    if (FrameworkConfig.Instance.scriptEnvironment == RunEnvironment.DotNet || uiName.IndexOf("Canvas_Loading") != -1)
                    {
                        LDebug.Log(">>>>>UI Load Search Assembly " + assembly.FullName + "  :  " + _allRegisterUIDict[uiName]);
                        baseUI = ( BaseUI )assembly.CreateInstance(_allRegisterUIDict[uiName], true);
                    }
                    else if (FrameworkConfig.Instance.scriptEnvironment == RunEnvironment.ILRuntime)
                    {
                        //获取热更工程程序集
                        //借由反射现成方法,调取生成ILR内部实例,并返回结果
                        LDebug.Log(">>>> RunEnvironment.ILRuntime " + assembly.FullName);
                        var ssstype = assembly.GetType("Assets.Scripts.ILRScriptCall");
                        baseUI = ssstype.GetMethod("GetUITypeByThis").Invoke(null, new object[1] {
                            _allRegisterUIDict[uiName]
                        }) as BaseUI;
                    }
                    //========================//
                    //baseUI = Activator.CreateInstance( Type.GetType( _allRegisterUIDict[ uiName ], true, true ) ) as BaseUI;
                    baseUI.GameObjectInstance = prefClone;
                    baseUI.AssetsName         = uiName;
                    baseUI.IsInitOver         = true;
                    //========================//
                }

                if (baseUI == null)
                {
                    LDebug.LogError(uiName + "UI 脚本加载失败"); return(null);
                }

                baseUI.OnAwake();

                switch (baseUI.CurrentUIType.uiNodeType)
                {
                case UINodeTypeEnum.Normal:
                    prefClone.transform.SetParent(TransNormal, false);
                    break;

                case UINodeTypeEnum.Fixed:
                    prefClone.transform.SetParent(TransFixed, false);
                    break;

                case UINodeTypeEnum.PopUp:
                    prefClone.transform.SetParent(TransPopUp, false);
                    break;

                case UINodeTypeEnum.Global:
                    prefClone.transform.SetParent(TransGlobal, false);
                    break;

                default:
                    throw new Exception("未登记的UI类型--" + baseUI.CurrentUIType.uiShowMode);
                }

                baseUI.OnAdapter();

                //加入到所有窗体缓存中
                _dictLoadedAllUIs.Add(uiName, baseUI);
                return(baseUI);
            }
            return(null);
        }
Пример #7
0
        /// <summary>
        /// 显示(打开)UI窗口
        /// 功能:
        /// 1、根据UI窗体的名称,加载到UI窗口缓存列表
        /// 2、根据不同UI显示模式,做不同的加载处理
        /// </summary>
        /// <param name="uiName">UI窗体预制件名称</param>
        public IBaseUI Show(string uiName)
        {
            BaseUI baseUI = null;

            if (string.IsNullOrEmpty(uiName))
            {
                throw new Exception("UI--uiName 为 Null");
            }

            //根据名称加载窗体到UI窗体缓存中
            baseUI = LoadUIToAndFromAllList(uiName);
            if (baseUI == null)
            {
                throw new Exception("UI--baseUI 加载失败");
            }

            var    modelType    = UIModelBehavior.Instance.GetBehavior(uiName);
            UIType targetUIType = modelType != null ? modelType : baseUI.CurrentUIType;

            //判断是否清空“栈”结构体集合
            if (targetUIType.isClearPopUp)
            {
                ClearPopUpStackArray();
            }

            //只针对pop up 类型窗口适用 uiShowMode 功能
            if (targetUIType.uiNodeType == UINodeTypeEnum.PopUp)
            {
                switch (targetUIType.uiShowMode)
                {
                case UIShowModeEnum.Parallel:
                    LoadParallelUI(uiName);
                    break;

                case UIShowModeEnum.Stack:
                    LoadStackUI(uiName);
                    break;

                case UIShowModeEnum.Unique:
                    LoadUniqueUI(uiName);
                    break;

                default:
                    throw new Exception("未登记的UI类型--" + targetUIType.uiShowMode);
                }
            }
            else
            {
                //获取当前UI,进行展示处理
                _dictLoadedAllUIs.TryGetValue(uiName, out baseUI);
                if (baseUI != null)
                {
                    if (baseUI.IsShowing)
                    {
                        baseUI.OnShow();
                    }
                    else
                    {
                        if (baseUI.IsInitOver)
                        {
                            baseUI.OnEnabled(false);
                        }
                        baseUI.Show();
                    }
                }
            }
            return(baseUI);
        }