/// <summary> /// 当前面板是否可以缓存pid /// </summary> /// <param name="pType"></param> /// <returns></returns> public bool CanCachePanel(PanelID pid) { PanelCacheLv cacheLv = CacheLv; if (cacheLv == PanelCacheLv.None || IsStartPanel) { return(false); } bool canCache = false; LocalPanelInfo localP2 = null; if (DataManager.Manager <UIPanelManager>().TryGetLocalPanelInfo(pid, out localP2) && !localP2.IgnoreCache) { if (cacheLv == PanelCacheLv.All) { canCache = true; } else { PanelRootType r1 = UIRootHelper.Instance.GetRootTypePanelType(PType); PanelRootType r2 = UIRootHelper.Instance.GetRootTypePanelType(localP2.PType); canCache = (r1 >= r2); if (!canCache && CacheLv == PanelCacheLv.Dialog && r2 == PanelRootType.PopUp) { canCache = true; } } } return(canCache); }
/// <summary> /// 构建本地面板数据 /// </summary> private void StructLocalPanelInfo() { m_dic_localPanelInfo = new Dictionary <int, LocalPanelInfo>(); List <table.PanelInfoDataBase> panelInfos = GameTableManager.Instance.GetTableList <table.PanelInfoDataBase>(); if (null != panelInfos) { LocalPanelInfo localInfo = null; int pid = 0; for (int i = 0; i < panelInfos.Count; i++) { localInfo = LocalPanelInfo.Create(panelInfos[i].id); if (localInfo.PID == PanelID.None) { Engine.Utility.Log.Error("UIPanelManager->StructLocalPanelInfo error tableid = {0}", panelInfos[i].id); continue; } pid = (int)localInfo.PID; if (!m_dic_localPanelInfo.ContainsKey(pid)) { m_dic_localPanelInfo.Add(pid, localInfo); } } } }
/// <summary> /// 面板资源是否准备好 /// </summary> /// <param name="localInfo"></param> /// <returns></returns> private bool IsPanelAssetReady(LocalPanelInfo localInfo) { UIPanelBase tempPanel = null; bool ready = true; if (localInfo.NeedBg && ready) { tempPanel = GetPanel(PanelID.CommonBgPanel); if (null == tempPanel) { ready = false; } } if (localInfo.NeedTopBar && ready) { tempPanel = GetPanel(PanelID.TopBarPanel); if (null == tempPanel) { ready = false; } } tempPanel = GetPanel(localInfo.PID); if (null == tempPanel) { ready = false; } return(ready); }
public void ShowPanelTips(string tipsContronlName, LocalPanelInfo info) { string btnName = tipsContronlName; if (!string.IsNullOrEmpty(btnName)) { int len = btnName.Length; if (len > 0) { char chnum = btnName[len - 1]; int num = 0; if (int.TryParse(chnum.ToString(), out num)) { if (info.TextIDList != null) { if (num > 0) { num -= 1; if (num < info.TextIDList.Count) { uint textID = info.TextIDList[num]; DataManager.Manager <UIPanelManager>().ShowPanel(PanelID.CommonTipsPanel, data: textID); } } } } } } }
/// <summary> /// 显示面板 /// </summary> /// <param name="panelShowData"></param> private UIPanelBase ShowPanel(PanelShowData panelShowData) { UIPanelBase pBase = GetPanel(panelShowData.PID); if (null == pBase) { Engine.Utility.Log.Error("UIPanelManager->ShowPanel pBase null,pid:{0}", panelShowData.PID); return(pBase); } if (IsShowPanel(panelShowData.PID)) { pBase.PrePanelData = panelShowData.PrePanelData; pBase.ShowPanel(panelShowData.Data, jumpData: panelShowData.JumpData); Engine.Utility.Log.Warning(CLASS_NAME + "-> ShowPanel failed,panelId = {0} already show!", panelShowData.PID.ToString()); return(pBase); } //如果存在互斥面板已经显示则直接返回 LocalPanelInfo panelInfo = null; if (TryGetLocalPanelInfo(panelShowData.PID, out panelInfo)) { List <PanelID> mutexPanels = panelInfo.MutexPanels; if (null != mutexPanels) { for (int i = 0; i < mutexPanels.Count; i++) { if (IsShowPanel(mutexPanels[i])) { DealShowPanelMutex(panelShowData.PID); return(null); } } } } //if (panelShowData.PID == PanelID.MainPanel || panelShowData.PID == PanelID.MissionAndTeamPanel) //{ // UIRootHelper.Instance.SetPanelRootStatusByType(PanelRootType.Main, true); //} ReadyPanel(pBase, panelShowData.IgnoreCache); if (pBase.PanelInfo.IsStartPanel || panelShowData.ForceResetPanel) { pBase.ResetPanel(); } DoShowPanel(pBase, panelShowData.PrePanelData, panelShowData.Data, panelShowData.JumpData); if (pBase.PanelInfo.IsStartPanel || panelShowData.ForceClearCacheBack) { ClearCacheStack(); } return(pBase); }
/// <summary> /// 创建面板 /// </summary> /// <param name="pid">面板ID</param> /// <param name="panelTs">依赖的Transform</param> /// <returns></returns> private UIPanelBase CreatePanel(PanelID pid, Transform panelTs) { UIPanelBase panelBase = GetPanel(pid); if (null == panelTs) { Engine.Utility.Log.Error("UIPanelManager->CreatePanel failed ,Panel Transform null,PID:{0}", pid); return(panelBase); } LocalPanelInfo localPanelInfo = null; if (TryGetLocalPanelInfo(pid, out localPanelInfo)) { if (null == panelBase) { string panelPath = localPanelInfo.PrefabPath; string panelClassName = localPanelInfo.PanelEnumName; GameObject go = panelTs.gameObject; if (!string.IsNullOrEmpty(panelClassName)) { go.name = panelClassName; panelBase = go.GetComponent <UIPanelBase>(); if (null == panelBase) { panelBase = Util.AddComponent(go, panelClassName) as UIPanelBase; if (null != panelBase) { panelBase.PanelInfo = localPanelInfo; if (null != go && !go.activeSelf) { go.SetActive(true); } //初始化 panelBase.Init(); panelBase.InitPanelDetph(); //go.SetActive(false); } } allPanels.Add((uint)pid, panelBase); } } else { Debug.LogError("DespawnExistpanel:" + pid.ToString()); if (IsShowPanel(pid)) { Debug.LogError("DespawnExistSSS##panel:" + pid.ToString()); } UIManager.ReleaseObjs(localPanelInfo.TableData.resID, panelTs); } } return(panelBase); }
/// <summary> /// 异步加载面板 /// </summary> /// <param name="pid"></param> /// <param name="panelCreateAction"></param> private void LoadingPanelAsyn(PanelID pid) { LocalPanelInfo panelInfo = null; if (TryGetLocalPanelInfo(pid, out panelInfo) && !IsPanelReady(pid) && !IsLoadingPanel(pid)) { AddLoadingMask(pid); UIManager.GetObjAsyn(panelInfo.TableData.resID, OnPanelTransformAsynLoad, pid); } }
/// <summary> /// 准备资源 /// </summary> /// <param name="panelInfo"></param> private void ReadyPanelAsset(LocalPanelInfo panelInfo) { if (panelInfo.NeedBg) { LoadingPanelAsyn(PanelID.CommonBgPanel); } if (panelInfo.NeedTopBar) { LoadingPanelAsyn(PanelID.TopBarPanel); } LoadingPanelAsyn(panelInfo.PID); }
/// <summary> /// 是否下一个将要显示的面板ready /// </summary> /// <param name="pid"></param> /// <returns></returns> private bool IsNextShowPanelReady(ref PanelID pid) { nextShowPanelID = PanelID.None; bool ready = false; if (m_lstWaitingShow.Count > 0) { PanelShowData nextShowData = m_lstWaitingShow[0]; nextShowPanelID = nextShowData.PID; LocalPanelInfo localInfo = null; if (TryGetLocalPanelInfo(pid, out localInfo)) { ready = IsPanelAssetReady(localInfo); } } return(ready); }
/// <summary> /// 隐藏面板 /// </summary> /// <param name="id">面板id</param> /// <param name="ignoreCacheBack">是否忽略cacheBack</param> /// <param name="action"></param> /// <param name="needDestroy"></param> /// <param name="?"></param> public void HidePanel(PanelID id, bool needReturnBack, Action action = null) { if (!IsShowPanel(id)) { return; } UIPanelBase panel = GetPanel(id); int pid = (int)id; Action hideCallback = () => { LocalPanelInfo lp = null; if (TryGetLocalPanelInfo(id, out lp) && lp.PanelTaData.Enable) { UIFrameManager.Instance.ResetTabs(); } if (needReturnBack) { if (panel.PanelInfo.CacheLv != PanelCacheLv.None) { OnPanelCacheBack(id); } //如果有前置面板,显示前置面板 if (null != panel.PrePanelData && panel.PrePanelData.PID != PanelID.None) { ShowPanel(panel.PrePanelData.PID , prePanelData: panel.PrePanelData.PrePanelData , data: panel.PrePanelData.Data, jumpData: panel.PrePanelData.JumpData); } } //主界面影藏,根节点也隐藏 //if (id == PanelID.MainPanel) //{ // UIRootHelper.Instance.SetPanelRootStatusByType(PanelRootType.Main,false); //} }; if (null != action) { hideCallback += action; } panel.HidePanel(hideCallback); }
/// <summary> /// 面板状态改变 /// </summary> /// <param name="status">面板状态数据</param> private void OnPanelStatusChanged(UIPanelBase.PanelStatusData status) { switch (status.Status) { case UIPanelBase.PanelStatus.Awake: break; case UIPanelBase.PanelStatus.PrepareShow: break; case UIPanelBase.PanelStatus.Show: { OnPanelShow(status.ID); //播放音效 LocalPanelInfo localInfo = null; if (TryGetLocalPanelInfo(status.ID, out localInfo) && localInfo.HaveSoundEffect) { DataManager.Manager <UIManager>().PlayUIAudioEffect(localInfo.SoundEffectId); } } break; case UIPanelBase.PanelStatus.Hide: { OnPanelHide(status.ID); } break; case UIPanelBase.PanelStatus.Destroy: { //if (IsShowPanel(status.ID)) //{ // UnityEngine.Debug.LogError("p1:" + status.Obj.transform.GetInstanceID()); //} //RemoveHidePanel(status.ID); } break; } //if (UIDefine.IsUIDebugLogEnable) // Engine.Utility.Log.Info("UIPanelManager:<color=red>{0}->{1}</color>", status.ID, status.Status.ToString().ToUpper()); CheckFocusDatas(status.ID); Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.UIEVENT_PANELSTATUSDATACHANGED, status); }
/// <summary> /// 执行面板显示 /// </summary> private void ProccessPanelShowing() { LocalPanelInfo localPanelInfo = null; if (IsNextShowPanelReady(ref nextShowPanelID)) { if (TryGetLocalPanelInfo(nextShowPanelID, out localPanelInfo)) { PanelShowData nextShowData = new PanelShowData(); if (nextShowPanelID != PanelID.CommonBgPanel && nextShowPanelID != PanelID.TopBarPanel) { if (localPanelInfo.NeedBg) { nextShowData.PID = PanelID.CommonBgPanel; ShowPanel(nextShowData); } if (localPanelInfo.NeedTopBar) { nextShowData.PID = PanelID.TopBarPanel; nextShowData.Data = localPanelInfo; ShowPanel(nextShowData); } } if (m_lstWaitingShow.Count > 0) { nextShowData = m_lstWaitingShow[0]; ShowPanel(nextShowData); } } } else if (m_lstWaitingShow.Count > 0) { PanelShowData psd = m_lstWaitingShow[0]; if (TryGetLocalPanelInfo(psd.PID, out localPanelInfo) && !IsPanelAssetReady(localPanelInfo)) { ReadyPanelAsset(localPanelInfo); } } }
/// <summary> /// 更新导航信息 /// </summary> /// <param name="panelBase"></param> private void UpdateNavigationInfo(PanelID pid, bool ignoreCache) { LocalPanelInfo localPanelInfo = null; if (TryGetLocalPanelInfo(pid, out localPanelInfo)) { if (localPanelInfo.IsStartPanel) { ClearCacheStack(); } if ((localPanelInfo.HidePanelMask == 0 && localPanelInfo.CacheLv == PanelCacheLv.None)) { return; } HideCondition condition = (info) => { if (info != null && (localPanelInfo.IsMatchHideType(info.PType) || localPanelInfo.CanCachePanel(info.PID))) { return(true); } return(false); }; List <UIPanelBase.PanelData> cachePanels = new List <UIPanelBase.PanelData>(); if (showPanels.Count > 0 && condition != null) { List <PanelID> lstHide = new List <PanelID>(); UIPanelBase.PanelData panelBackspaceData = null; UIPanelBase.PanelReturnData lastReturnData = (null != panelCacheStack && panelCacheStack.Count != 0) ? panelCacheStack.Peek() : null; bool canCache = (null == lastReturnData || lastReturnData.PID != pid); PanelID tempPID = PanelID.None; UIPanelBase tempPBase = null; LocalPanelInfo tempInfo = null; for (int i = 0, max = showPanels.Count; i < max; i++) { tempPID = (PanelID)showPanels[i]; tempPBase = GetPanel(tempPID); if (null == tempPBase) { continue; } if (TryGetLocalPanelInfo(tempPID, out tempInfo) && condition(tempInfo)) { lstHide.Add(tempPID); if (!ignoreCache && canCache && localPanelInfo.CanCachePanel(tempPID)) { panelBackspaceData = tempPBase.GetPanelData(); if (null == panelBackspaceData.JumpData) { panelBackspaceData.JumpData = new UIPanelBase.PanelJumpData(); } panelBackspaceData.JumpData.IsBackspacing = true; cachePanels.Add(panelBackspaceData); } } } if (cachePanels.Count > 0) { cachePanels.Sort((left, right) => { UIPanelBase pleft = GetPanel(left.PID); UIPanelBase pright = GetPanel(right.PID); return(pleft.Depth - pright.Depth); }); panelCacheStack.Push(new UIPanelBase.PanelReturnData() { PID = pid, CachePanelList = cachePanels, }); } for (int i = 0; i < lstHide.Count; i++) { HidePanel(lstHide[i], false); } } } }
private void ShowPanel(PanelID panelId, UIPanelBase.PanelData prePanelData, bool ignoreCache, object data = null , UIPanelBase.PanelJumpData jumpData = null, bool forceClearCacheBack = false, bool forceResetPanel = false, Action <UIPanelBase> panelShowAction = null) { if (panelId == PanelID.LoadingPanel) { m_lstWaitingShow.Clear(); } if (IsShowPanel(panelId)) { //UIPanelBase pBase = GetPanel(panelId); //pBase.PrePanelData = prePanelData; //pBase.ShowPanel(data, jumpData: jumpData); //if (null != panelShowAction) //{ // panelShowAction.Invoke(pBase); //} Engine.Utility.Log.Warning(CLASS_NAME + "-> ShowPanel warning,panelId = {0} already show!", panelId.ToString()); //return ; } //如果存在互斥面板已经显示则直接返回 //不做互斥处理 LocalPanelInfo panelInfo = null; if (!TryGetLocalPanelInfo(panelId, out panelInfo)) { return; } if (!IsWaitingShow(panelId)) { PanelShowData showData = new PanelShowData() { PID = panelId, PrePanelData = prePanelData, Data = data, JumpData = jumpData, ForceClearCacheBack = forceClearCacheBack, ForceResetPanel = forceResetPanel, IgnoreCache = ignoreCache, PanelShowAction = panelShowAction, }; m_lstWaitingShow.Add(showData); } else { Engine.Utility.Log.Warning(CLASS_NAME + "-> ShowPanel failed,panelId = {0} already in waitingshow Quene !", panelId.ToString()); } //列表容量保护 if (m_lstWaitingShow.Count >= MAX_WAITING_SHOW_NUM) { m_lstWaitingShow = new List <PanelShowData>(); ShowMain(); return; } if (!IsPanelAssetReady(panelInfo)) { ReadyPanelAsset(panelInfo); } else { ProccessPanelShowing(); } }
/// <summary> /// 根据当前显示面板重新检测当前获取焦点面板 /// </summary> /// <param name="panelID">当前显示面板</param> private void CheckFocusDatas(PanelID panelID) { LocalPanelInfo panelInfo = null; if (!TryGetLocalPanelInfo(panelID, out panelInfo) || !panelInfo.IsNeedCalculateFocus) { return; } PanelRootType rootType = UIRootHelper.Instance.GetRootTypePanelType(panelInfo.PType); oldFocusTempData.Clear(); curFocusTempData.Clear(); oldFocusTempData.AddRange(GetFocusPanels()); RemoveAllFocusPanel(); PanelRootType tempRootType = PanelRootType.None; PanelRootType maxFocusRootType = PanelRootType.None; LocalPanelInfo tempPanelInfo = null; List <uint> showPanelsKeys = new List <uint>(); showPanelsKeys.AddRange(showPanels); PanelID showNormal = PanelID.None; int maxRootPanelDepth = 0; UIPanelBase tempPanelBase = null; PanelID pid = PanelID.None; for (int i = 0; i < showPanelsKeys.Count; i++) { pid = (PanelID)showPanelsKeys[i]; if (!TryGetLocalPanelInfo(pid, out tempPanelInfo) || !tempPanelInfo.IsNeedCalculateFocus) { continue; } if (tempPanelInfo.PType == PanelType.Normal) { showNormal = tempPanelInfo.PID; } tempRootType = UIRootHelper.Instance.GetRootTypePanelType(tempPanelInfo.PType); if ((tempRootType == PanelRootType.None || maxFocusRootType < tempRootType) && tempRootType != PanelRootType.MarQueen //&& tempPanelInfo.PType != PanelType.SmartPopUp ) { maxFocusRootType = tempRootType; } tempPanelBase = GetPanel(pid); if (tempRootType == maxFocusRootType && tempPanelBase.Depth > maxRootPanelDepth) { maxRootPanelDepth = tempPanelBase.Depth; } } for (int i = 0; i < showPanelsKeys.Count; i++) { pid = (PanelID)showPanelsKeys[i]; if (!TryGetLocalPanelInfo(pid, out tempPanelInfo) || !tempPanelInfo.IsNeedCalculateFocus) { continue; } tempRootType = UIRootHelper.Instance.GetRootTypePanelType(tempPanelInfo.PType); tempPanelBase = GetPanel(pid); if (tempRootType < maxFocusRootType) { if (maxFocusRootType == PanelRootType.Fixed) { if (showNormal != PanelID.None) { if (tempPanelBase.PanelId == showNormal) { AddFocusPanel(pid); } } else { AddFocusPanel(pid); } } } else if (tempRootType == maxFocusRootType) { if (maxFocusRootType == PanelRootType.Main || tempPanelBase.Depth >= maxRootPanelDepth) { AddFocusPanel(pid); } } else if (tempRootType > maxFocusRootType) { AddFocusPanel(pid); } } //3、对比焦点变化的面板 curFocusTempData.AddRange(GetFocusPanels()); PanelFocusData focusData = new PanelFocusData(); focusData.GetFocus = false; for (int i = 0; i < oldFocusTempData.Count; i++) { if (curFocusTempData.Contains(oldFocusTempData[i])) { curFocusTempData.Remove(oldFocusTempData[i]); } else { focusData.ID = oldFocusTempData[i]; Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.UIEVENT_PANELFOCUSSTATUSCHANGED, focusData); } } focusData.GetFocus = true; for (int i = 0; i < curFocusTempData.Count; i++) { focusData.ID = curFocusTempData[i]; Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.UIEVENT_PANELFOCUSSTATUSCHANGED, focusData); } }
/// <summary> /// 尝试回去本地面板信息 /// </summary> /// <param name="pID"></param> /// <param name="info"></param> /// <returns></returns> public bool TryGetLocalPanelInfo(PanelID pID, out LocalPanelInfo info) { return(m_dic_localPanelInfo.TryGetValue((int)pID, out info)); }