Example #1
0
        /// <summary>
        /// 出栈 ,把页面从界面上移除
        /// </summary>
        public BasePanel PopPanel()
        {
            if (m_PanelStack == null)
            {
                m_PanelStack = new Stack <BasePanel>();
            }

            if (m_PanelStack.Count <= 0)
            {
                return(null);
            }

            BasePanel topPanel = m_PanelStack.Pop(); // 获取并移除栈顶面板

            topPanel.OnClose();                      // 关闭面板
            return(topPanel);
        }
Example #2
0
        /// <summary>
        /// 根据面板类型 得到实例化的面板
        /// </summary>
        /// <returns></returns>
        public BasePanel GetPanel(string uiname)
        {
            if (m_PanelDict == null)
            {
                m_PanelDict = new Dictionary <string, BasePanel>();
            }

            m_PanelDict.TryGetValue(uiname, out BasePanel panel);

            if (panel == null)
            {
                // 根据prefab去实例化面板
                m_PanelPathDict.TryGetValue(uiname, out string path);
                Debug.Log(path);
                GameObject instPanel = GameObject.Instantiate(Resources.Load(path)) as GameObject;

                // UICore与派生类不一定在一个程序集类,所以不能直接用Type.GetType  TODO : 根据不同平台规定路径
                Assembly  asmb      = Assembly.Load("Assembly-CSharp");
                Type      type      = asmb.GetType(uiname);
                BasePanel basePanel = (BasePanel)Activator.CreateInstance(type);
                basePanel.Init(instPanel, uiname);
                if (basePanel == null)
                {
                    throw new System.Exception("面板类名错误");
                }
                m_PanelDict.Add(uiname, basePanel);

                Transform uiGroup = CanvasTransform.Find("Level" + basePanel.Level);
                if (uiGroup == null)
                {
                    RectTransform rect;
                    rect = (new GameObject("Level" + basePanel.Level)).AddComponent <RectTransform>();
                    rect.SetParent(CanvasTransform);
                    rect.sizeDelta  = CanvasTransform.sizeDelta;
                    rect.position   = CanvasTransform.position;
                    rect.localScale = Vector3.one;
                    uiGroup         = rect;
                }
                instPanel.transform.SetParent(uiGroup, false);
                return(basePanel);
            }
            else
            {
                return(panel);
            }
        }
Example #3
0
        /// <summary>
        /// 把某个页面入栈,  把某个页面显示在界面上
        /// </summary>
        public void PushPanel(string uiname)
        {
            if (m_PanelStack == null)
            {
                m_PanelStack = new Stack <BasePanel>();
            }

            BasePanel nextPanel    = GetPanel(uiname); // 计划打开的页面
            BasePanel currentPanel = null;             // 最近一次关闭的界面

            // 判断一下栈里面是否有页面
            if (m_PanelStack.Count > 0)
            {
                BasePanel topPanel = m_PanelStack.Peek(); // 获取栈顶页面

                // 如果即将打开的页面是栈顶页面,即关闭栈顶页面
                if (topPanel == nextPanel)
                {
                    PopPanel();
                    return;
                }
                // 当栈内有面板时,进行判断
                while (m_PanelStack.Count > 0)
                {
                    if (topPanel.Level < nextPanel.Level)
                    {
                        break;
                    }
                    // 如果栈顶页面的层级不小于要打开的页面层级,关闭它并保存
                    currentPanel = PopPanel();
                    if (m_PanelStack.Count > 0)
                    {
                        topPanel = m_PanelStack.Peek();
                    }
                }
            }
            // 如果最后关闭的界面和要打开的是同一个,就不打开了
            if (currentPanel != nextPanel)
            {
                nextPanel.OnOpen();
                m_PanelStack.Push(nextPanel); // 将打开的面板入栈
            }
        }