Пример #1
0
        public static SubScene CreateSubSceneInSceneFromObjects(string name, bool keepOpen, Scene parentScene, Func <List <GameObject> > createObjects = null)
        {
            var args = new SubSceneContextMenu.NewSubSceneArgs
            {
                parentScene     = parentScene,
                newSubSceneMode = SubSceneContextMenu.NewSubSceneMode.EmptyScene
            };

            SceneManager.SetActiveScene(parentScene);

            var subScene = SubSceneContextMenu.CreateNewSubScene(name, args, InteractionMode.AutomatedAction);

            SubSceneInspectorUtility.EditScene(subScene);
            var objects = createObjects?.Invoke();

            if (objects != null)
            {
                foreach (var obj in objects)
                {
                    SceneManager.MoveGameObjectToScene(obj, subScene.EditingScene);
                }
            }

            EditorSceneManager.SaveScene(subScene.EditingScene);
            EditorSceneManager.SaveScene(parentScene);
            if (!keepOpen)
            {
                SubSceneInspectorUtility.CloseSceneWithoutSaving(subScene);
            }
            return(subScene);
        }
        public void OneTimeSetUp()
        {
            if (!EditorApplication.isPlaying)
            {
                string path;
                do
                {
                    path = Path.GetRandomFileName();
                } while (AssetDatabase.IsValidFolder(Path.Combine(k_AssetsFolderRoot, path)));

                m_PreviousLiveLinkState = SubSceneInspectorUtility.LiveLinkEnabledInEditMode;
                SubSceneInspectorUtility.LiveLinkEnabledInEditMode = true;

                var guid = AssetDatabase.CreateFolder(k_AssetsFolderRoot, path);
                m_TestAssetsDirectory = AssetDatabase.GUIDToAssetPath(guid);

                m_Scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
                var mainScenePath = Path.Combine(m_TestAssetsDirectory, $"{k_SceneName}.{k_SceneExtension}");

                EditorSceneManager.SaveScene(m_Scene, mainScenePath);
                SceneManager.SetActiveScene(m_Scene);

                // Temp context GameObject, necessary to create an empty subscene
                var targetGO = new GameObject(k_SubSceneName);

                var subsceneArgs = new SubSceneContextMenu.NewSubSceneArgs(targetGO, m_Scene, SubSceneContextMenu.NewSubSceneMode.EmptyScene);
                m_SubScene     = SubSceneContextMenu.CreateNewSubScene(targetGO.name, subsceneArgs, InteractionMode.AutomatedAction);
                m_SubSceneRoot = m_SubScene.gameObject;

                UnityEngine.Object.DestroyImmediate(targetGO);
                EditorSceneManager.SaveScene(m_Scene);
            }
        }
Пример #3
0
    public void CreatingSubSceneFromPartialPrefabInstanceIsNotAllowed()
    {
        var mainScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

        EditorSceneManager.SetActiveScene(mainScene);

        var path = Path.Combine(m_TempAssetDir, "ParentScene.unity");

        EditorSceneManager.SaveScene(mainScene, path);

        var go1 = new GameObject("go1");
        var go2 = new GameObject("go2");
        var go3 = new GameObject("go3");

        go2.transform.parent = go1.transform;
        go3.transform.parent = go2.transform;
        PrefabUtility.SaveAsPrefabAssetAndConnect(go1, m_TempAssetDir + "/TestPrefab.prefab", InteractionMode.AutomatedAction);

        Selection.activeGameObject = go2;
        var args = new SubSceneContextMenu.NewSubSceneArgs
        {
            target          = Selection.activeGameObject,
            newSubSceneMode = SubSceneContextMenu.NewSubSceneMode.MoveSelectionToScene
        };

        Assert.Throws <ArgumentException>(
            () => { SubSceneContextMenu.CreateNewSubScene(args.target.name, args, InteractionMode.AutomatedAction); }
            , "Creating a SubScene from a partial Prefab selection should fail");
    }
Пример #4
0
    public void CreateSubSceneFromSelectionKeepsSiblingIndexInHierarchy()
    {
        var mainScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

        EditorSceneManager.SetActiveScene(mainScene);

        var path = Path.Combine(m_TempAssetDir, "ParentScene.unity");

        EditorSceneManager.SaveScene(mainScene, path);

        var go1 = new GameObject("go1");
        var go2 = new GameObject("go2");
        var go3 = new GameObject("go3");

        var siblingIndex = go2.transform.GetSiblingIndex();

        Selection.activeGameObject = go2;

        var args = new SubSceneContextMenu.NewSubSceneArgs
        {
            target          = Selection.activeGameObject,
            newSubSceneMode = SubSceneContextMenu.NewSubSceneMode.MoveSelectionToScene
        };
        var subsceneComponent = SubSceneContextMenu.CreateNewSubScene(args.target.name, args, InteractionMode.AutomatedAction);

        Assert.AreEqual(siblingIndex, subsceneComponent.transform.GetSiblingIndex(), "The resulting SubScene GameObject should have the sibling order in the Hierarchy as the input GameObject.");
    }
Пример #5
0
        public void Should_Convert_Under_Subscene()
        {
            SubSceneContextMenu.CreateSubSceneAndAddSelection(m_GrandParent);

            var conversionStatusGrandParent = GameObjectConversionEditorUtility.GetGameObjectConversionResultStatus(m_GrandParent);
            var conversionStatusParent      = GameObjectConversionEditorUtility.GetGameObjectConversionResultStatus(m_Parent);
            var conversionStatusChild       = GameObjectConversionEditorUtility.GetGameObjectConversionResultStatus(m_Child);

            Assert.That(conversionStatusGrandParent, Is.EqualTo(GameObjectConversionResultStatus.ConvertedBySubScene));
            Assert.That(conversionStatusParent, Is.EqualTo(GameObjectConversionResultStatus.ConvertedBySubScene));
            Assert.That(conversionStatusChild, Is.EqualTo(GameObjectConversionResultStatus.ConvertedBySubScene));
        }
Пример #6
0
    void CreateSubScene(string name)
    {
        var mainScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

        EditorSceneManager.SetActiveScene(mainScene);

        var path = Path.Combine(m_TempAssetDir, $"{name}.unity");

        EditorSceneManager.SaveScene(mainScene, path);

        Selection.activeObject = new GameObject();

        SubSceneContextMenu.CreateSubSceneAndAddSelection(Selection.activeObject);
    }
Пример #7
0
    SubScene CreateSubScene(string subSceneName, string parentSceneName, InteractionMode interactionMode = InteractionMode.AutomatedAction)
    {
        var mainScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

        EditorSceneManager.SetActiveScene(mainScene);

        var path = Path.Combine(m_TempAssetDir, $"{parentSceneName}.unity");

        EditorSceneManager.SaveScene(mainScene, path);

        var go = new GameObject();

        go.name = subSceneName;
        Selection.activeGameObject = go;

        return(SubSceneContextMenu.CreateSubSceneAndAddSelection(Selection.activeGameObject, interactionMode));
    }
Пример #8
0
    public void CreatingSubSceneFromPartialPrefabInstanceIsNotAllowed()
    {
        var mainScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

        EditorSceneManager.SetActiveScene(mainScene);

        var path = Path.Combine(m_TempAssetDir, "ParentScene.unity");

        EditorSceneManager.SaveScene(mainScene, path);

        var go1 = new GameObject("go1");
        var go2 = new GameObject("go2");
        var go3 = new GameObject("go3");

        go2.transform.parent = go1.transform;
        go3.transform.parent = go2.transform;
        PrefabUtility.SaveAsPrefabAssetAndConnect(go1, m_TempAssetDir + "/TestPrefab.prefab", InteractionMode.AutomatedAction);

        Selection.activeGameObject = go2;
        var subsceneComponent = SubSceneContextMenu.CreateSubSceneAndAddSelection(Selection.activeGameObject, InteractionMode.AutomatedAction);

        Assert.IsNull(subsceneComponent, "Creating a SubScene from a partial Prefab selection should fail");
    }
Пример #9
0
        SubScene CreateSubScene(string subSceneName, string parentSceneName, InteractionMode interactionMode = InteractionMode.AutomatedAction, SubSceneContextMenu.NewSubSceneMode mode = SubSceneContextMenu.NewSubSceneMode.MoveSelectionToScene)
        {
            var mainScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

            SceneManager.SetActiveScene(mainScene);

            var path = Path.Combine(m_TempAssetDir, $"{parentSceneName}.unity");

            EditorSceneManager.SaveScene(mainScene, path);

            var go = new GameObject();

            go.name = subSceneName;
            Selection.activeGameObject = go;

            var args = new SubSceneContextMenu.NewSubSceneArgs
            {
                target          = go,
                newSubSceneMode = mode
            };

            return(SubSceneContextMenu.CreateNewSubScene(go.name, args, interactionMode));
        }