/// <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; } } }
/// <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; } } }
/// <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; } } }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// 终结助手 /// </summary> public void OnTermination() { _defineUIAndEntitys.Clear(); foreach (var ui in OverlayUIs) { UILogicBase uiLogic = ui.Value; if (!uiLogic.IsCreated) { continue; } uiLogic.OnDestroy(); Main.Kill(uiLogic.UIEntity); uiLogic.UIEntity = null; } OverlayUIs.Clear(); foreach (var ui in CameraUIs) { UILogicBase uiLogic = ui.Value; if (!uiLogic.IsCreated) { continue; } uiLogic.OnDestroy(); Main.Kill(uiLogic.UIEntity); uiLogic.UIEntity = null; } CameraUIs.Clear(); foreach (var ui in WorldUIs) { ui.Value.OnTermination(); } WorldUIs.Clear(); }
/// <summary> /// 终结助手 /// </summary> public void OnTermination() { _defineUIAndEntitys.Clear(); foreach (var ui in OverlayUIs) { DestroyUIEntity(ui.Value); } OverlayUIs.Clear(); foreach (var ui in CameraUIs) { DestroyUIEntity(ui.Value); } CameraUIs.Clear(); foreach (var ui in WorldUIs) { ui.Value.OnTermination(); } WorldUIs.Clear(); }
public UILogicBase GetOpenedUI() { return(OverlayUIs.Where(x => x.Value.IsOpened && (x.Value is UILogicResident)).FirstOrDefault().Value); }
/// <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); }
/// <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 标记!"); } } }
/// <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; } } }
/// <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); }