public void TagQueryFindsCorrectNumberOfGameObjects() { const int copyCount = 5; var gameObject = new GameObject(); gameObject.AddComponent <ExampleTag>(); for (var i = 0; i < copyCount - 1; i++) { Object.Instantiate(gameObject); } var gameObject2 = new GameObject(); gameObject2.AddComponent <ExampleTag2>(); for (var i = 0; i < copyCount - 1; i++) { Object.Instantiate(gameObject2); } var tagManager = RandomizerTagManager.singleton; var queriedObjects = tagManager.Query <ExampleTag>().ToArray(); Assert.AreEqual(queriedObjects.Length, copyCount); queriedObjects = tagManager.Query <ExampleTag2>().ToArray(); Assert.AreEqual(queriedObjects.Length, copyCount); queriedObjects = tagManager.Query <ExampleTag>(true).ToArray(); Assert.AreEqual(queriedObjects.Length, copyCount * 2); }
public void TagInheritanceWorksInTagQueries() { const int copyCount = 5; var gameObject = new GameObject(); gameObject.AddComponent <BaseTag>(); for (var i = 0; i < copyCount - 1; i++) { Object.Instantiate(gameObject); } var gameObject2 = new GameObject(); gameObject2.AddComponent <DerivedTag>(); for (var i = 0; i < copyCount - 1; i++) { Object.Instantiate(gameObject2); } var tagManager = RandomizerTagManager.singleton; var queriedBaseTags = tagManager.Query <BaseTag>().ToArray(); Assert.AreEqual(queriedBaseTags.Length, copyCount); var queriedDerivedTags = tagManager.Query <DerivedTag>().ToArray(); Assert.AreEqual(queriedDerivedTags.Length, copyCount); queriedBaseTags = tagManager.Query <BaseTag>(true).ToArray(); Assert.AreEqual(queriedBaseTags.Length, copyCount * 2); }
public void TestInstantiateAtActivated(bool isActivated) { GraphBuilder.VariableHandle handle = default; SetupTestGraphDefinitionMultipleFrames((b, _) => { handle = b.BindVariableToDataIndex("TestEntity"); var onUpdate = b.AddNode(new OnUpdate()); var enabled = b.AddNode(new ConstantBool { Value = true }); var instantiateAt = b.AddNode(new InstantiateAt()); var constantActivatedValue = b.AddNode(new ConstantBool { Value = isActivated }); b.BindVariableToInput(handle, instantiateAt.Prefab); b.CreateEdge(enabled.ValuePort, onUpdate.Enabled); b.CreateEdge(onUpdate.Output, instantiateAt.Input); b.CreateEdge(constantActivatedValue.ValuePort, instantiateAt.Activate); }, (manager, entity, index) => { var instance = GetGraphInstance(entity); instance.WriteValueToDataSlot(handle.DataIndex, entity); }, (manager, entity, index) => { var e = manager.GetAllEntities().Last(); Assert.AreEqual(manager.GetEnabled(e), isActivated); }); }
/// <summary> Returns writer instance. </summary> /// <returns> The writer instance. </returns> public ThreadWriter AsThreadWriter() { #if ENABLE_UNITY_COLLECTIONS_CHECKS Assert.IsTrue(this._useThreads, "Not in thread mode."); #endif return(new ThreadWriter(ref this)); }
/// <summary> Returns writer instance. </summary> /// <returns> The writer instance. </returns> public IndexWriter AsIndexWriter() { #if ENABLE_UNITY_COLLECTIONS_CHECKS Assert.IsFalse(this._useThreads, "Not in index mode."); #endif return(new IndexWriter(ref this)); }
public static ulong GenerateStableValueForMathOp(MathOperationsMetaData.MathOps mathOp, ValueType returnType, ValueType[] paramTypes) { uint signature = GenerateSignatureFlag(returnType, paramTypes); uint op = (uint)mathOp; Assert.AreNotEqual((op & k_IsCustomOpBit), k_IsCustomOpBit, $"Op {mathOp} uses the {nameof(k_IsCustomOpBit)} bit"); ulong result = ((ulong)signature << 32) | op; return(result); }
internal static ulong GenerateStableValueForCustomOp(MathOperationsMetaData.CustomOps customOp, Runtime.ValueType returnType, Runtime.ValueType[] paramTypes) { uint signature = GenerateSignatureFlag(returnType, paramTypes); uint op = (uint)customOp; Assert.AreNotEqual((op & k_IsCustomOpBit), k_IsCustomOpBit, $"Op {customOp} uses the {nameof(k_IsCustomOpBit)} bit"); op |= k_IsCustomOpBit; ulong result = ((ulong)signature << 32) | op; return(result); }
public void Disposed_world_cleans_provider() { using (var mockWorld = MockWorld.Create(new MockWorld.Options())) { mockWorld.Step(world => { world.Connection.CreateEntity(entityId, GetTemplate()); }); Assert.AreEqual(1, ReferenceProvider <string> .Count); } Assert.AreEqual(0, ReferenceProvider <string> .Count); }
public void TagQueryFindsCorrectNumberOfGameObjects() { const int copyCount = 5; var gameObject = new GameObject(); gameObject.AddComponent <ExampleTag>(); for (var i = 0; i < copyCount - 1; i++) { Object.Instantiate(gameObject); } var queriedObjects = m_Scenario.tagManager.Query <ExampleTag>().ToArray(); Assert.AreEqual(queriedObjects.Length, copyCount); }
public void ShouldWriteImportedMesh() { const string primitiveName = "Books"; const string tmpFileName = "ShouldWriteImportedMesh.vpx"; var go = VpxImportEngine.ImportIntoScene(VpxPath.Primitive, options: ConvertOptions.SkipNone); var ta = go.GetComponent <TableComponent>(); ta.TableContainer.Save(tmpFileName); var writtenTable = FileTableContainer.Load(tmpFileName); var writtenMesh = writtenTable.Primitive(primitiveName).GetMesh(); var table = FileTableContainer.Load(VpxPath.Primitive); var originalMesh = table.Primitive(primitiveName).GetMesh(); Assert.IsTrue(originalMesh.SomewhatEquals(writtenMesh, 0.9f, 4)); File.Delete(tmpFileName); Object.DestroyImmediate(go); }
public void Removed_component_disposes_reference() { var template = GetTemplate(); using (var mockWorld = MockWorld.Create(new MockWorld.Options())) { mockWorld .Step(world => { world.Connection.CreateEntity(entityId, template); }) .Step(world => { Assert.AreEqual(1, ReferenceProvider <string> .Count); world.Connection.RemoveEntityAndComponents(entityId, template); }); Assert.AreEqual(0, ReferenceProvider <string> .Count); } }
public void TestInstantiateAtNonUniformScale(bool hasComponent) { GraphBuilder.VariableHandle handle = default; var scale = new float3(1f, 2f, 4f); SetupTestGraphDefinitionMultipleFrames((b, _) => { handle = b.BindVariableToDataIndex("TestEntity"); var onUpdate = b.AddNode(new OnUpdate()); var enabled = b.AddNode(new ConstantBool { Value = true }); var instantiateAt = b.AddNode(new InstantiateAt()); var scaleValue = b.AddNode(new ConstantFloat3 { Value = scale }); b.BindVariableToInput(handle, instantiateAt.Prefab); b.CreateEdge(enabled.ValuePort, onUpdate.Enabled); b.CreateEdge(onUpdate.Output, instantiateAt.Input); b.CreateEdge(scaleValue.ValuePort, instantiateAt.Scale); }, (manager, entity, index) => { var instance = GetGraphInstance(entity); instance.WriteValueToDataSlot(handle.DataIndex, entity); if (hasComponent) { manager.AddComponent <Scale>(entity); manager.AddComponent <NonUniformScale>(entity); } }, (manager, entity, index) => { var e = manager.GetAllEntities().Last(); Assert.IsTrue(manager.GetComponentData <NonUniformScale>(e).Value.Equals(scale)); Assert.IsFalse(manager.HasComponent <Scale>(e)); }); }
public void TagQueriesPreserveInsertionOrder() { const int copyCount = 5; const int destroyCount = 3; var testObj = new GameObject(); testObj.AddComponent <BaseTag>(); var testObjects = new List <GameObject> { testObj }; for (var i = 0; i < copyCount - 1; i++) { testObjects.Add(Object.Instantiate(testObj)); } for (var i = 0; i < destroyCount; i++) { Object.DestroyImmediate(testObjects[1]); testObjects.RemoveAt(1); } for (var i = 0; i < copyCount + destroyCount; i++) { testObjects.Add(Object.Instantiate(testObj)); } var tagManager = RandomizerTagManager.singleton; var tags = tagManager.Query <BaseTag>(); var tagsArray = tags.ToArray(); var index = 0; foreach (var tag in tagsArray) { Assert.AreEqual(tag, testObjects[index++].GetComponent <BaseTag>()); } }
public void TestInstantiateAtRotation(bool hasComponent) { GraphBuilder.VariableHandle handle = default; var rotation = new quaternion(1f, 2f, 3f, 4f); SetupTestGraphDefinitionMultipleFrames((b, _) => { handle = b.BindVariableToDataIndex("TestEntity"); var onUpdate = b.AddNode(new OnUpdate()); var enabled = b.AddNode(new ConstantBool { Value = true }); var instantiateAt = b.AddNode(new InstantiateAt()); var constantPositionValue = b.AddNode(new ConstantQuaternion { Value = rotation }); b.BindVariableToInput(handle, instantiateAt.Prefab); b.CreateEdge(enabled.ValuePort, onUpdate.Enabled); b.CreateEdge(onUpdate.Output, instantiateAt.Input); b.CreateEdge(constantPositionValue.ValuePort, instantiateAt.Rotation); }, (manager, entity, index) => { var instance = GetGraphInstance(entity); instance.WriteValueToDataSlot(handle.DataIndex, entity); if (hasComponent) { manager.AddComponent <Rotation>(entity); } }, (manager, entity, index) => { var e = manager.GetAllEntities().Last(); Assert.IsTrue(manager.GetComponentData <Rotation>(e).Value.Equals(rotation)); }); }