protected override JobHandle OnUpdate(JobHandle inputDeps) { Entities.WithStructuralChanges().ForEach((Entity entity, in RoadSpawner roadSpawner, in LocalToWorld location) => { inputDeps.Complete(); EntityManager.DestroyEntity(entity); NativeArray <Entity> instances = new NativeArray <Entity>((int)roadSpawner.Length, Allocator.TempJob, NativeArrayOptions.ClearMemory); EntityManager.Instantiate(roadSpawner.Prefab, instances); inputDeps = new SetComponentDataJob { Instances = instances, Translations = GetComponentDataFromEntity <Translation>() }.Schedule((int)roadSpawner.Length, 1, default);
/// <inheritdoc /> protected override JobHandle SetComponentData(EntityManager entityManager, NativeArray <Entity> entities) { var componentType = entityManager.GetArchetypeChunkComponentType <T>(false); var chunks = this.query.CreateArchetypeChunkArray(Allocator.TempJob); int startIndex = 0; var handles = new NativeArray <JobHandle>(this.queues.Count, Allocator.TempJob); // Create a job for each queue. This is designed so that these jobs can run simultaneously. for (var index = 0; index < this.queues.Count; index++) { var queue = this.queues[index]; var job = new SetComponentDataJob { Chunks = chunks, Queue = queue, StartIndex = startIndex, ComponentType = componentType, }; startIndex += queue.Count; handles[index] = job.Schedule(); } var handle = JobHandle.CombineDependencies(handles); handles.Dispose(); // Deallocate the chunk array handle = new DeallocateJob <NativeArray <ArchetypeChunk> >(chunks).Schedule(handle); return(handle); }