private void LoadMainUI() { int menuId = MenuType.MainUI; MenuConfig config = configSet [menuId]; assetManager.Load(config.path, (string path, System.Object o) => { UnityEngine.Object obj = o as UnityEngine.Object; GameObject go = GameObject.Instantiate(obj) as GameObject; go.name = config.prefabName; go.transform.SetParent(GetRoot(MenuLayerType.Layer_MainUI), false); RectTransform rectTransform = go.transform as RectTransform; rectTransform.localScale = Vector3.one; if (config.layoutType == LayoutType.PositionZero) { rectTransform.anchoredPosition = Vector2.zero; } else { rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; } IModule module = go.GetComponent <IModule>(); module.MenuId = menuId; mainUiModule = module; SetMenuUI(setLasetMainUIMenuId); }); }
/// <summary> /// 关闭窗口 /// </summary> /// /// <param name="win"> 窗口实体 </param> /// <param name="isInitiativeClose"> 是否是主动关闭(是否是主动关闭 true:主动,false:被迫) </param> /// <returns></returns> private void CloseWindow(IModule module, bool isInitiativeClose, bool forcedDestroy = false) { MenuConfig config = configSet [module.MenuId]; //Debug.Log("MenuManager.CloseWindow config.name="+config.name+ " config.showIndex=" + config.showIndex+ " config.showType=" + config.showType + " module=" + module + " module.MenuId=" + module.MenuId + " isInitiativeClose=" + isInitiativeClose + " activeFullScreenWindowCount=" + activeFullScreenWindowCount); if (config.showType == ShowType.Screen && module.IsActive) { activeFullScreenWindowCount--; //Debug.Log("MenuManager.CloseWindow config.name="+config.name+ " activeFullScreenWindowCount="+activeFullScreenWindowCount); if (activeFullScreenWindowCount < 0) { Debug.Log("<color=red>MenuManager.CloseWindow config.name=" + config.name + " activeFullScreenWindowCount=" + activeFullScreenWindowCount + "</color>"); } } if (config.isDestroy || forcedDestroy) { modules.Remove(module.MenuId); } if (isInitiativeClose) { if (config.targetMenuId > 0) { MenuChangeVO menuVO = new MenuChangeVO(); menuVO.menuId = config.targetMenuId; menuVO.isToOpen = true; menuVO.isCloseOthers = false; CheckMenuVO(menuVO); } else { } } //TODO blurbg if (config.showBlurBG) { if (blurBG != null) { blurBG.OnCloseMenu(config); } } if (config.isPushMenuId) { if (openedMenuIds.IndexOf(config.menuId) != -1) { openedMenuIds.Remove(config.menuId); } } if (config.showType == ShowType.Screen) { CheckMainUI(); } RemoveWindow(module, isInitiativeClose, forcedDestroy); }
private void OpenWindow(MenuChangeVO vo, IModule module) { MenuConfig config = configSet [vo.menuId]; //Debug.Log("MenuManager.OpenWindow config.name="+config.name+ " module=" + module + " module.MenuId=" + module.MenuId ); if (vo.isCloseOthers) { Queue <IModule> closeWinQueue = new Queue <IModule>(); if (config.showType == ShowType.Screen) { foreach (var item in modules) { if (!item.Value.IsActive) { continue; } MenuConfig itemConfig = configSet [item.Value.MenuId]; if (itemConfig != null && config.menuId != itemConfig.menuId) { closeWinQueue.Enqueue(item.Value); } } } else if (config.showType == ShowType.Popup) { foreach (var item in modules) { if (!item.Value.IsActive) { continue; } MenuConfig itemConfig = configSet [item.Value.MenuId]; if (itemConfig != null && config.menuId != itemConfig.menuId && config.showIndex == itemConfig.showIndex) { closeWinQueue.Enqueue(item.Value); } } } while (closeWinQueue.Count > 0) { CloseWindow(closeWinQueue.Dequeue(), false); } } if (modules.ContainsKey(vo.menuId)) { modules [vo.menuId] = module; } else { modules.Add(vo.menuId, module); } module.IsActive = true; module.rectTransform.SetParent(GetRoot(vo.isPreInstance ? MenuLayerType.Layer_PreInstance : config.layer), false); if (vo.isPreInstance) { module.rectTransform.SetAsFirstSibling(); } else { module.rectTransform.SetAsLastSibling(); } module.SetParameter(vo.parameter); if (!vo.isBackState) { if (!vo.isPreInstance) { module.Enter(); } } else { vo.isBackState = false; module.OnBack(); } if (config.showType == ShowType.Screen) { activeFullScreenWindowCount++; //Debug.Log("MenuManager.OpenWindow config.name="+config.name+ " activeFullScreenWindowCount="+activeFullScreenWindowCount); } if (vo.isPreInstance) { DelayClose(vo); return; } CheckMainUI(config.menuId); //TODO blurbg if (config.showBlurBG) { if (blurBG != null) { blurBG.OnOpenMenu(config); } } if (config.isPushMenuId) { if (openedMenuIds.IndexOf(config.menuId) != -1) { openedMenuIds.Remove(config.menuId); } openedMenuIds.Add(config.menuId); } }