/** 打开模块 */ public void OpenMenuBack(int menuId, int backId, object parameter, LoadType loadType) { MenuChangeVO vo = new MenuChangeVO(); vo.menuId = menuId; vo.loadType = loadType; vo.isToOpen = true; vo.parameter = parameter; vo.backId = backId; if (lastOpens.ContainsKey(vo.menuId)) { lastOpens[vo.menuId] = vo; } else { lastOpens.Add(vo.menuId, vo); } Debug.Log(string.Format("<color=yellow>OpenMenuBack menuId={0} backId={1}</color>", menuId, backId)); if (backs.ContainsKey(menuId)) { backs[menuId] = backId; } else { backs.Add(menuId, backId); } CheckMenuVO(vo); }
private void CloseMenu(MenuChangeVO vo) { MenuConfig config = configSet [vo.menuId]; if (config == null) { //Debug.Log(string.Format("<color=red>[MenuManager.CloseMenu(MenuVO vo)] 没有获取到配置 menuId={0} config=null</color>", vo.menuId)); return; } if (config.moduleType == ModuleType.Panel) { IModule module; if (modules.TryGetValue(vo.menuId, out module)) { CloseWindow(module, true); } } else if (config.moduleType == ModuleType.Scene) { if (Application.loadedLevelName != "Main") { OpenMenu(MenuType.MainScene); } } }
/** 关闭模块 */ public void CloseMenu(int menuId) { MenuChangeVO vo = new MenuChangeVO(); vo.menuId = menuId; vo.isToOpen = false; CheckMenuVO(vo); }
private void OpenMenu(MenuChangeVO vo) { MenuConfig config = configSet [vo.menuId]; if (config == null) { Debug.Log(string.Format("<color=red>[MenuManager.OpenMenu(MenuVO vo)] 没有获取到配置 menuId={0} config=null</color>", vo.menuId)); return; } if (config.moduleType == ModuleType.Panel) { if (vo.menuId != MenuType.Home && config.showType != ShowType.Screen) { // if (activeFullScreenWindowCount <= 0) // { // if(GameScene.IsMain()) // { // MenuChangeVO menuVO = null; // // if(!lastOpens.TryGetValue(MenuType.Home, out menuVO)) // { // menuVO = new MenuChangeVO(); // menuVO.menuId = MenuType.Home; // menuVO.isToOpen = true; // menuVO.isCloseOthers = false; // } // CheckMenuVO(menuVO); // } // } } IModule module; if (modules.TryGetValue(vo.menuId, out module)) { if (module.IsActive) { SetModuleParameter(config, vo, module); } else { OpenWindow(vo, module); } } else { loadManager.LoadPanel(vo.isPreInstance, vo.loadType == LoadType.None ? config.loadType : vo.loadType, GetPreloadFiles(vo.menuId, vo.parameter), OnModuleLoadDone, OnModuleLoadCancel, config.menuId, vo); } } else if (config.moduleType == ModuleType.Scene) { loadManager.LoadScene(config.path, config.menuId != MenuType.WarScene, config.menuId, vo.parameter, vo.loadType); } }
private void CheckMenuVO(MenuChangeVO vo) { if (vo.isToOpen) { OpenMenu(vo); } else { CloseMenu(vo); } }
/** 预打开模块 */ public void OpenMenuPreInstance(int menuId, object parameter, Action <int> callback) { MenuChangeVO vo = new MenuChangeVO(); vo.menuId = menuId; vo.isToOpen = true; vo.parameter = parameter; vo.isPreInstance = true; vo.instanceCallback = callback; CheckMenuVO(vo); }
IEnumerator OnDelayClose(MenuChangeVO vo) { yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); CloseMenu(vo.menuId); if (vo.instanceCallback != null) { vo.instanceCallback(vo.menuId); } }
private void RemoveWindow(IModule module, bool isInitiativeClose = true, bool forcedDestroy = false) { MenuConfig config = configSet [module.MenuId]; //Debug.Log("MenuManager.RemoveWindow config.name="+config.name+ " module=" + module + " module.MenuId=" + module.MenuId ); Debug.Log(config.menuId + " " + config.name + "config.isDestroy=" + config.isDestroy + " forcedDestroy=" + forcedDestroy); module.CheckOnExit(); if (config.isDestroy || forcedDestroy) { Debug.Log(config.menuId + " " + config.name + "config.isDestroy=" + config.isDestroy + " forcedDestroy=" + forcedDestroy); // if(module.IsActive) module.DestroyModule(); module.DestroyModule(); //Coo.assetManager.UnloadUnusedAssets(); } else { if (module.IsActive) { module.IsActive = false; } } int activeScreenFullCount = 0; foreach (IModule mod in modules.Values) { var menuId = mod.MenuId; var cfg = configSet[menuId]; if (cfg.showType == ShowType.Screen && mod.IsActive) { activeScreenFullCount += 1; } } if (activeScreenFullCount <= 0) { if (Application.loadedLevelName == "Main" && isInitiativeClose) //主动关闭会默认打开主场景 { MenuChangeVO menuVO = null; if (!lastOpens.TryGetValue(MenuType.Home, out menuVO)) { menuVO = new MenuChangeVO(); menuVO.menuId = MenuType.Home; menuVO.isToOpen = true; menuVO.isCloseOthers = false; } CheckMenuVO(menuVO); } } }
private void SetModuleParameter(MenuConfig config, MenuChangeVO vo, IModule module) { module.SetParameter(vo.parameter); module.rectTransform.SetParent(GetRoot(vo.isPreInstance ? MenuLayerType.Layer_PreInstance : config.layer), false); if (vo.isPreInstance) { module.rectTransform.SetAsFirstSibling(); } else { module.rectTransform.SetAsLastSibling(); } }
private void OnModuleLoadDone(Loader loader) { MenuChangeVO vo = loader.bindData as MenuChangeVO; MenuConfig config = configSet [vo.menuId]; Debug.Log("MenuManager.OpenWindow config.name=" + config.name + " config.menuId=" + config.menuId); assetManager.Load(config.path, (string path, System.Object o) => { UnityEngine.Object obj = o as UnityEngine.Object; if (obj == null) { Debug.Log(string.Format("<color=red>MenuManager.OnModuleLoadDone obj=null path={0}</color>", path)); } GameObject go = GameObject.Instantiate(obj) as GameObject; go.name = config.prefabName; go.transform.SetParent(GetRoot(vo.isPreInstance ? MenuLayerType.Layer_PreInstance : config.layer), 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 = vo.menuId; OpenWindow(vo, module); // UpdateLayerZ(); }); }
/// <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 DelayClose(MenuChangeVO vo) { StartCoroutine(OnDelayClose(vo)); }
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); } }