Example #1
0
    /// <summary>
    /// 加载面板
    /// </summary>
    protected void LoadPanel(string prefabPath, string panelName, Transform parentObj, float zValue, bool isSecendLevelUI = false)
    {
        try
        {
            GameObject panelPrefab = Resources.Load(prefabPath) as GameObject;
            GameObject panelObj    = GameObject.Instantiate(panelPrefab) as GameObject;

            if (parentObj == null)
            {
                parentObj = UIControl.CameraUI.transform;
            }
            panelObj.transform.parent = parentObj;

            if (zValue != 0)
            {
                panelObj.transform.localPosition = new Vector3(0, 0, zValue);
            }

            panelObj.transform.localScale = Vector3.one;
            panelObj.name = panelName;

            IPanel panelBase = panelObj.GetComponent <IPanel>();
            panelDic.Add(panelName, panelBase);
            if (isSecendLevelUI)
            {
                secendLevelPanelDic.Add(panelName, panelBase);
            }
            // 初始化Panel
            panelBase.Init();
        }
        catch (UnityException uex)
        {
            // //LogManager.Log(uex.ToString(), LogType.Fatal);
        }
    }