/// <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)); } }
/// <summary> /// 预加载非常驻UI /// </summary> /// <param name="type">非常驻UI逻辑类</param> /// <param name="entity">UI实体</param> /// <returns>加载协程</returns> public Coroutine PreloadingTemporaryUI(Type type, GameObject entity) { if (_worldUIs.ContainsKey(type)) { UILogicBase ui = _worldUIs[type]; if (!ui.IsCreated) { if (entity != null) { ui.UIEntity = Instantiate(entity, _worldTemporaryPanel); ui.UIEntity.SetLayerIncludeChildren(_worldUIRoot.gameObject.layer); ui.OnInit(); 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.OnInit(); }, true)); } } } else { throw new HTFrameworkException(HTFrameworkModule.UI, "预加载UI失败:UI对象 " + type.Name + " 并未存在!"); } return(null); }
/// <summary> /// 预加载常驻UI /// </summary> /// <param name="type">常驻UI逻辑类</param> /// <param name="entity">UI实体</param> /// <returns>加载协程</returns> public Coroutine PreloadingResidentUI(Type type, GameObject entity) { if (_worldUIs.ContainsKey(type)) { UILogicBase ui = _worldUIs[type]; if (ui.IsCreated) { return(null); } if (entity != null) { ui.UIEntity = Main.Clone(entity, _worldResidentPanel); ui.UIEntity.SetLayerIncludeChildren(_worldUIRoot.gameObject.layer); ui.OnInit(); return(null); } else { return(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 { throw new HTFrameworkException(HTFrameworkModule.UI, string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name)); } }
/// <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)); } }
/// <summary> /// 预加载非常驻UI /// </summary> /// <param name="type">非常驻UI逻辑类</param> /// <returns>加载协程</returns> public Coroutine PreloadingTemporaryUI(Type type) { if (_worldUIs.ContainsKey(type)) { UILogicBase ui = _worldUIs[type]; 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.OnInit(); }, true)); } } else { GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name)); } return(null); }
/// <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(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)) { UILogicBase ui = _cameraUIs[type]; if (!ui.IsCreated) { return(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)) { return(_worldUIs[attribute.WorldUIDomainName].PreloadingTemporaryUI(type)); } else { GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName)); } break; } } return(null); }