/// <summary> /// Creates a NativeArray containing the entities in a given EntityQuery. /// </summary> /// <param name="matchingArchetypes">List of matching archetypes.</param> /// <param name="allocator">Allocator to use for the array.</param> /// <param name="type">An atomic safety handle required by GatherEntitiesJob so it can call GetNativeArray() on chunks.</param> /// <param name="entityQuery">EntityQuery to gather entities from.</param> /// <param name="filter">EntityQueryFilter for calculating the length of the output array.</param> /// <param name="jobHandle">Handle to the GatherEntitiesJob job used to fill the output array.</param> /// <param name="dependsOn">Handle to a job this GatherEntitiesJob must wait on.</param> /// <returns>NativeArray of the entities in a given EntityQuery.</returns> public static NativeArray <Entity> CreateEntityArray(UnsafeMatchingArchetypePtrList matchingArchetypes, Allocator allocator, ArchetypeChunkEntityType type, EntityQuery entityQuery, ref EntityQueryFilter filter, out JobHandle jobHandle, JobHandle dependsOn) { var entityCount = CalculateEntityCount(matchingArchetypes, ref filter); var job = new GatherEntitiesJob { EntityType = type, Entities = new NativeArray <Entity>(entityCount, allocator) }; jobHandle = job.Schedule(entityQuery, dependsOn); return(job.Entities); }
/// <summary> /// Creates a NativeArray containing the entities in a given ComponentGroup. /// </summary> /// <param name="firstMatchingArchetype">First node of MatchingArchetypes linked list.</param> /// <param name="allocator">Allocator to use for the array.</param> /// <param name="type">An atomic safety handle required by GatherEntitiesJob so it can call GetNativeArray() on chunks.</param> /// <param name="componentGroup">ComponentGroup to gather entities from.</param> /// <param name="filter">ComponentGroupFilter for calculating the length of the output array.</param> /// <param name="jobHandle">Handle to the GatherEntitiesJob job used to fill the output array.</param> /// <param name="dependsOn">Handle to a job this GatherEntitiesJob must wait on.</param> /// <returns>NativeArray of the entities in a given ComponentGroup.</returns> public static NativeArray <Entity> CreateEntityArray(MatchingArchetypes *firstMatchingArchetype, Allocator allocator, ArchetypeChunkEntityType type, ComponentGroup componentGroup, ref ComponentGroupFilter filter, out JobHandle jobHandle, JobHandle dependsOn) { var entityCount = CalculateLength(firstMatchingArchetype, ref filter); var job = new GatherEntitiesJob { EntityType = type, Entities = new NativeArray <Entity>(entityCount, allocator) }; jobHandle = job.Schedule(componentGroup, dependsOn); return(job.Entities); }