コード例 #1
0
        internal bool LoadStage(string prefabPath)
        {
            if (isValid)
            {
                Cleanup();
            }

            m_PrefabAssetPath = prefabPath;

            // Ensure m_PreviewScene is set before calling LoadPrefabIntoPreviewScene() so the user can request the current
            // the PrefabStage in their OnEnable and other callbacks (if they use ExecuteInEditMode or ExecuteAlways)
            bool isUIPrefab = PrefabStageUtility.IsUIPrefab(m_PrefabAssetPath);

            m_PreviewScene = PrefabStageUtility.GetEnvironmentSceneOrEmptyScene(isUIPrefab);

            m_PrefabContentsRoot = PrefabStageUtility.LoadPrefabIntoPreviewScene(prefabAssetPath, m_PreviewScene);
            if (m_PrefabContentsRoot != null)
            {
                PrefabStageUtility.HandleReparentingIfNeeded(m_PrefabContentsRoot, isUIPrefab);
                m_PrefabFileIcon      = DeterminePrefabFileIconFromInstanceRootGameObject();
                m_LastRootTransform   = m_PrefabContentsRoot.transform;
                m_InitialSceneDirtyID = m_PreviewScene.dirtyID;
                UpdateEnvironmentHideFlags();
            }
            else
            {
                // Invalid setup
                Cleanup();
            }

            return(isValid);
        }
コード例 #2
0
        internal bool LoadStage(string prefabPath)
        {
            if (initialized)
            {
                Cleanup();
            }

            m_PrefabAssetPath = prefabPath;

            // Tempoary scene used while loading the prefab
            m_PreviewScene = EditorSceneManager.NewPreviewScene();

            // The user can have OnEnable and other callbacks called during LoadPrefabIntoPreviewScene (if they use ExecuteInEditMode or ExecuteAlways)
            // where they might request the current the prefabstage, so we ensure m_PreviewScene have been setup so they can check this stage's scene.
            m_PrefabContentsRoot = PrefabStageUtility.LoadPrefabIntoPreviewScene(prefabAssetPath, m_PreviewScene);

            if (m_PrefabContentsRoot != null)
            {
                // Create the environment scene and move the prefab root to this scene to ensure the correct rendersettings (skybox etc) are used in Prefab Mode.
                string environmentEditingScenePath = PrefabStageUtility.GetEnvironmentScenePathForPrefab(m_PrefabContentsRoot);
                Scene  environmentScene            = PrefabStageUtility.CreatePreviewScene(environmentEditingScenePath);
                environmentScene.name = m_PrefabContentsRoot.name;
                SceneManager.MoveGameObjectToScene(m_PrefabContentsRoot, environmentScene);
                if (!PrefabStageUtility.HandleAutoReparenting(m_PrefabContentsRoot, environmentScene))
                {
                    m_PrefabContentsRoot.transform.SetAsFirstSibling();
                }

                // Close the temporary prefab loading scene and set the environment scene as the scene of the stage
                EditorSceneManager.ClosePreviewScene(m_PreviewScene);
                m_PreviewScene = environmentScene;

                m_PrefabFileIcon      = DeterminePrefabFileIconFromInstanceRootGameObject();
                m_InitialSceneDirtyID = m_PreviewScene.dirtyID;
                UpdateEnvironmentHideFlags();
            }
            else
            {
                // Invalid setup
                Cleanup();
            }

            return(initialized);
        }
コード例 #3
0
        internal bool LoadStage(string prefabPath)
        {
            if (initialized)
            {
                Cleanup();
            }

            m_PrefabAssetPath = prefabPath;

            // Tempoary scene used while loading the prefab
            m_PreviewScene = EditorSceneManager.NewPreviewScene();

            // The user can have OnEnable and other callbacks called during LoadPrefabIntoPreviewScene (if they use ExecuteInEditMode or ExecuteAlways)
            // where they might request the current the prefabstage, so we ensure m_PreviewScene have been setup so they can check this stage's scene.
            m_PrefabContentsRoot = PrefabStageUtility.LoadPrefabIntoPreviewScene(prefabAssetPath, m_PreviewScene);

            if (m_PrefabContentsRoot != null)
            {
                Scene environmentScene = PrefabStageUtility.MovePrefabRootToEnvironmentScene(m_PrefabContentsRoot);

                // Close the temporary prefab loading scene and set the environment scene as the scene of the stage
                EditorSceneManager.ClosePreviewScene(m_PreviewScene);
                m_PreviewScene = environmentScene;

                m_PrefabFileIcon      = DeterminePrefabFileIconFromInstanceRootGameObject();
                m_InitialSceneDirtyID = m_PreviewScene.dirtyID;
                UpdateEnvironmentHideFlags();
            }
            else
            {
                // Invalid setup
                Cleanup();
            }

            return(initialized);
        }