コード例 #1
0
        IEnumerator LiveLinkRemovesDeletedSubScene(bool usePlayMode, EnteringPlayMode useDomainReload = EnteringPlayMode.WithoutDomainReload)
        {
            {
                SetDomainReload(useDomainReload);
                var scene = CreateTmpScene();
                SubSceneTestsHelper.CreateSubSceneInSceneFromObjects("TestSubScene1", true, scene, () =>
                {
                    var go = new GameObject("TestGameObject");
                    go.AddComponent <TestPrefabComponentAuthoring>().IntValue = 1;
                    return(new List <GameObject> {
                        go
                    });
                });
            }

            yield return(GetEnterPlayMode(usePlayMode));

            {
                var subScene      = Object.FindObjectOfType <SubScene>();
                var w             = GetLiveLinkWorld(usePlayMode);
                var subSceneQuery = w.EntityManager.CreateEntityQuery(ComponentType.ReadWrite <SubScene>());
                Assert.Contains(subScene, subSceneQuery.ToComponentArray <SubScene>(), "SubScene was not loaded");

                var componentQuery = w.EntityManager.CreateEntityQuery(ComponentType.ReadWrite <TestPrefabComponent>());
                Assert.AreEqual(1, componentQuery.CalculateEntityCount(), "Expected a game object to be converted");
                Assert.AreEqual(1, componentQuery.GetSingleton <TestPrefabComponent>().IntValue);

                Object.DestroyImmediate(subScene.gameObject);

                yield return(null);

                Assert.IsTrue(subSceneQuery.IsEmptyIgnoreFilter, "SubScene was not unloaded");
                Assert.AreEqual(0, componentQuery.CalculateEntityCount());
            }
        }
        IEnumerator LiveLinkConvertsSubScenes(bool usePlayMode, EnteringPlayMode useDomainReload = EnteringPlayMode.WithoutDomainReload)
        {
            {
                SetDomainReload(useDomainReload);
                var scene = CreateTmpScene();
                SubSceneTestsHelper.CreateSubSceneInSceneFromObjects("TestSubScene1", true, scene, () =>
                {
                    var go = new GameObject("TestGameObject1");
                    go.AddComponent <TestComponentAuthoring>().IntValue = 1;
                    return(new List <GameObject> {
                        go
                    });
                });
                SubSceneTestsHelper.CreateSubSceneInSceneFromObjects("TestSubScene2", true, scene, () =>
                {
                    var go = new GameObject("TestGameObject2");
                    go.AddComponent <TestComponentAuthoring>().IntValue = 2;
                    return(new List <GameObject> {
                        go
                    });
                });
            }

            yield return(GetEnterPlayMode(usePlayMode));

            {
                var w = GetLiveLinkWorld(usePlayMode);

                var subSceneQuery   = w.EntityManager.CreateEntityQuery(ComponentType.ReadWrite <SubScene>());
                var subScenes       = subSceneQuery.ToComponentArray <SubScene>();
                var subSceneObjects = Object.FindObjectsOfType <SubScene>();
                foreach (var subScene in subSceneObjects)
                {
                    Assert.Contains(subScene, subScenes);
                }

                var componentQuery = w.EntityManager.CreateEntityQuery(ComponentType.ReadWrite <TestComponentAuthoring.UnmanagedTestComponent>());

                Assert.AreEqual(2, componentQuery.CalculateEntityCount(), "Expected a game object to be converted");
                using (var components = componentQuery.ToComponentDataArray <TestComponentAuthoring.UnmanagedTestComponent>(Allocator.TempJob))
                {
                    Assert.IsTrue(components.Contains(new TestComponentAuthoring.UnmanagedTestComponent {
                        IntValue = 1
                    }), "Failed to find contents of subscene 1");
                    Assert.IsTrue(components.Contains(new TestComponentAuthoring.UnmanagedTestComponent {
                        IntValue = 2
                    }), "Failed to find contents of subscene 2");
                }
            }
        }
        IEnumerator LiveLinkDestroysEntitiesWhenObjectMoves(bool usePlayMode, EnteringPlayMode useDomainReload = EnteringPlayMode.WithoutDomainReload)
        {
            var mainScene = CreateTmpScene();

            {
                SetDomainReload(useDomainReload);
                SubSceneTestsHelper.CreateSubSceneInSceneFromObjects("TestSubScene", true, mainScene, () =>
                {
                    var go = new GameObject("TestGameObject");
                    go.AddComponent <TestComponentAuthoring>();
                    return(new List <GameObject> {
                        go
                    });
                });
            }

            yield return(GetEnterPlayMode(usePlayMode));

            {
                var w = GetLiveLinkWorld(usePlayMode);

                var testTagQuery = w.EntityManager.CreateEntityQuery(ComponentType.ReadWrite <TestComponentAuthoring.UnmanagedTestComponent>());
                Assert.AreEqual(1, testTagQuery.CalculateEntityCount(), "Expected a game object to be converted");

                var go = Object.FindObjectOfType <TestComponentAuthoring>().gameObject;
                Undo.MoveGameObjectToScene(go, mainScene, "Test Move1");

                w.Update();

                Assert.AreEqual(0, testTagQuery.CalculateEntityCount(), "Expected an entity to be removed");
                Undo.PerformUndo();

                w.Update();

                Assert.AreEqual(1, testTagQuery.CalculateEntityCount(), "Expected a game object to be converted, undo failed");
                Undo.PerformRedo();

                w.Update();

                Assert.AreEqual(0, testTagQuery.CalculateEntityCount(), "Expected an entity to be removed, redo failed");
            }
        }
コード例 #4
0
        public static void SetUpOnce()
        {
            s_Assets.SetUp();

            var assetGuids = new List <GUID>();

            try
            {
                {
                    string path = s_Assets.GetNextPath(".asset");
                    AssetDatabase.CreateAsset(s_TempTexture = new Texture2D(64, 64), path);
                    s_TempTextureGuid = new GUID(AssetDatabase.AssetPathToGUID(path));
                    assetGuids.Add(s_TempTextureGuid);
                }
                {
                    string path = s_Assets.GetNextPath(".mat");
                    AssetDatabase.CreateAsset(s_TempMaterial = new Material(Shader.Find("Standard")), path);
                    s_TempMaterialGuid = new GUID(AssetDatabase.AssetPathToGUID(path));
                    assetGuids.Add(s_TempMaterialGuid);
                    s_TempMaterial.mainTexture = s_TempTexture;
                }

                var tempScenePath = s_Assets.GetNextPath(".unity");
                s_TempScene            = SubSceneTestsHelper.CreateScene(tempScenePath);
                s_SubSceneWithSections = SubSceneTestsHelper.CreateSubSceneInSceneFromObjects("SubScene", false, s_TempScene, () =>
                {
                    var go1 = new GameObject();
                    go1.AddComponent <SceneSectionComponent>().SectionIndex = 0;
                    var go2 = new GameObject();
                    go2.AddComponent <SceneSectionComponent>().SectionIndex = 2;
                    go2.AddComponent <TestComponentAuthoring>().Material    = s_TempMaterial;
                    return(new List <GameObject> {
                        go1, go2
                    });
                });

                {
                    var path = s_Assets.GetNextPath("LiveLinkBuildConfig.buildconfiguration");
                    BuildConfiguration.CreateAsset(path, config =>
                    {
                        config.SetComponent(new SceneList
                        {
                            SceneInfos = new List <SceneList.SceneInfo>
                            {
                                new SceneList.SceneInfo
                                {
                                    Scene = GlobalObjectId.GetGlobalObjectIdSlow(AssetDatabase.LoadAssetAtPath <SceneAsset>(tempScenePath))
                                }
                            }
                        });
                    });
                    s_LiveLinkBuildConfigGuid = new GUID(AssetDatabase.AssetPathToGUID(path));
                }
            }
            catch
            {
                s_Assets.TearDown();
                throw;
            }

            // This call ensures that the asset worker is already running and no test times out because we're still
            // waiting for the asset worker. Effectively this doesn't change the runtime that much since we will have
            // to wait for the import to finish in most of the tests anyway.
            GetLiveLinkArtifactHash(s_TempMaterialGuid, ImportMode.Synchronous);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            s_TempAssetGuids = assetGuids.ToArray();
        }
 SubScene CreateSubSceneFromObjects(string name, bool keepOpen, Func <List <GameObject> > createObjects) =>
 SubSceneTestsHelper.CreateSubSceneInSceneFromObjects(name, keepOpen, CreateTmpScene(), createObjects);
 SubScene CreateEmptySubScene(string name, bool keepOpen) => SubSceneTestsHelper.CreateSubSceneInSceneFromObjects(name, keepOpen, CreateTmpScene());