Beispiel #1
0
        /// <summary>
        /// 销毁UI
        /// </summary>
        public void DestroyUI <T>() where T : UILogic
        {
            if (_UIs.ContainsKey(typeof(T)))
            {
                UILogic ui = _UIs[typeof(T)];

                if (!ui.IsCreated)
                {
                    return;
                }

                if (ui.IsOpened)
                {
                    return;
                }

                ui.OnDestroy();
                Destroy(ui.UIEntity);
                ui.UIEntity = null;
            }
            else
            {
                GlobalTools.LogError("销毁UI失败:UI对象 " + typeof(T).Name + " 并未存在!");
            }
        }
Beispiel #2
0
            /// <summary>
            /// 销毁UI
            /// </summary>
            /// <param name="type">UI逻辑类</param>
            public void DestroyUI(Type type)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogic ui = _worldUIs[type];

                    if (!ui.IsCreated)
                    {
                        return;
                    }

                    if (ui.IsOpened)
                    {
                        return;
                    }

                    ui.OnDestroy();
                    Destroy(ui.UIEntity);
                    ui.UIEntity = null;
                }
                else
                {
                    GlobalTools.LogError(string.Format("销毁UI失败:UI对象 {0} 并未存在!", type.Name));
                }
            }
Beispiel #3
0
        /// <summary>
        /// 预加载非常驻UI
        /// </summary>
        public void PreloadingTemporaryUI <T>() where T : UILogicTemporary
        {
            if (_UIs.ContainsKey(typeof(T)))
            {
                UILogic ui = _UIs[typeof(T)];

                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.OnInit();
                    }, true);
                }
            }
            else
            {
                GlobalTools.LogError("预加载UI失败:UI对象 " + typeof(T).Name + " 并未存在!");
            }
        }
Beispiel #4
0
            /// <summary>
            /// 销毁域
            /// </summary>
            public void Termination()
            {
                foreach (KeyValuePair <Type, UILogic> ui in _worldUIs)
                {
                    UILogic uiLogic = ui.Value;

                    if (!uiLogic.IsCreated)
                    {
                        return;
                    }

                    uiLogic.OnDestroy();
                    Destroy(uiLogic.UIEntity);
                    uiLogic.UIEntity = null;
                }
                _worldUIs.Clear();

                Destroy(_worldUIRoot.gameObject);
            }
Beispiel #5
0
        public override void Termination()
        {
            base.Termination();

            foreach (KeyValuePair <Type, UILogic> ui in _UIs)
            {
                UILogic uiLogic = ui.Value;

                if (!uiLogic.IsCreated)
                {
                    return;
                }

                uiLogic.OnDestroy();
                Destroy(uiLogic.UIEntity);
                uiLogic.UIEntity = null;
            }
            _UIs.Clear();
        }
Beispiel #6
0
            /// <summary>
            /// 预加载非常驻UI
            /// </summary>
            /// <param name="type">非常驻UI逻辑类</param>
            public void PreloadingTemporaryUI(Type type)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogic ui = _worldUIs[type];

                    if (!ui.IsCreated)
                    {
                        Main.m_Resource.LoadPrefab(new PrefabInfo(type.GetCustomAttribute <UIResourceAttribute>()), _worldTemporaryPanel, null, (obj) =>
                        {
                            ui.UIEntity = obj;
                            ui.OnInit();
                        }, true);
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name));
                }
            }
Beispiel #7
0
            /// <summary>
            /// 获取已经打开的UI
            /// </summary>
            /// <param name="type">UI逻辑类</param>
            /// <returns>UI逻辑对象</returns>
            public UILogic GetOpenedUI(Type type)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogic ui = _worldUIs[type];

                    if (ui.IsOpened)
                    {
                        return(ui);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("获取UI失败:UI对象 {0} 并未存在,或并未打开!", type.Name));
                    return(null);
                }
            }
Beispiel #8
0
            /// <summary>
            /// 预加载常驻UI
            /// </summary>
            /// <param name="type">常驻UI逻辑类</param>
            public void PreloadingResidentUI(Type type)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogic ui = _worldUIs[type];

                    if (!ui.IsCreated)
                    {
                        Main.m_Resource.LoadPrefab(new PrefabInfo(type.GetCustomAttribute <UIResourceAttribute>()), _worldResidentPanel, null, (obj) =>
                        {
                            ui.UIEntity = obj;
                            ui.UIEntity.SetLayerIncludeChildren(_worldUIRoot.gameObject.layer);
                            ui.OnInit();
                        }, true);
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name));
                }
            }
Beispiel #9
0
        /// <summary>
        /// 获取已经打开的UI
        /// </summary>
        public T GetOpenedUI <T>() where T : UILogic
        {
            if (_UIs.ContainsKey(typeof(T)))
            {
                UILogic ui = _UIs[typeof(T)];

                if (ui.IsOpened)
                {
                    return(ui as T);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                GlobalTools.LogError("获取UI失败:UI对象 " + typeof(T).Name + " 并未存在!");
                return(null);
            }
        }
Beispiel #10
0
        public override void OnTermination()
        {
            base.OnTermination();

            foreach (KeyValuePair <Type, UILogic> ui in _overlayUIs)
            {
                UILogic uiLogic = ui.Value;

                if (!uiLogic.IsCreated)
                {
                    return;
                }

                uiLogic.OnDestroy();
                Destroy(uiLogic.UIEntity);
                uiLogic.UIEntity = null;
            }
            _overlayUIs.Clear();

            foreach (KeyValuePair <Type, UILogic> ui in _cameraUIs)
            {
                UILogic uiLogic = ui.Value;

                if (!uiLogic.IsCreated)
                {
                    return;
                }

                uiLogic.OnDestroy();
                Destroy(uiLogic.UIEntity);
                uiLogic.UIEntity = null;
            }
            _cameraUIs.Clear();

            foreach (KeyValuePair <string, WorldUIDomain> ui in _worldUIs)
            {
                ui.Value.Termination();
            }
            _worldUIs.Clear();
        }
Beispiel #11
0
            /// <summary>
            /// 关闭UI
            /// </summary>
            /// <param name="type">UI逻辑类</param>
            public void CloseUI(Type type)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogic ui = _worldUIs[type];

                    if (!ui.IsCreated)
                    {
                        return;
                    }

                    if (!ui.IsOpened)
                    {
                        return;
                    }

                    ui.UIEntity.SetActive(false);
                    ui.OnClose();
                }
                else
                {
                    GlobalTools.LogError(string.Format("关闭UI失败:UI对象 {0} 并未存在!", type.Name));
                }
            }
Beispiel #12
0
        /// <summary>
        /// 关闭UI
        /// </summary>
        public void CloseUI <T>() where T : UILogic
        {
            if (_UIs.ContainsKey(typeof(T)))
            {
                UILogic ui = _UIs[typeof(T)];

                if (!ui.IsCreated)
                {
                    return;
                }

                if (!ui.IsOpened)
                {
                    return;
                }

                ui.UIEntity.SetActive(false);
                ui.OnClose();
            }
            else
            {
                GlobalTools.LogError("关闭UI失败:UI对象 " + typeof(T).Name + " 并未存在!");
            }
        }
Beispiel #13
0
        /// <summary>
        /// 销毁UI
        /// </summary>
        /// <param name="type">UI逻辑类</param>
        public void DestroyUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

                        if (!ui.IsCreated)
                        {
                            return;
                        }

                        if (ui.IsOpened)
                        {
                            return;
                        }

                        ui.OnDestroy();
                        Destroy(ui.UIEntity);
                        ui.UIEntity = null;
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("销毁UI失败:UI对象 {0} 并未存在!", type.Name));
                    }
                    break;

                case UIType.Camera:
                    if (_cameraUIs.ContainsKey(type))
                    {
                        UILogic ui = _cameraUIs[type];

                        if (!ui.IsCreated)
                        {
                            return;
                        }

                        if (ui.IsOpened)
                        {
                            return;
                        }

                        ui.OnDestroy();
                        Destroy(ui.UIEntity);
                        ui.UIEntity = null;
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("销毁UI失败:UI对象 {0} 并未存在!", type.Name));
                    }
                    break;

                case UIType.World:
                    if (_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        _worldUIs[attribute.WorldUIDomainName].DestroyUI(type);
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("销毁UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                    }
                    break;
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// 获取已经打开的UI
        /// </summary>
        /// <param name="type">UI逻辑类</param>
        /// <returns>UI逻辑对象</returns>
        public UILogic GetOpenedUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

                        if (ui.IsOpened)
                        {
                            return(ui);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("获取UI失败:UI对象 {0} 并未存在,或并未打开!", type.Name));
                        return(null);
                    }

                case UIType.Camera:
                    if (_cameraUIs.ContainsKey(type))
                    {
                        UILogic ui = _cameraUIs[type];

                        if (ui.IsOpened)
                        {
                            return(ui);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("获取UI失败:UI对象 {0} 并未存在,或并未打开!", type.Name));
                        return(null);
                    }

                case UIType.World:
                    if (_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(_worldUIs[attribute.WorldUIDomainName].GetOpenedUI(type));
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("获取UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                        return(null);
                    }
                }
                return(null);
            }
            return(null);
        }
Beispiel #15
0
        /// <summary>
        /// 预加载非常驻UI
        /// </summary>
        /// <param name="type">非常驻UI逻辑类</param>
        public void PreloadingTemporaryUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

                        if (!ui.IsCreated)
                        {
                            Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _overlayTemporaryPanel, null, (obj) =>
                            {
                                ui.UIEntity = obj;
                                ui.OnInit();
                            }, true);
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name));
                    }
                    break;

                case UIType.Camera:
                    if (_cameraUIs.ContainsKey(type))
                    {
                        UILogic ui = _cameraUIs[type];

                        if (!ui.IsCreated)
                        {
                            Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _cameraTemporaryPanel, null, (obj) =>
                            {
                                ui.UIEntity = obj;
                                ui.OnInit();
                            }, true);
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name));
                    }
                    break;

                case UIType.World:
                    if (_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        _worldUIs[attribute.WorldUIDomainName].PreloadingTemporaryUI(type);
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                    }
                    break;
                }
            }
        }