Пример #1
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);
    }