public unsafe NativeArray <Entity> GetNativeArray(ArchetypeChunkEntityType archetypeChunkEntityType) { AtomicSafetyHandle.CheckReadAndThrow(archetypeChunkEntityType.m_Safety); int count = this.m_Chunk.Count; NativeArray <Entity> array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Entity>((void *)(&this.m_Chunk.Buffer.FixedElementField + this.m_Chunk.Archetype.Offsets[0]), count, Allocator.None); NativeArrayUnsafeUtility.SetAtomicSafetyHandle <Entity>(ref array, archetypeChunkEntityType.m_Safety); return(array); }
public NativeArray <Entity> ToEntityArray(Allocator allocator, out JobHandle jobhandle) { #if ENABLE_UNITY_COLLECTIONS_CHECKS var entityType = new ArchetypeChunkEntityType(m_SafetyManager.GetSafetyHandle(TypeManager.GetTypeIndex <Entity>(), true)); #else var entityType = new ArchetypeChunkEntityType(); #endif return(ComponentChunkIterator.CreateEntityArray(m_GroupData->MatchingArchetypes, allocator, entityType, this, ref m_Filter, out jobhandle, GetDependency())); }
/// <summary> /// Creates a NativeArray containing the selected entities. /// </summary> /// <remarks>This version of the function blocks until the Job used to fill the array is complete.</remarks> /// <param name="allocator">The type of memory to allocate.</param> /// <returns>An array containing all the entities selected by the EntityQuery.</returns> public NativeArray <Entity> ToEntityArray(Allocator allocator) { #if ENABLE_UNITY_COLLECTIONS_CHECKS var entityType = new ArchetypeChunkEntityType(m_SafetyManager->GetEntityManagerSafetyHandle()); #else var entityType = new ArchetypeChunkEntityType(); #endif JobHandle job; var res = ComponentChunkIterator.CreateEntityArray(m_QueryData->MatchingArchetypes, allocator, entityType, this, ref m_Filter, out job, GetDependency()); job.Complete(); return(res); }
public NativeArray <Entity> GetNativeArray(ArchetypeChunkEntityType archetypeChunkEntityType) { #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.CheckReadAndThrow(archetypeChunkEntityType.m_Safety); #endif var archetype = m_Chunk->Archetype; var buffer = m_Chunk->Buffer; var length = m_Chunk->Count; var startOffset = archetype->Offsets[0]; var result = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Entity>(buffer + startOffset, length, Allocator.None); #if ENABLE_UNITY_COLLECTIONS_CHECKS NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref result, archetypeChunkEntityType.m_Safety); #endif return(result); }
public NativeArray <Entity> GetAllEntities(Allocator allocator = 2) { this.BeforeStructuralChange(); EntityArchetypeQuery query1 = new EntityArchetypeQuery(); query1.Any = Array.Empty <ComponentType>(); query1.None = Array.Empty <ComponentType>(); query1.All = Array.Empty <ComponentType>(); EntityArchetypeQuery query = query1; EntityArchetypeQuery query4 = new EntityArchetypeQuery { Any = Array.Empty <ComponentType>(), None = Array.Empty <ComponentType>() }; query4.All = new ComponentType[] { typeof(Disabled) }; EntityArchetypeQuery query2 = query4; query4 = new EntityArchetypeQuery { Any = Array.Empty <ComponentType>(), None = Array.Empty <ComponentType>() }; query4.All = new ComponentType[] { typeof(Prefab) }; EntityArchetypeQuery query3 = query4; NativeList <EntityArchetype> foundArchetypes = new NativeList <EntityArchetype>(Allocator.TempJob); this.AddMatchingArchetypes(query, foundArchetypes); this.AddMatchingArchetypes(query2, foundArchetypes); this.AddMatchingArchetypes(query3, foundArchetypes); NativeArray <ArchetypeChunk> chunks = this.CreateArchetypeChunkArray(foundArchetypes, Allocator.TempJob); NativeArray <Entity> thisArray = new NativeArray <Entity>(ArchetypeChunkArray.CalculateEntityCount(chunks), allocator, NativeArrayOptions.ClearMemory); ArchetypeChunkEntityType archetypeChunkEntityType = this.GetArchetypeChunkEntityType(); int start = 0; int num3 = 0; while (true) { if (num3 >= chunks.Length) { chunks.Dispose(); foundArchetypes.Dispose(); return(thisArray); } NativeArray <Entity> nativeArray = chunks[num3].GetNativeArray(archetypeChunkEntityType); thisArray.Slice <Entity>(start, nativeArray.Length).CopyFrom(nativeArray); start += nativeArray.Length; num3++; } }
/// <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); }