Example #1
0
        /// <summary>
        /// 显示界面的预处理
        /// </summary>
        /// <param name="panelID"></param>
        /// <returns></returns>
        private Panel BeforeShowPanel(PanelID panelID)
        {
            if (IsPanelShown(panelID))
            {
                Log.Warn(String.Format("{0} panel have been shown!", panelID.ToString()));
                return(null);
            }

            Panel basePanel = GetGamePanel(panelID);

            if (basePanel == null)
            {
                Assert.IsTrue(UIConfig.BundleName.ContainsKey(panelID));
                GameObject prefab = ResManager.Instance.Load <GameObject>(
                    UIConfig.BundleName[panelID],
                    panelID.ToString() + UIConfig.Suffix
                    );
                Assert.IsNotNull <GameObject>(prefab);
                GameObject goPanel = GameObject.Instantiate(prefab, normalCanvas);
                goPanel.SetActive(false);
                basePanel = goPanel.GetComponent <Panel>();
                Assert.AreEqual <PanelID>(panelID, basePanel.PanelID);
                RectTransform targetRoot = GetCanvasRoot(basePanel.PanelData.Type);
                goPanel.transform.SetParent(targetRoot);
                goPanel.name       = panelID.ToString();
                allPanels[panelID] = basePanel;
            }
            return(basePanel);
        }
Example #2
0
    /// <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);
    }
Example #3
0
 public T Get <T>(PanelID id) where T : UIPanel
 {
     if (_registeredPanels.ContainsKey(id))
     {
         if (_registeredPanels[id] is T)
         {
             return(_registeredPanels[id] as T);
         }
         else
         {
             Debug.LogError("UIPanel mathcing ID '" + id.ToString() + "' is not of type '" + typeof(T).ToString() + "'.");
         }
     }
     else
     {
         Debug.LogError("No UIPanel with id '" + id.ToString() + "' registered with UIManager.");
     }
     return(null);
 }
Example #4
0
        /// <summary>
        /// 关闭界面
        /// </summary>
        /// <param name="panelID">界面ID</param>
        /// <param name="onComplete">回调</param>
        public bool HidePanel(PanelID panelID, Action onComplete = null)
        {
            if (!allPanels.ContainsKey(panelID))
            {
                Log.Warn(String.Format("Failed to hide {0} panel : cannot find panel!", panelID.ToString()));
                return(false);
            }

            Panel panel       = allPanels[panelID];
            Panel returnPanel = null;

            switch (panel.PanelData.Type)
            {
            //Normal界面
            case PanelType.Normal:
                DestroyAllPopupPanels();
                allPanels.Remove(panelID);
                panel.Destroy();

                //无导航,返回默认上级Normal界面
                if (normalNavigation.Count == 0)
                {
                    returnPanel = BeforeShowPanel(panel.PrePanelID);
                    if (returnPanel == null)
                    {
                        return(false);
                    }
                    Assert.AreEqual <PanelType>(PanelType.Normal, returnPanel.PanelData.Type);
                    returnPanel.Show();
                    curNormalPanel = returnPanel;
                }
                //返回导航Normal界面
                else
                {
                    Context lastContext = normalNavigation.Pop();
                    returnPanel = BeforeShowPanel(lastContext.PanelID);
                    if (returnPanel == null)
                    {
                        return(false);
                    }
                    returnPanel.Show(lastContext);
                    curNormalPanel = returnPanel;
                    if (lastContext.PopupNavigation != null)
                    {
                        ShowPopupPanels(lastContext.PopupNavigation);
                    }
                }
                RefreshFixedPanels(shownFixedPanels, returnPanel.FixedPanels);
                return(true);

            //Popup界面
            case PanelType.PopUp:
                if (panel.PanelData.NavigationMode == PanelNavigationMode.Navigation)
                {
                    if (panel != curPopupPanel)
                    {
                        //只能关闭最近打开的导航Popup界面
                        return(false);
                    }
                    panel.Hide();
                    if (shownPopupPanels.Count == 0)
                    {
                        curPopupPanel = null;
                    }
                    else
                    {
                        Context lastContext = popupNavigation.Pop();
                        returnPanel   = BeforeShowPanel(lastContext.PanelID);
                        curPopupPanel = returnPanel;
                        returnPanel.Show(lastContext);
                    }
                }
                else if (panel.PanelData.NavigationMode == PanelNavigationMode.NoNavigation)
                {
                    shownPopupPanels.Remove(panelID);
                    panel.Hide();
                }
                return(true);

            //Fixed界面
            case PanelType.Fixed:
                shownFixedPanels.Remove(panelID);
                panel.Hide();
                return(true);

            //
            default:
                return(false);
            }
        }
Example #5
0
        //----------------------------------------Public Methods

        /// <summary>
        /// 打开界面
        /// </summary>
        /// <param name="panelID">界面ID</param>
        /// <param name="context">上下文</param>
        public bool ShowPanel(PanelID panelID, Context context = null)
        {
            Panel panel = BeforeShowPanel(panelID);

            //Assert.IsNotNull<Panel>(panel);
            Debug.Log("ShowPanel:" + panelID.ToString());
            switch (panel.PanelData.Type)
            {
            //打开Normal界面
            case PanelType.Normal:
                if (curNormalPanel != null)
                {
                    //当前Normal界面压入导航栈
                    if (curNormalPanel.PanelData.NavigationMode == PanelNavigationMode.Navigation)
                    {
                        Context curContext = curNormalPanel.GetContext(popupNavigation);
                        normalNavigation.Push(curContext);
                    }
                    DestroyAllPopupPanels();
                    RefreshFixedPanels(shownFixedPanels, panel.FixedPanels);
                    curNormalPanel.Hide();
                }
                curNormalPanel = panel;
                panel.Show(context);
                if (context != null && context.PopupNavigation != null)
                {
                    ShowPopupPanels(context.PopupNavigation);
                }
                return(true);

            //打开Popup界面
            case PanelType.PopUp:
                if (panel.PanelData.PopupMode == PanelPopupMode.HideOther)
                {
                    foreach (KeyValuePair <PanelID, Panel> item in shownPopupPanels)
                    {
                        item.Value.Hide();
                    }
                    shownPopupPanels.Clear();
                    //压入导航栈,然后关闭
                    if (curPopupPanel != null)
                    {
                        Context curContext = curPopupPanel.GetContext();
                        popupNavigation.Push(curContext);
                        curPopupPanel.Hide();
                        curPopupPanel = null;
                    }
                }
                if (panel.PanelData.NavigationMode == PanelNavigationMode.Navigation)
                {
                    //压入导航栈但不关闭
                    if (curPopupPanel != null)
                    {
                        Context curContext = curPopupPanel.GetContext();
                        popupNavigation.Push(curContext);
                        curPopupPanel = panel;
                    }
                }
                panel.Show(context);
                return(true);

            //打开Fixed界面(不常用)
            case PanelType.Fixed:
                panel.Show(context);
                shownFixedPanels.Add(panelID, panel);
                return(true);

            //
            default:
                return(false);
            }
        }
Example #6
0
    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();
        }
    }