protected override JobHandle OnUpdate(JobHandle inputDeps) { ArchetypeChunkEntityType archetypeChunkEntityType = EntityManager.GetArchetypeChunkEntityType(); var exampleComponentType = GetArchetypeChunkComponentType <ExampleComponent>(); var job = new TestHashSetBufferJob { DeltaTime = Time.DeltaTime, EntityType = archetypeChunkEntityType, ExampleComponentType = exampleComponentType, Buffer = DynamicBufferHashSet.GetDynamicBufferHashSetHandler <TestHashSetBufferElement>(this), }; return(job.Schedule(_query, inputDeps)); }
private void Start() { _entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; EntityArchetype archetype = _entityManager.CreateArchetype(typeof(ExampleComponent)); _entity = _entityManager.CreateEntity(archetype); if (!_jobSystemTest) { _entityManager.AddComponent <ComponentSystemTag>(_entity); } DynamicBufferHashSet.AddDynamicBufferHashSet <TestHashSetBufferElement>(_entityManager, _entity, 32); }
protected override void OnUpdate() { var entities = _query.ToEntityArray(Allocator.TempJob); var exampleComponents = _query.ToComponentDataArray <ExampleComponent>(Allocator.TempJob); for (var i = 0; i < entities.Length; i++) { var exampleComponent = exampleComponents[i]; var entity = entities[i]; exampleComponent.Time += Time.DeltaTime; if (DynamicBufferHashSet.Length <TestHashSetBufferElement>(EntityManager, entity) == 0 && !exampleComponent.Remove && exampleComponent.Time > 3f && exampleComponent.Time < 5f) { DynamicBufferHashSet.TryAdd(EntityManager, entity, new TestHashSetBufferElement { Value = 12345 }); DynamicBufferHashSet.TryAdd(EntityManager, entity, new TestHashSetBufferElement { Value = 78901 }); DynamicBufferHashSet.TryAdd(EntityManager, entity, new TestHashSetBufferElement { Value = 5674654 }); } if (exampleComponent.Remove) { DynamicBufferHashSet.TryRemove(EntityManager, entity, new TestHashSetBufferElement { Value = 78901 }); DynamicBufferHashSet.TryRemove(EntityManager, entity, new TestHashSetBufferElement { Value = 5674654 }); } if (exampleComponent.Time > 7f) { exampleComponent.Remove = true; } if (exampleComponent.Time > 10f && exampleComponent.Remove) { exampleComponent.Remove = false; exampleComponent.Check1 = DynamicBufferHashSet.Contains(EntityManager, entity, new TestHashSetBufferElement { Value = 12345 }); exampleComponent.Check2 = DynamicBufferHashSet.Contains(EntityManager, entity, new TestHashSetBufferElement { Value = 54321 }); } exampleComponents[i] = exampleComponent; } _query.CopyFromComponentDataArray(exampleComponents); entities.Dispose(); exampleComponents.Dispose(); }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { NativeArray <Entity> entities = chunk.GetNativeArray(EntityType); NativeArray <ExampleComponent> exampleComponents = chunk.GetNativeArray(ExampleComponentType); for (int i = exampleComponents.Length - 1; i >= 0; i--) { var exampleComponent = exampleComponents[i]; exampleComponent.Time += DeltaTime; Buffer.Init(entities[i]); if (Buffer.Length == 0 && !exampleComponent.Remove && exampleComponent.Time > 3f && exampleComponent.Time < 5f) { DynamicBufferHashSet.TryAdd(Buffer, new TestHashSetBufferElement { Value = 12345 }); DynamicBufferHashSet.TryAdd(Buffer, new TestHashSetBufferElement { Value = 78901 }); DynamicBufferHashSet.TryAdd(Buffer, new TestHashSetBufferElement { Value = 5674654 }); } if (exampleComponent.Remove) { DynamicBufferHashSet.TryRemove(Buffer, new TestHashSetBufferElement { Value = 78901 }); DynamicBufferHashSet.TryRemove(Buffer, new TestHashSetBufferElement { Value = 5674654 }); } if (exampleComponent.Time > 7f) { exampleComponent.Remove = true; } if (exampleComponent.Time > 10f && exampleComponent.Remove) { exampleComponent.Remove = false; exampleComponent.Check1 = DynamicBufferHashSet.Contains(Buffer, new TestHashSetBufferElement { Value = 12345 }); exampleComponent.Check2 = DynamicBufferHashSet.Contains(Buffer, new TestHashSetBufferElement { Value = 54321 }); } exampleComponents[i] = exampleComponent; } }