コード例 #1
0
    private void _OpenPanel(string uiName, bool closeBottom = false, params object[] args)
    {
        UIBase panel = uiStack.Find((p) => p.UIName.Equals(uiName));

        if (panel == null)
        {
            if (uiCache.ContainsKey(uiName))
            {
                panel = instance.uiCache[uiName];
                instance.uiCache.Remove(uiName);
            }
            else
            {
                GameObject uiPrefab = loader.GetUIByName(uiName);

                GameObject ui = Instantiate(uiPrefab);
                panel        = ui.GetComponent <UIBase>();
                panel.UIName = uiName;
                panel.OnInit();
            }

            CurrentUIPanel = panel;
            panel.Args     = args;
            panel.gameObject.SetActive(true);
            panel.transform.SetParent(instance.panelRoot);
            panel.transform.localPosition = Vector3.zero;
            panel.transform.localScale    = Vector3.one;

            RectTransform rtf = panel.GetComponent <RectTransform>();
            rtf.anchorMax = new Vector2(1, 1);
            rtf.anchorMin = new Vector2(0, 0);
            rtf.offsetMax = new Vector2(0, 0);
            rtf.offsetMin = new Vector2(0, 0);

            panel.OnRefresh();

            if (uiStack.Count > 0 && closeBottom)
            {
                UIBase lastPanel = uiStack[uiStack.Count - 1];
                lastPanel.gameObject.SetActive(false);
            }

            uiStack.Add(panel);
        }
        else
        {
            Debug.LogError(uiName + "已经打开");
        }
    }
コード例 #2
0
    public static void OpenPanel(string uiName)
    {
        UIBase panel = uiStack.Find((p) => p.UIName.Equals(uiName));

        if (panel == null)
        {
            if (uiCache.ContainsKey(uiName))
            {
                panel = uiCache[uiName];
            }
            else
            {
                GameObject uiPrefab = loader.GetUIByName(uiName);

                GameObject ui = Instantiate(uiPrefab);
                panel        = ui.GetComponent <UIBase>();
                panel.UIName = uiName;
                panel.OnInit();
            }

            CurrentUIPanel = panel;

            panel.gameObject.SetActive(true);
            panel.transform.SetParent(instance.transform);
            panel.transform.localPosition = Vector3.zero;
            panel.transform.localScale    = Vector3.one;

            panel.OnBeginOpen();
            panel.OnRefresh();
            panel.OnEndOpen();

            uiStack.Add(panel);
        }
        else
        {
            Debug.LogError(uiName + "已经打开");
        }
    }