Ejemplo n.º 1
0
        /// <summary>
        /// 打开某个Ui
        /// </summary>
        /// <param name="panelName">Ui的名字</param>
        /// <param name="push">是否入栈</param>
        /// <param name="value">自定义数值</param>
        public void Open(string panelName, bool push = true, params object[] value)
        {
            if (m_uiDic.ContainsKey(panelName))
            {
                m_uiDic[panelName].show(false, value);
                m_uiDic[panelName].transform.SetAsLastSibling();
                m_uiDic[panelName].gameObject.SetActive(true);

                if (push)
                {
                    if (m_uiStack.Count > 0)
                    {
                        if (m_uiDic.ContainsKey(m_uiStack[m_uiStack.Count - 1]))
                        {
                            m_uiDic[m_uiStack[m_uiStack.Count - 1]].gameObject.SetActive(false);
                        }
                    }
                    m_uiStack.Add(panelName);
                }
            }
            else
            {
                if (ConfigManager.Instance.UIPanelConfigData.ContainsKey(panelName))
                {
                    UIPanelConfig uiData = ConfigManager.Instance.UIPanelConfigData[panelName];
                    if (uiData.Path != string.Empty)
                    {
                        GameObject go = Daemon.Instantiate(Resources.Load(uiData.Path) as GameObject);
                        go.transform.SetParent(Canvas.transform, false);
                        go.SetActive(false);
                        UIBase ui = go.GetComponent <UIBase>();
                        m_uiDic.Add(panelName, ui);

                        ui.show(true, value);
                        ui.gameObject.SetActive(true);
                        ui.transform.SetAsLastSibling();

                        if (push)
                        {
                            if (m_uiStack.Count > 0)
                            {
                                if (m_uiDic.ContainsKey(m_uiStack[m_uiStack.Count - 1]))
                                {
                                    m_uiDic[m_uiStack[m_uiStack.Count - 1]].gameObject.SetActive(false);
                                }
                            }
                            m_uiStack.Add(panelName);
                        }
                    }
                    else
                    {
                        Debug.LogError("UIPath is empty!");
                    }
                }
                else
                {
                    Debug.LogError("The UiPanel is not exist!");
                }
            }
        }