public static PPPUIBase addScript(GameObject obj, string strClassName)
    {
        var       type = Type.GetType(strClassName);
        PPPUIBase ret  = null;

        if (type != null)
        {
            ret = obj.AddComponent(type) as PPPUIBase;
            if (ret != null)
            {
                ret.initProperty();
                ret.Init();
            }
        }
        return(ret);
    }
    /// <summary>
    /// 加载UI界面
    /// </summary>
    /// <param name="strPrefabePath"></param>
    /// <returns></returns>
    public UIDialogBase LoadScene(string strPrefabePath)
    {
        UIDialogBase dialog = FindInCache(strPrefabePath);


        if (dialog == null)
        {
            GameObject newSceneGameObject = Resources.Load <GameObject>(strPrefabePath);

            if (newSceneGameObject != null)
            {
                newSceneGameObject = UIUtils.AddChild(this.gameObject, newSceneGameObject);
                if (newSceneGameObject != null)
                {
                    dialog = newSceneGameObject.GetComponent <UIDialogBase>();
                    if (dialog == null)
                    {
                        newSceneGameObject.name = newSceneGameObject.name.Replace("(Clone)", "");
                        dialog = PPPUIBase.addScript(newSceneGameObject, newSceneGameObject.name) as UIDialogBase;
                    }

                    if (dialog != null)
                    {
                        dialog.name = strPrefabePath;
                        dialog.InitializeScene();
                    }
                }
                else
                {
                    PPP.pppShow(true, "UISystem::LoadDialog() Failed to add new scene to parent UISystem with name: " + strPrefabePath);
                }
            }
            else
            {
                PPP.pppShow(true, "UISystem::LoadDialog() Failed to load new scene with name: " + strPrefabePath);
            }
        }

        return(dialog);
    }
Exemple #3
0
    /* Load the scene and return the instanced scene. Now by name! */
    public UISceneBase LoadScene(string page, bool hideScene = false)
    {
        // Find the scene in the loaded list
        for (int idx = 0; idx < LoadedScenes.Count; idx++)
        {
            // NEW: find by name instead of enum
            if (LoadedScenes[idx] != null &&
                LoadedScenes[idx].Page == page)
            {
                return(LoadedScenes[idx]);
            }
        }

        //if (page == UIPage.Null)
        //{
        //    PPP.pppShow();
        //    return null;
        //}
        string     strPrefabeName     = page;
        GameObject newSceneGameObject = Resources.Load <GameObject>(strPrefabeName);

        if (newSceneGameObject == null)
        {
            PPP.pppShow();
            return(null);
        }
        GameObject go = GameObject.Instantiate(newSceneGameObject) as GameObject;

        if (go == null)
        {
            PPP.pppShow();
            return(null);
        }
        SceneGame objSceneGame = go.GetComponent <SceneGame>();

        UISceneBase objSceneUI = go.GetComponent <UISceneBase>();

        if (objSceneGame == null && objSceneUI == null)
        {
            go.name = go.name.Replace("(Clone)", "");
            var objTemp = PPPUIBase.addScript(go, go.name);
            if (objTemp != null)
            {
                objSceneGame = objTemp as SceneGame;
                if (objSceneGame == null)
                {
                    objSceneUI = objTemp as UISceneBase;
                }
            }
        }
        if (objSceneGame != null)
        {
#if UNITY_EDITOR
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create Object");
#endif
            Transform t = go.transform;
            t.SetParent(Game.Instance.transform);
            go.layer = Game.Instance.gameObject.layer;

            if (objSceneGame.sceneUI == null)
            {
                var arrChild = objSceneGame.GetComponentsInChildren <UISceneBase>();
                if (arrChild == null || arrChild.Length == 0)
                {
                    PPP.pppShow();
                    return(null);
                }
                objSceneGame.sceneUI         = arrChild[0];
                objSceneGame.sceneUI.scene3D = objSceneGame;
            }
            objSceneGame.sceneUI.Page = page;

            LoadedScenes.Add(objSceneGame.sceneUI);
            // Allow the scene to initialize itself
            objSceneGame.sceneUI.InitializeScene();

            if (hideScene == true)
            {
                objSceneGame.sceneUI.HideScene();
            }
            return(objSceneGame.sceneUI);
        }
        else if (objSceneUI != null)
        {
#if UNITY_EDITOR
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create Object");
#endif
            Transform t = go.transform;
            t.SetParent(this.gameObject.transform);
            t.localPosition = Vector3.zero;
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;
            go.layer        = this.gameObject.layer;

            objSceneUI.Page = page;

            LoadedScenes.Add(objSceneUI);
            // Allow the scene to initialize itself
            objSceneUI.InitializeScene();

            if (hideScene == true)
            {
                objSceneUI.HideScene();
            }
            return(objSceneUI);
        }
        else
        {
            PPP.pppShow();
        }
        return(null);
    }