本次介绍的内容如下:

Chunk是一个空间,ECS系统会将相同类型的实体放在Chunk中.当一个Chunk放满后则会创建相同类型的一个Chunk.
当一个Chunk存满了以后会创建新的Chunk进行储存.
相同类型的一系列Chunk块称为ArchType

当需要创建大量实体的时候,建议使用此方式效率会更高
EntityArchetype tempEntityArchetype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype();
并可以在创建时添加实体
EntityArchetype tempEntityArchetype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(typeof(PrintComponentData1), typeof(RotationEulerXYZAuthoring3));
使用For可以实现多个创建
for (int i = 0; i < 200; i++)
{
EntityArchetype tempEntityArchetype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(typeof(PrintComponentData1), typeof(RotationEulerXYZAuthoring3));
}
在JobSystem多线程操作中不允许使用普通的List数组,因而我们需要使用NativeArray进行存储操作
EntityArchetype tempEntityArchetype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(typeof(PrintComponentData1), typeof(RotationEulerXYZAuthoring3));
// 使用NativeArray创建实体
NativeArray<Entity> tempNativeArray = new NativeArray<Entity>(5, Allocator.Temp);
World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchetype, tempNativeArray);