public void ConvertGameObject_HasOnlyTransform_ProducesEntityWithPositionAndRotation() { var scene = SceneManager.GetActiveScene(); var go = CreateGameObject("Test Conversion"); go.transform.localPosition = new Vector3(1, 2, 3); using (var blobAssetStore = new BlobAssetStore()) { var settings = GameObjectConversionSettings.FromWorld(World, blobAssetStore); GameObjectConversionUtility.ConvertScene(scene, settings); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact( new Translation { Value = new float3(1, 2, 3) }, new Rotation { Value = quaternion.identity }, new LocalToWorld { Value = go.transform.localToWorldMatrix })); } }
public void InactiveHierarchyBecomesPartOfLinkedEntityGroupSet() { var go = CreateGameObject(); var child = CreateGameObject(); var childChild = CreateGameObject(); child.SetActive(false); go.AddComponent <EntityRefTestDataAuthoring>().Value = child; child.transform.parent = go.transform; childChild.transform.parent = child.transform; var entity = ConvertGameObjectHierarchy(go, MakeDefaultSettings()); var childEntity = m_Manager.GetComponentData <EntityRefTestData>(entity).Value; EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EntityRefTestData, LinkedEntityGroup>(k_CommonComponents, entity), EntityMatch.Exact <Disabled, LinkedEntityGroup>(k_ChildComponents, childEntity), EntityMatch.Exact <Disabled> (k_ChildComponents)); // Conversion will automatically add a LinkedEntityGroup to all inactive children // so that when enabling them, the whole hierarchy will get enabled m_Manager.SetEnabled(m_Manager.GetComponentData <EntityRefTestData>(entity).Value, true); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EntityRefTestData, LinkedEntityGroup>(k_CommonComponents, entity), EntityMatch.Exact <LinkedEntityGroup>(k_ChildComponents, childEntity), EntityMatch.Exact(k_ChildComponents)); }
public void ConvertGameObject_WithFilteredBuildSettings_ConversionDoesntRun() { var scene = SceneManager.GetActiveScene(); var go = CreateGameObject("Test Conversion"); go.transform.localPosition = new Vector3(1, 2, 3); var config = BuildConfiguration.CreateInstance((bs) => { bs.hideFlags = HideFlags.HideAndDontSave; bs.SetComponent(new ConversionSystemFilterSettings("Unity.Transforms.Hybrid")); }); var conversionSettings = new GameObjectConversionSettings { DestinationWorld = World, BuildConfiguration = config, Systems = TestWorldSetup.GetDefaultInitSystemsFromEntitiesPackage(WorldSystemFilterFlags.GameObjectConversion).ToList() }; GameObjectConversionUtility.ConvertScene(scene, conversionSettings); // We still expect to find an Entity, just with nothing on it, because // entities are eagerly created for every GameObject even if no components // get converted on them. EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact()); }
public void GeneratedAuthoringComponent_WithMultipleReferences_ConvertsOnlyPrefab() { var go = CreateGameObject(); var authoringType = GetAuthoringComponentType <CodeGenManagedTestComponent>(); var c = go.AddComponent(authoringType); authoringType.GetField(nameof(CodeGenManagedTestComponent.Entities)).SetValue(c, new[] { LoadPrefab("Prefab"), null, CreateGameObject() }); LogAssert.Expect(LogType.Warning, new Regex(@"GameObject that was not included in the conversion")); Entity goEntity = default; Assert.DoesNotThrow(() => goEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, MakeDefaultSettings())); EntitiesAssert.Contains(m_Manager, EntityMatch.Exact <CodeGenManagedTestComponent>(goEntity, k_RootComponents)); var prefabEntity = m_Manager.GetComponentData <CodeGenManagedTestComponent>(goEntity).Entities[0]; EntitiesAssert.ContainsOnly(m_Manager, // gameobject created above EntityMatch.Exact <CodeGenManagedTestComponent>(goEntity, k_RootComponents), // referenced prefab EntityMatch.Exact <Prefab>(prefabEntity, new MockData(), k_RootComponents) ); }
public void GeneratedAuthoringComponent_ConvertsPrimitiveTypes() { var go = CreateGameObject(); var authoringType = GetAuthoringComponentType <CodeGenTestComponent>(); var c = go.AddComponent(authoringType); authoringType.GetField(nameof(CodeGenTestComponent.Bool)).SetValue(c, true); authoringType.GetField(nameof(CodeGenTestComponent.Int)).SetValue(c, 16); authoringType.GetField(nameof(CodeGenTestComponent.Char)).SetValue(c, 'x'); authoringType.GetField(nameof(CodeGenTestComponent.Enum)).SetValue(c, WorldFlags.Conversion | WorldFlags.Shadow); const float floatValue = 42.2f; authoringType.GetField(nameof(CodeGenTestComponent.Float)).SetValue(c, floatValue); Entity goEntity = default; Assert.DoesNotThrow(() => goEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, MakeDefaultSettings())); EntitiesAssert.ContainsOnly(m_Manager, // gameobject created above EntityMatch.Exact <CodeGenTestComponent>(goEntity, k_RootComponents) ); var component = m_Manager.GetComponentData <CodeGenTestComponent>(goEntity); Assert.AreEqual(true, component.Bool); Assert.AreEqual(16, component.Int); Assert.AreEqual(floatValue, component.Float); Assert.AreEqual('x', component.Char); Assert.AreEqual(WorldFlags.Conversion | WorldFlags.Shadow, component.Enum); }
public void ConvertGameObject_WithFilteredBuildSettings_ConversionDoesntRun() { var scene = SceneManager.GetActiveScene(); var go = CreateGameObject("Test Conversion"); go.transform.localPosition = new Vector3(1, 2, 3); var bs = ScriptableObject.CreateInstance <BuildSettings>(); bs.hideFlags = HideFlags.HideAndDontSave; bs.SetComponent(new ConversionSystemFilterSettings("Unity.Transforms.Hybrid")); var settings = new GameObjectConversionSettings { DestinationWorld = World, BuildSettings = bs }; GameObjectConversionUtility.ConvertScene(scene, settings); // We still expect to find an Entity, just with nothing on it, because // entities are eagerly created for every GameObject even if no components // get converted on them. EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact()); }
public void ConversionOfStaticGameObject() { var gameObject = CreateGameObject("", typeof(StaticOptimizeEntity)); var entity = ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <Static, LocalToWorld, LinkedEntityGroup>(entity)); }
public void ConversionOfGameObject() { var gameObject = CreateGameObject(); var entity = ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(entity, k_RootComponents)); }
public void ConversionOfPrefabIsEntityPrefab() { var entity = ConvertGameObjectHierarchy(LoadPrefab("Prefab"), MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <Prefab, MockData>(entity, k_RootComponents)); }
public void ConversionIsBuildingForEditor() { var gameObject = CreateGameObject("", typeof(TestComponentAuthoringIsBuildingForEditor)); ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Partial(new IntTestData(1))); }
public void EntitiesCanBeReferencedAcrossConversionRoots() { var a = CreateGameObject("a", DestructionBy.Test); var b = CreateGameObject("b", DestructionBy.Test); a.AddConvertAndDestroy(); b.AddConvertAndDestroy(); a.AddComponent <EntityRefTestDataAuthoring>().Value = b; b.AddComponent <EntityRefTestDataAuthoring>().Value = a; AwakeConversion(a, b); Entity entityX; Entity entityY; using (var entities = m_Manager.UniversalQuery.ToEntityArray(Allocator.TempJob)) { entityX = entities[0]; entityY = entities[1]; } EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(new EntityRefTestData { Value = entityX }, k_CommonComponents), EntityMatch.Exact(new EntityRefTestData { Value = entityY }, k_CommonComponents)); }
public void ConversionIgnoresMissingMonoBehaviour() { LogAssert.Expect(LogType.Warning, new Regex("missing")); var entity = ConvertGameObjectHierarchy(LoadPrefab("Prefab_MissingMB"), MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Any(entity)); }
public void PrefabHierarchy_WithStaticOptimizeEntity_ActuallyIsStatic() { var entity = ConvertGameObjectHierarchy(LoadPrefab("Prefab_Hierarchy_With_StaticOptimizeEntity"), MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <Prefab, Disabled>(entity, k_StaticRootComponents), EntityMatch.Exact <Prefab, Disabled>(k_StaticComponents)); }
public void IncrementalConversionLinkedGroup() { var conversionFlags = GameObjectConversionUtility.ConversionFlags.GameViewLiveLink | GameObjectConversionUtility.ConversionFlags.AssignName; // Parent (LinkedEntityGroup) (2 additional entities) // - Child (2 additional entities) // All reference parent game object var parent = CreateGameObject().AddComponent <EntityRefTestDataAuthoring>(); var child = CreateGameObject().AddComponent <EntityRefTestDataAuthoring>(); child.transform.parent = parent.transform; child.name = "child"; child.AdditionalEntityCount = 2; child.DeclareLinkedEntityGroup = false; child.Value = parent.gameObject; parent.name = "parent"; parent.AdditionalEntityCount = 2; parent.DeclareLinkedEntityGroup = true; parent.Value = parent.gameObject; using (var conversionWorld = GameObjectConversionUtility.ConvertIncrementalInitialize(SceneManager.GetActiveScene(), new GameObjectConversionSettings(World, conversionFlags))) { Entities.ForEach((ref EntityRefTestData data) => StringAssert.StartsWith("parent", m_Manager.GetName(data.Value))); var entity = EmptySystem.GetSingletonEntity <LinkedEntityGroup>(); // Parent (LinkedEntityGroup) (2 additional entities) // - Child (1 additional entities) // All reference child game object child.Value = child.gameObject; child.AdditionalEntityCount = 1; parent.Value = child.gameObject; GameObjectConversionUtility.ConvertIncremental(conversionWorld, new[] { child.gameObject }, conversionFlags); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EntityRefTestData>(entity, k_CommonComponents, EntityMatch.Component((LinkedEntityGroup[] group) => group.Length == 5)), EntityMatch.Exact <EntityRefTestData>(k_ChildComponents), EntityMatch.Exact <EntityRefTestData>(), EntityMatch.Exact <EntityRefTestData>(), EntityMatch.Exact <EntityRefTestData>()); // We expect there to still only be one linked entity group and it should be the same entity as before // since it is attached to the primary entity which is not getting destroyed. Assert.AreEqual(entity, EmptySystem.GetSingletonEntity <LinkedEntityGroup>()); Entities.ForEach((ref EntityRefTestData data) => StringAssert.StartsWith("child", m_Manager.GetName(data.Value))); foreach (var e in m_Manager.GetBuffer <LinkedEntityGroup>(entity).AsNativeArray()) { Assert.IsTrue(m_Manager.Exists(e.Value)); } } }
public void CreateAdditionalEntity_CreatesAdditionalEntity() { var go = CreateGameObject(); var entity = ConvertGameObjectHierarchy(go, MakeDefaultSettings().WithExtraSystem <CreateAdditionalEntitySystem>()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(entity, k_RootComponents), EntityMatch.Exact(new TestEntityData(0)) ); }
public void DisabledBehaviourStripping() { var gameObject = new GameObject(); gameObject.AddComponent <MockDataAuthoring>().enabled = false; gameObject.AddComponent <EntityRefTestDataAuthoring>().enabled = false; var strippedEntity = ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(strippedEntity, k_RootComponents)); }
public void ConversionOfNullGameObjectReference() { var go = CreateGameObject(); go.AddComponent <EntityRefTestDataAuthoring>(); var entity = ConvertGameObjectHierarchy(go, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <LocalToWorld, Translation, Rotation, LinkedEntityGroup>(entity, new EntityRefTestData())); }
public void SingleGameObject_RecordsCreatingDstEntity() { var go = CreateGameObject(); var entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, m_Settings); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Any(entity)); Assert.That(m_Events, Has.Length.EqualTo(1)); Assert.That(m_Events.EventsOfType <Entity>(), Is.EqualTo(new[] { JournalDataDebug.Create(go.GetInstanceID(), entity) })); }
public void DuplicateComponentOnRootGameObject() { var gameObject = new GameObject(); gameObject.AddComponent <EntityRefTestDataAuthoring>(); gameObject.AddComponent <EntityRefTestDataAuthoring>(); var convertedEntity = ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EntityRefTestData>(convertedEntity, k_RootComponents)); }
public void ConvertAndInject_Simple() { var go0 = CreateGameObject("level0"); var go1 = CreateGameObject("level1").ParentTo(go0); var go2 = CreateGameObject("level2").ParentTo(go1); go0.AddConvertAndInject(); AwakeConversion(go0); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(k_CommonComponents, typeof(Transform))); }
public void RedundantGameObjectToEntityConversionAreIgnored() { var go0 = CreateGameObject("level0", DestructionBy.Test); var go1 = CreateGameObject("level1", DestructionBy.Test).ParentTo(go0); go0.AddConvertAndDestroy(); AwakeConversion(go0); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(k_CommonComponents), EntityMatch.Exact(k_ChildComponents)); }
public void DuplicateComponentOnRootGameObject() { var gameObject = new GameObject(); gameObject.AddComponent <EntityRefTestDataAuthoring>(); gameObject.AddComponent <EntityRefTestDataAuthoring>(); Assert.DoesNotThrow(() => ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings())); LogAssert.Expect(LogType.Warning, new Regex(@"Missing entity for root GameObject")); EntitiesAssert.IsEmpty(m_Manager); }
public void GameObjectReferenceOutsideConvertedGroupWarning() { LogAssert.Expect(LogType.Warning, new Regex("not included in the conversion")); var go = CreateGameObject(); var notIncluded = CreateGameObject(); go.AddComponent <EntityRefTestDataAuthoring>().Value = notIncluded; var entity = ConvertGameObjectHierarchy(go, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(entity, new EntityRefTestData(), k_RootComponents)); }
public void ConversionOfInactiveStaticGameObject() { var gameObject = CreateGameObject("", typeof(StaticOptimizeEntity)); var child = CreateGameObject(""); child.transform.parent = gameObject.transform; gameObject.SetActive(false); var entity = ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <Disabled, Static, LocalToWorld, LinkedEntityGroup>(entity), EntityMatch.Exact <Disabled, Static, LocalToWorld>()); }
public void ConversionOfComponentDataProxy() { var gameObject = CreateGameObject(); gameObject.AddComponent <EcsTestProxy>().Value = new EcsTestData(5); var entity = ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, // this is the converted gameobject we created above EntityMatch.Exact(entity, new EcsTestData(5), k_RootComponents), // ComponentDataProxyBase requires GameObjectEntity which creates this redundant Entity into the destination world from its OnEnable // TODO: is this ^^ behavior right? EntityMatch.Exact <EcsTestData, Transform>()); }
public void ConversionOfPrefabSelfReference() { var go = CreateGameObject(); go.AddComponent <EntityRefTestDataAuthoring>().Value = LoadPrefab("Prefab_Reference_Self"); var entity = ConvertGameObjectHierarchy(go, MakeDefaultSettings()); var referenced = m_Manager.GetComponentData <EntityRefTestData>(entity).Value; EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <EntityRefTestData>(entity, k_RootComponents), EntityMatch.Exact <Prefab, MockData>(referenced, new EntityRefTestData { Value = referenced }, k_RootComponents)); }
public void InactiveConversion() { var gameObject = CreateGameObject(); var child = CreateGameObject(); child.transform.parent = gameObject.transform; gameObject.gameObject.SetActive(false); var entity = ConvertGameObjectHierarchy(gameObject, MakeDefaultSettings()); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <Disabled>(entity, k_RootComponents), EntityMatch.Exact <Disabled>(k_ChildComponents)); Assert.That(Entities.WithAll <Translation>().ToEntityQuery().CalculateEntityCount(), Is.Zero); }
public void GeneratedAuthoringComponent_WithNullReference_DoesNotThrow() { var go = CreateGameObject(); go.AddComponent(GetAuthoringComponentType <CodeGenTestComponent>()); Entity goEntity = default; Assert.DoesNotThrow(() => goEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(go, MakeDefaultSettings())); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <CodeGenTestComponent>(goEntity, k_RootComponents) ); Assert.AreEqual(Entity.Null, m_Manager.GetComponentData <CodeGenTestComponent>(goEntity).Entity); }
public void StopGameObjectToEntityConversion() { var go0 = CreateGameObject("level0", DestructionBy.Test); var go1 = CreateGameObject("level1").ParentTo(go0); var go2 = CreateGameObject("level2").ParentTo(go1); go0.AddConvertAndDestroy(); go1.AddStopConvert(); go2.AddConvertAndDestroy(); AwakeConversion(go0); LogAssert.Expect(LogType.Warning, new Regex("ConvertToEntity will be ignored because of a StopConvertToEntity higher in the hierarchy")); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact(k_CommonComponents)); }
public void DestroyEntity_WithInstantiatedPrefabHierarchy_DestroysEntireHierarchy() { var entity = ConvertGameObjectHierarchy(LoadPrefab("Prefab_Hierarchy"), MakeDefaultSettings()); var instance = m_Manager.Instantiate(entity); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <Prefab>(new MockData(100), k_RootComponents, entity), EntityMatch.Exact <Prefab>(new MockData(101), k_ChildComponents), EntityMatch.Exact(new MockData(100), k_RootComponents, instance), EntityMatch.Exact(new MockData(101), k_ChildComponents)); m_Manager.DestroyEntity(instance); EntitiesAssert.ContainsOnly(m_Manager, EntityMatch.Exact <Prefab>(new MockData(100), k_RootComponents, entity), EntityMatch.Exact <Prefab>(new MockData(101), k_ChildComponents)); }