示例#1
0
 /// <summary>
 /// 创建并打开UI实体
 /// </summary>
 /// <param name="uIResource">UI资源标记</param>
 /// <param name="uITypeName">UI逻辑类型</param>
 /// <param name="uILogic">UI逻辑类对象</param>
 /// <param name="uIParent">UI的父级</param>
 /// <param name="args">UI打开的参数</param>
 /// <returns>加载协程</returns>
 private Coroutine CreateOpenUIEntity(UIResourceAttribute uIResource, string uITypeName, UILogicBase uILogic, Transform uIParent, params object[] args)
 {
     if (_defineUIAndEntitys.ContainsKey(uITypeName) && _defineUIAndEntitys[uITypeName] != null)
     {
         uILogic.UIEntity = Main.Clone(_defineUIAndEntitys[uITypeName], uIParent);
         uILogic.UIEntity.transform.SetAsLastSibling();
         uILogic.UIEntity.SetActive(true);
         uILogic.OnInit();
         uILogic.OnOpen(args);
         if (uILogic is UILogicResident)
         {
             uILogic.Cast <UILogicResident>().OnPlaceTop();
         }
         return(null);
     }
     else
     {
         return(Main.m_Resource.LoadPrefab(new PrefabInfo(uIResource), uIParent, null, (obj) =>
         {
             uILogic.UIEntity = obj;
             uILogic.UIEntity.transform.SetAsLastSibling();
             uILogic.UIEntity.SetActive(true);
             uILogic.OnInit();
             uILogic.OnOpen(args);
             if (uILogic is UILogicResident)
             {
                 uILogic.Cast <UILogicResident>().OnPlaceTop();
             }
         }, true));
     }
 }
示例#2
0
/// <summary>
        /// 置顶常驻UI
        /// </summary>
        /// <param name="type">常驻UI逻辑类</param>
        public void PlaceTopUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

            if (attribute != null)
            {
                switch (attribute.EntityType)
                {
                case UIType.Overlay:
                    if (OverlayUIs.ContainsKey(type))
                    {
                        PlaceTopUIEntity(OverlayUIs[type] as UILogicResident);
                    }
                    break;

                case UIType.Camera:
                    if (CameraUIs.ContainsKey(type))
                    {
                        PlaceTopUIEntity(CameraUIs[type] as UILogicResident);
                    }
                    break;

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        WorldUIs[attribute.WorldUIDomainName].PlaceTop(type);
                    }
                    break;
                }
            }
        }
示例#3
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))
                    {
                        DestroyUIEntity(OverlayUIs[type]);
                    }
                    break;

                case UIType.Camera:
                    if (CameraUIs.ContainsKey(type))
                    {
                        DestroyUIEntity(CameraUIs[type]);
                    }
                    break;

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        WorldUIs[attribute.WorldUIDomainName].DestroyUI(type);
                    }
                    break;
                }
            }
        }
示例#4
0
        /// <summary>
        /// 获取已经打开的UI
        /// </summary>
        /// <param name="type">UI逻辑类</param>
        /// <returns>UI逻辑对象</returns>
        public UILogicBase GetOpenedUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

                        if (ui.IsOpened)
                        {
                            return(ui);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "获取UI失败:UI对象 " + type.Name + " 并未存在,或并未打开!");
                    }

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

                        if (ui.IsOpened)
                        {
                            return(ui);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "获取UI失败:UI对象 " + type.Name + " 并未存在,或并未打开!");
                    }

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(WorldUIs[attribute.WorldUIDomainName].GetOpenedUI(type));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "获取UI失败:UI对象 " + type.Name + " 的域 " + attribute.WorldUIDomainName + " 并未存在!");
                    }
                }
            }
            return(null);
        }
示例#5
0
        /// <summary>
        /// 置顶常驻UI
        /// </summary>
        /// <param name="type">常驻UI逻辑类</param>
        public void PlaceTopUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

                        if (!ui.IsOpened)
                        {
                            return;
                        }

                        ui.UIEntity.transform.SetAsLastSibling();
                        ui.OnPlaceTop();
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "置顶UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

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

                        if (!ui.IsOpened)
                        {
                            return;
                        }

                        ui.UIEntity.transform.SetAsLastSibling();
                        ui.OnPlaceTop();
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "置顶UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        WorldUIs[attribute.WorldUIDomainName].PlaceTop(type);
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "置顶UI失败:UI对象 " + type.Name + " 的域 " + attribute.WorldUIDomainName + " 并未存在!");
                    }
                    break;
                }
            }
        }
示例#6
0
        /// <summary>
        /// 获取已经打开的UI
        /// </summary>
        /// <param name="type">UI逻辑类</param>
        /// <returns>UI逻辑对象</returns>
        public UILogicBase GetOpenedUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

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

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

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

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(WorldUIs[attribute.WorldUIDomainName].GetOpenedUI(type));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }
示例#7
0
        /// <summary>
        /// 置顶常驻UI
        /// </summary>
        /// <param name="type">常驻UI逻辑类</param>
        public void PlaceTop(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

                        if (!ui.IsOpened)
                        {
                            return;
                        }

                        ui.UIEntity.transform.SetAsLastSibling();
                        ui.OnPlaceTop();
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("置顶UI失败:UI对象 {0} 并未存在!", type.Name));
                    }
                    break;

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

                        if (!ui.IsOpened)
                        {
                            return;
                        }

                        ui.UIEntity.transform.SetAsLastSibling();
                        ui.OnPlaceTop();
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("置顶UI失败:UI对象 {0} 并未存在!", type.Name));
                    }
                    break;

                case UIType.World:
                    if (_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        _worldUIs[attribute.WorldUIDomainName].PlaceTop(type);
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("置顶UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                    }
                    break;
                }
            }
        }
示例#8
0
        /// <summary>
        /// 预加载非常驻UI
        /// </summary>
        /// <param name="type">非常驻UI逻辑类</param>
        /// <returns>加载协程</returns>
        public Coroutine PreloadingTemporaryUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

                        if (!ui.IsCreated)
                        {
                            return(CreateUIEntity(attribute, type.FullName, ui, _overlayTemporaryPanel));
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "预加载UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

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

                        if (!ui.IsCreated)
                        {
                            return(CreateUIEntity(attribute, type.FullName, ui, _cameraTemporaryPanel));
                        }
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "预加载UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(WorldUIs[attribute.WorldUIDomainName].PreloadingTemporaryUI(type, _defineUIAndEntitys.ContainsKey(type.FullName) ? _defineUIAndEntitys[type.FullName] : null));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "预加载UI失败:UI对象 " + type.Name + " 的域 " + attribute.WorldUIDomainName + " 并未存在!");
                    }
                }
            }
            return(null);
        }
示例#9
0
 /// <summary>
 /// 创建UI实体
 /// </summary>
 /// <param name="uIResource">UI资源标记</param>
 /// <param name="uITypeName">UI逻辑类型</param>
 /// <param name="uILogic">UI逻辑类对象</param>
 /// <param name="uIParent">UI的父级</param>
 /// <returns>加载协程</returns>
 private Coroutine CreateUIEntity(UIResourceAttribute uIResource, string uITypeName, UILogicBase uILogic, Transform uIParent)
 {
     if (_defineUIAndEntitys.ContainsKey(uITypeName) && _defineUIAndEntitys[uITypeName] != null)
     {
         uILogic.UIEntity = Main.Clone(_defineUIAndEntitys[uITypeName], uIParent);
         uILogic.UIEntity.SetActive(false);
         uILogic.OnInit();
         return(null);
     }
     else
     {
         return(Main.m_Resource.LoadPrefab(new PrefabInfo(uIResource), uIParent, null, (obj) =>
         {
             uILogic.UIEntity = obj;
             uILogic.OnInit();
         }, true));
     }
 }
示例#10
0
        /// <summary>
        /// 打开常驻UI
        /// </summary>
        /// <param name="type">常驻UI逻辑类</param>
        /// <param name="args">可选参数</param>
        /// <returns>加载协程</returns>
        public Coroutine OpenResidentUI(Type type, params object[] args)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

            if (attribute != null)
            {
                switch (attribute.EntityType)
                {
                case UIType.Overlay:
                    if (OverlayUIs.ContainsKey(type))
                    {
                        return(CreateOpenUIEntity(attribute, type.FullName, OverlayUIs[type], _overlayResidentPanel, args));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name));
                    }

                case UIType.Camera:
                    if (CameraUIs.ContainsKey(type))
                    {
                        return(CreateOpenUIEntity(attribute, type.FullName, CameraUIs[type], _cameraResidentPanel, args));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name));
                    }

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(WorldUIs[attribute.WorldUIDomainName].OpenResidentUI(type, _defineUIAndEntitys.ContainsKey(type.FullName) ? _defineUIAndEntitys[type.FullName] : null, args));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("打开UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                    }
                }
            }
            return(null);
        }
示例#11
0
        /// <summary>
        /// 预加载非常驻UI
        /// </summary>
        /// <param name="type">非常驻UI逻辑类</param>
        /// <returns>加载协程</returns>
        public Coroutine PreloadingTemporaryUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

            if (attribute != null)
            {
                switch (attribute.EntityType)
                {
                case UIType.Overlay:
                    if (OverlayUIs.ContainsKey(type))
                    {
                        return(CreateUIEntity(attribute, type.FullName, OverlayUIs[type], _overlayTemporaryPanel));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name));
                    }

                case UIType.Camera:
                    if (CameraUIs.ContainsKey(type))
                    {
                        return(CreateUIEntity(attribute, type.FullName, CameraUIs[type], _cameraTemporaryPanel));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name));
                    }

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(WorldUIs[attribute.WorldUIDomainName].PreloadingTemporaryUI(type, _defineUIAndEntitys.ContainsKey(type.FullName) ? _defineUIAndEntitys[type.FullName] : null));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("预加载UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                    }
                }
            }
            return(null);
        }
示例#12
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))
                    {
                        UILogicBase ui = OverlayUIs[type];

                        if (!ui.IsCreated)
                        {
                            return;
                        }

                        if (ui.IsOpened)
                        {
                            return;
                        }

                        ui.OnDestroy();
                        Main.Kill(ui.UIEntity);
                        ui.UIEntity = null;
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "销毁UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

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

                        if (!ui.IsCreated)
                        {
                            return;
                        }

                        if (ui.IsOpened)
                        {
                            return;
                        }

                        ui.OnDestroy();
                        Main.Kill(ui.UIEntity);
                        ui.UIEntity = null;
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "销毁UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

                case UIType.World:
                    if (WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        WorldUIs[attribute.WorldUIDomainName].DestroyUI(type);
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "销毁UI失败:UI对象 " + type.Name + " 的域 " + attribute.WorldUIDomainName + " 并未存在!");
                    }
                    break;
                }
            }
        }
示例#13
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))
                    {
                        if (_currentOverlayTemporaryUI != null && _currentOverlayTemporaryUI.IsOpened)
                        {
                            if (IsLockTemporaryUI)
                            {
                                return(null);
                            }
                            if (!_navigataBackUI)
                            {
                                _temporaryUIStack.Add(_currentOverlayTemporaryUI);
                            }
                            CloseUIEntity(_currentOverlayTemporaryUI);
                            _currentOverlayTemporaryUI = null;
                        }
                        _currentOverlayTemporaryUI = OverlayUIs[type] as UILogicTemporary;

                        return(CreateOpenUIEntity(attribute, type.FullName, OverlayUIs[type], _overlayTemporaryPanel, args));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name));
                    }

                case UIType.Camera:
                    if (CameraUIs.ContainsKey(type))
                    {
                        if (_currentCameraTemporaryUI != null && _currentCameraTemporaryUI.IsOpened)
                        {
                            if (IsLockTemporaryUI)
                            {
                                return(null);
                            }

                            CloseUIEntity(_currentCameraTemporaryUI);
                            _currentCameraTemporaryUI = null;
                        }
                        _currentCameraTemporaryUI = CameraUIs[type] as UILogicTemporary;

                        return(CreateOpenUIEntity(attribute, type.FullName, CameraUIs[type], _cameraTemporaryPanel, args));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name));
                    }

                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, string.Format("打开UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                    }
                }
            }
            return(null);
        }
示例#14
0
        /// <summary>
        /// 初始化助手
        /// </summary>
        public void OnInitialization()
        {
            _module = Module as UIManager;

            for (int i = 0; i < _module.DefineUINames.Count; i++)
            {
                if (!_defineUIAndEntitys.ContainsKey(_module.DefineUINames[i]))
                {
                    _defineUIAndEntitys.Add(_module.DefineUINames[i], _module.DefineUIEntitys[i]);
                }
            }

            _UIEntity              = _module.transform.FindChildren("UIEntity");
            _overlayUIRoot         = _UIEntity.transform.Find("OverlayUIRoot");
            _overlayUIRootRect     = _overlayUIRoot.rectTransform();
            _overlayResidentPanel  = _overlayUIRoot.Find("ResidentPanel");
            _overlayTemporaryPanel = _overlayUIRoot.Find("TemporaryPanel");
            _cameraUIRoot          = _UIEntity.transform.Find("CameraUIRoot");
            _cameraUIRootRect      = _cameraUIRoot.rectTransform();
            _cameraResidentPanel   = _cameraUIRoot.Find("ResidentPanel");
            _cameraTemporaryPanel  = _cameraUIRoot.Find("TemporaryPanel");
            _worldUIRoot           = _UIEntity.transform.Find("WorldUIRoot");
            _maskPanel             = _overlayUIRoot.FindChildren("MaskPanel");
            UICamera = _UIEntity.GetComponentByChild <Camera>("UICamera");

            _overlayUIRoot.gameObject.SetActive(_module.IsEnableOverlayUI);
            _cameraUIRoot.gameObject.SetActive(_module.IsEnableCameraUI);
            UICamera.gameObject.SetActive(_module.IsEnableCameraUI);
            _worldUIRoot.gameObject.SetActive(_module.IsEnableWorldUI);

            //创建所有UI的逻辑对象
            List <Type> types = ReflectionToolkit.GetTypesInRunTimeAssemblies(type =>
            {
                return((type.IsSubclassOf(typeof(UILogicResident)) || type.IsSubclassOf(typeof(UILogicTemporary))) && !type.IsAbstract);
            });

            for (int i = 0; i < types.Count; i++)
            {
                UIResourceAttribute attribute = types[i].GetCustomAttribute <UIResourceAttribute>();
                if (attribute != null)
                {
                    switch (attribute.EntityType)
                    {
                    case UIType.Overlay:
                        if (_module.IsEnableOverlayUI)
                        {
                            OverlayUIs.Add(types[i], Activator.CreateInstance(types[i]) as UILogicBase);
                        }
                        break;

                    case UIType.Camera:
                        if (_module.IsEnableCameraUI)
                        {
                            CameraUIs.Add(types[i], Activator.CreateInstance(types[i]) as UILogicBase);
                        }
                        break;

                    case UIType.World:
                        if (_module.IsEnableWorldUI)
                        {
                            if (!WorldUIs.ContainsKey(attribute.WorldUIDomainName))
                            {
                                WorldUIs.Add(attribute.WorldUIDomainName, new UIWorldDomain(attribute.WorldUIDomainName, _worldUIRoot.FindChildren("CanvasTem")));
                            }
                            WorldUIs[attribute.WorldUIDomainName].Injection(types[i]);
                        }
                        break;
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.UI, "创建UI逻辑对象失败:UI逻辑类 " + types[i].Name + " 丢失 UIResourceAttribute 标记!");
                }
            }
        }
示例#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;
                }
            }
        }
示例#16
0
        /// <summary>
        /// 打开非常驻UI
        /// </summary>
        /// <param name="type">非常驻UI逻辑类</param>
        /// <param name="args">可选参数</param>
        public void 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;
                        }

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

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

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

                        if (ui.IsOpened)
                        {
                            return;
                        }

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

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

                case UIType.World:
                    if (_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        _worldUIs[attribute.WorldUIDomainName].OpenTemporaryUI(type, args);
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                    }
                    break;
                }
            }
        }
示例#17
0
        /// <summary>
        /// 关闭UI
        /// </summary>
        /// <param name="type">UI逻辑类</param>
        public void CloseUI(Type type)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

                        if (!ui.IsCreated)
                        {
                            return;
                        }

                        if (!ui.IsOpened)
                        {
                            return;
                        }

                        ui.UIEntity.SetActive(false);
                        ui.OnClose();
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "关闭UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

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

                        if (!ui.IsCreated)
                        {
                            return;
                        }

                        if (!ui.IsOpened)
                        {
                            return;
                        }

                        ui.UIEntity.SetActive(false);
                        ui.OnClose();
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "关闭UI失败:UI对象 " + type.Name + " 并未存在!");
                    }
                    break;

                case UIType.World:
                    if (_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        _worldUIs[attribute.WorldUIDomainName].CloseUI(type);
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "关闭UI失败:UI对象 " + type.Name + " 的域 " + attribute.WorldUIDomainName + " 并未存在!");
                    }
                    break;
                }
            }
        }
示例#18
0
        /// <summary>
        /// 打开常驻UI
        /// </summary>
        /// <param name="type">常驻UI逻辑类</param>
        /// <param name="args">可选参数</param>
        /// <returns>加载协程</returns>
        public Coroutine OpenResidentUI(Type type, params object[] args)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

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

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

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

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

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

                case UIType.World:
                    if (_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(_worldUIs[attribute.WorldUIDomainName].OpenResidentUI(type, _defineUIAndEntitys.ContainsKey(type.FullName) ? _defineUIAndEntitys[type.FullName] : null, args));
                    }
                    else
                    {
                        throw new HTFrameworkException(HTFrameworkModule.UI, "打开UI失败:UI对象 " + type.Name + " 的域 " + attribute.WorldUIDomainName + " 并未存在!");
                    }
                }
            }
            return(null);
        }
示例#19
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);
        }
示例#20
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;
                }
            }
        }
示例#21
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);
        }
示例#22
0
        /// <summary>
        /// 打开常驻UI
        /// </summary>
        /// <param name="type">常驻UI逻辑类</param>
        /// <param name="args">可选参数</param>
        /// <returns>加载协程</returns>
        public Coroutine OpenResidentUI(Type type, params object[] args)
        {
            UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>();

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

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

                        if (!ui.IsCreated)
                        {
                            return(Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _overlayResidentPanel, null, (obj) =>
                            {
                                ui.UIEntity = obj;
                                ui.UIEntity.transform.SetAsLastSibling();
                                ui.UIEntity.SetActive(true);
                                ui.OnInit();
                                ui.OnOpen(args);
                                ui.OnPlaceTop();
                            }, true));
                        }
                        else
                        {
                            ui.UIEntity.transform.SetAsLastSibling();
                            ui.UIEntity.SetActive(true);
                            ui.OnOpen(args);
                            ui.OnPlaceTop();
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name));
                    }
                    break;

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

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

                        if (!ui.IsCreated)
                        {
                            return(Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _cameraResidentPanel, null, (obj) =>
                            {
                                ui.UIEntity = obj;
                                ui.UIEntity.transform.SetAsLastSibling();
                                ui.UIEntity.SetActive(true);
                                ui.OnInit();
                                ui.OnOpen(args);
                                ui.OnPlaceTop();
                            }, true));
                        }
                        else
                        {
                            ui.UIEntity.transform.SetAsLastSibling();
                            ui.UIEntity.SetActive(true);
                            ui.OnOpen(args);
                            ui.OnPlaceTop();
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name));
                    }
                    break;

                case UIType.World:
                    if (_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                    {
                        return(_worldUIs[attribute.WorldUIDomainName].OpenResidentUI(type, args));
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName));
                    }
                    break;
                }
            }
            return(null);
        }
示例#23
0
        public override void OnInitialization()
        {
            base.OnInitialization();

            _UIEntity              = transform.FindChildren("UIEntity");
            _overlayUIRoot         = _UIEntity.transform.Find("OverlayUIRoot");
            _overlayUIRootRect     = _overlayUIRoot.rectTransform();
            _overlayResidentPanel  = _overlayUIRoot.Find("ResidentPanel");
            _overlayTemporaryPanel = _overlayUIRoot.Find("TemporaryPanel");
            _cameraUIRoot          = _UIEntity.transform.Find("CameraUIRoot");
            _cameraUIRootRect      = _cameraUIRoot.rectTransform();
            _cameraResidentPanel   = _cameraUIRoot.Find("ResidentPanel");
            _cameraTemporaryPanel  = _cameraUIRoot.Find("TemporaryPanel");
            _worldUIRoot           = _UIEntity.transform.Find("WorldUIRoot");
            UICamera = _UIEntity.GetComponentByChild <Camera>("UICamera");

            _overlayUIRoot.gameObject.SetActive(IsEnableOverlayUI);
            _cameraUIRoot.gameObject.SetActive(IsEnableCameraUI);
            UICamera.gameObject.SetActive(IsEnableCameraUI);
            _worldUIRoot.gameObject.SetActive(IsEnableWorldUI);

            //创建所有UI的逻辑对象
            List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies();

            for (int i = 0; i < types.Count; i++)
            {
                if (types[i].IsSubclassOf(typeof(UILogicResident)) || types[i].IsSubclassOf(typeof(UILogicTemporary)))
                {
                    UIResourceAttribute attribute = types[i].GetCustomAttribute <UIResourceAttribute>();
                    if (attribute != null)
                    {
                        switch (attribute.EntityType)
                        {
                        case UIType.Overlay:
                            if (IsEnableOverlayUI)
                            {
                                _overlayUIs.Add(types[i], Activator.CreateInstance(types[i]) as UILogic);
                            }
                            break;

                        case UIType.Camera:
                            if (IsEnableCameraUI)
                            {
                                _cameraUIs.Add(types[i], Activator.CreateInstance(types[i]) as UILogic);
                            }
                            break;

                        case UIType.World:
                            if (IsEnableWorldUI)
                            {
                                if (!_worldUIs.ContainsKey(attribute.WorldUIDomainName))
                                {
                                    _worldUIs.Add(attribute.WorldUIDomainName, new WorldUIDomain(attribute.WorldUIDomainName, _worldUIRoot.FindChildren("CanvasTem")));
                                }
                                _worldUIs[attribute.WorldUIDomainName].Injection(types[i]);
                            }
                            break;
                        }
                    }
                    else
                    {
                        GlobalTools.LogError(string.Format("创建UI逻辑对象失败:UI逻辑类 {0} 丢失 UIResourceAttribute 标记!", types[i].Name));
                    }
                }
            }
        }