示例#1
0
            /// <summary>
            /// 打开非常驻UI
            /// </summary>
            /// <param name="type">非常驻UI逻辑类</param>
            /// <param name="entity">UI实体</param>
            /// <param name="args">可选参数</param>
            /// <returns>加载协程</returns>
            public Coroutine OpenTemporaryUI(Type type, GameObject entity, params object[] args)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogicTemporary ui = _worldUIs[type] as UILogicTemporary;

                    if (ui.IsOpened)
                    {
                        return(null);
                    }

                    if (_currentWorldTemporaryUI != null && _currentWorldTemporaryUI.IsOpened)
                    {
                        _currentWorldTemporaryUI.UIEntity.SetActive(false);
                        _currentWorldTemporaryUI.OnClose();
                        _currentWorldTemporaryUI = null;
                    }

                    if (!ui.IsCreated)
                    {
                        if (entity != null)
                        {
                            ui.UIEntity = Instantiate(entity, _worldTemporaryPanel);
                            ui.UIEntity.SetLayerIncludeChildren(_worldUIRoot.gameObject.layer);
                            ui.UIEntity.transform.SetAsLastSibling();
                            ui.UIEntity.SetActive(true);
                            ui.OnInit();
                            ui.OnOpen(args);
                            _currentWorldTemporaryUI = ui;
                            return(null);
                        }
                        else
                        {
                            return(Main.m_Resource.LoadPrefab(new PrefabInfo(type.GetCustomAttribute <UIResourceAttribute>()), _worldTemporaryPanel, null, (obj) =>
                            {
                                ui.UIEntity = obj;
                                ui.UIEntity.SetLayerIncludeChildren(_worldUIRoot.gameObject.layer);
                                ui.UIEntity.transform.SetAsLastSibling();
                                ui.UIEntity.SetActive(true);
                                ui.OnInit();
                                ui.OnOpen(args);
                                _currentWorldTemporaryUI = ui;
                            }, true));
                        }
                    }
                    else
                    {
                        ui.UIEntity.transform.SetAsLastSibling();
                        ui.UIEntity.SetActive(true);
                        ui.OnOpen(args);
                        _currentWorldTemporaryUI = ui;
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.UI, "打开UI失败:UI对象 " + type.Name + " 并未存在!");
                }
                return(null);
            }
示例#2
0
        /// <summary>
        /// 打开非常驻UI
        /// </summary>
        public void OpenTemporaryUI <T>(params object[] args) where T : UILogicTemporary
        {
            if (_UIs.ContainsKey(typeof(T)))
            {
                UILogicTemporary ui = _UIs[typeof(T)] as UILogicTemporary;

                if (ui.IsOpened)
                {
                    return;
                }

                //关闭当前打开的非常驻UI
                if (_currentTemporaryUI != null && _currentTemporaryUI.IsOpened)
                {
                    _currentTemporaryUI.UIEntity.SetActive(false);
                    _currentTemporaryUI.OnClose();
                    _currentTemporaryUI = null;
                }

                if (!ui.IsCreated)
                {
                    object[] atts = typeof(T).GetCustomAttributes(typeof(UIResourceAttribute), false);
                    if (atts.Length != 1)
                    {
                        GlobalTools.LogError("打开UI失败:UI对象 " + typeof(T).Name + " 并未标记UIResourceAttribute特性!");
                        return;
                    }
                    Main.m_Resource.LoadPrefab(new PrefabInfo(atts[0] as UIResourceAttribute), _temporaryPanel, null, (obj) =>
                    {
                        ui.UIEntity = obj;
                        ui.UIEntity.transform.SetAsLastSibling();
                        ui.UIEntity.SetActive(true);
                        ui.OnInit();
                        ui.OnOpen(args);
                        _currentTemporaryUI = ui;
                    }, true);
                }
                else
                {
                    ui.UIEntity.transform.SetAsLastSibling();
                    ui.UIEntity.SetActive(true);
                    ui.OnOpen(args);
                    _currentTemporaryUI = ui;
                }
            }
            else
            {
                GlobalTools.LogError("打开UI失败:UI对象 " + typeof(T).Name + " 并未存在!");
            }
        }
示例#3
0
            /// <summary>
            /// 打开非常驻UI
            /// </summary>
            /// <param name="type">非常驻UI逻辑类</param>
            /// <param name="args">可选参数</param>
            /// <returns>加载协程</returns>
            public Coroutine OpenTemporaryUI(Type type, params object[] args)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogicTemporary ui = _worldUIs[type] as UILogicTemporary;

                    if (ui.IsOpened)
                    {
                        return(null);
                    }

                    if (_currentWorldTemporaryUI != null && _currentWorldTemporaryUI.IsOpened)
                    {
                        _currentWorldTemporaryUI.UIEntity.SetActive(false);
                        _currentWorldTemporaryUI.OnClose();
                        _currentWorldTemporaryUI = null;
                    }

                    if (!ui.IsCreated)
                    {
                        return(Main.m_Resource.LoadPrefab(new PrefabInfo(type.GetCustomAttribute <UIResourceAttribute>()), _worldTemporaryPanel, null, (obj) =>
                        {
                            ui.UIEntity = obj;
                            ui.UIEntity.SetLayerIncludeChildren(_worldUIRoot.gameObject.layer);
                            ui.UIEntity.transform.SetAsLastSibling();
                            ui.UIEntity.SetActive(true);
                            ui.OnInit();
                            ui.OnOpen(args);
                            _currentWorldTemporaryUI = ui;
                        }, true));
                    }
                    else
                    {
                        ui.UIEntity.transform.SetAsLastSibling();
                        ui.UIEntity.SetActive(true);
                        ui.OnOpen(args);
                        _currentWorldTemporaryUI = ui;
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name));
                }
                return(null);
            }
示例#4
0
        /// <summary>
        /// 打开非常驻UI
        /// </summary>
        /// <param name="type">非常驻UI逻辑类</param>
        /// <param name="args">可选参数</param>
        /// <returns>加载协程</returns>
        public Coroutine OpenTemporaryUI(Type type, params object[] args)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

            if (attribute != null)
            {
                switch (attribute.EntityType)
                {
                case UIType.Overlay:
                    if (OverlayUIs.ContainsKey(type))
                    {
                        UILogicTemporary ui = OverlayUIs[type] as UILogicTemporary;

                        if (ui.IsOpened)
                        {
                            return(null);
                        }

                        if (_currentOverlayTemporaryUI != null && _currentOverlayTemporaryUI.IsOpened)
                        {
                            if (IsLockTemporaryUI)
                            {
                                return(null);
                            }
                            _currentOverlayTemporaryUI.UIEntity.SetActive(false);
                            _currentOverlayTemporaryUI.OnClose();
                            _currentOverlayTemporaryUI = null;
                        }
                        _currentOverlayTemporaryUI = ui;

                        if (!ui.IsCreated)
                        {
                            return(CreateOpenUIEntity(attribute, type.FullName, ui, _overlayTemporaryPanel, args));
                        }
                        else
                        {
                            ui.UIEntity.transform.SetAsLastSibling();
                            ui.UIEntity.SetActive(true);
                            ui.OnOpen(args);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "打开UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

                case UIType.Camera:
                    if (CameraUIs.ContainsKey(type))
                    {
                        UILogicTemporary ui = CameraUIs[type] as UILogicTemporary;

                        if (ui.IsOpened)
                        {
                            return(null);
                        }

                        if (_currentCameraTemporaryUI != null && _currentCameraTemporaryUI.IsOpened)
                        {
                            if (IsLockTemporaryUI)
                            {
                                return(null);
                            }
                            _currentCameraTemporaryUI.UIEntity.SetActive(false);
                            _currentCameraTemporaryUI.OnClose();
                            _currentCameraTemporaryUI = null;
                        }
                        _currentCameraTemporaryUI = ui;

                        if (!ui.IsCreated)
                        {
                            return(CreateOpenUIEntity(attribute, type.FullName, ui, _cameraTemporaryPanel, args));
                        }
                        else
                        {
                            ui.UIEntity.transform.SetAsLastSibling();
                            ui.UIEntity.SetActive(true);
                            ui.OnOpen(args);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "打开UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(WorldUIs[attribute.WorldUIDomainName].OpenTemporaryUI(type, _defineUIAndEntitys.ContainsKey(type.FullName) ? _defineUIAndEntitys[type.FullName] : null, args));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "打开UI失败:UI对象 " + type.Name + " 的域 " + attribute.WorldUIDomainName + " 并未存在!");
                    }
                }
            }
            return(null);
        }