コード例 #1
0
    public void CloseUI(UIPanelBase uiPanel)
    {
        if (uiPanel.GetType().IsSubclassOf(typeof(UIWindow)))
        {
            UIWindow tempWnd = windowsStack.Peek();
            Debug.Log(tempWnd.name);
            if (!(uiPanel as UIWindow).isMain && tempWnd == uiPanel)
            {
                tempWnd = windowsStack.Pop();
                tempWnd.OnDispose();
                Destroy(tempWnd.gameObject);

                tempWnd = windowsStack.Peek();
                tempWnd.gameObject.SetActive(true);
                tempWnd.OnShow();
            }
            else
            {
                Debug.LogError("要关闭的界面不是栈顶元素或是栈底元素");
            }
        }
        else if (uiPanel.GetType().IsSubclassOf(typeof(UIDialog)))
        {
            UIDialog tempDlg = dialogsStack.Peek();

            Debug.Log(tempDlg.gameObject.name + "  " + uiPanel.gameObject.name);

            if (tempDlg == uiPanel)
            {
                tempDlg = dialogsStack.Pop();
                tempDlg.OnDispose();
                Destroy(tempDlg.gameObject);

                if (dialogsStack.Count > 0)
                {
                    tempDlg = dialogsStack.Peek();
                    tempDlg.OnShow();
                }
            }
            else
            {
                Debug.LogError("要关闭的界面不是栈顶元素");
            }
        }
        else
        {
            Debug.LogError("关闭的UI類型有問題,請檢測類型");
        }
    }