人們做網站怎么賺錢seo系統(tǒng)優(yōu)化
文章目錄
- 一.Chunk和Archetype
- 什么是Chunk?
- 什么是ArchType
- 二.Archetype創(chuàng)建
- 1.創(chuàng)建實體
- 2.創(chuàng)建并添加組件
- 3.批量創(chuàng)建
- 三.多線程數組NativeArray
本次介紹的內容如下:
一.Chunk和Archetype
什么是Chunk?
Chunk是一個空間,ECS系統(tǒng)會將相同類型的實體放在Chunk中.當一個Chunk放滿后則會創(chuàng)建相同類型的一個Chunk.
當一個Chunk存滿了以后會創(chuàng)建新的Chunk進行儲存.
什么是ArchType
相同類型的一系列Chunk塊稱為ArchType
二.Archetype創(chuàng)建
1.創(chuàng)建實體
當需要創(chuàng)建大量實體的時候,建議使用此方式效率會更高
EntityArchetype tempEntityArchetype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype();
2.創(chuàng)建并添加組件
并可以在創(chuàng)建時添加實體
EntityArchetype tempEntityArchetype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(typeof(PrintComponentData1), typeof(RotationEulerXYZAuthoring3));
3.批量創(chuàng)建
使用For可以實現多個創(chuàng)建
for (int i = 0; i < 200; i++)
{EntityArchetype tempEntityArchetype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(typeof(PrintComponentData1), typeof(RotationEulerXYZAuthoring3));
}
三.多線程數組NativeArray
在JobSystem多線程操作中不允許使用普通的List數組,因而我們需要使用NativeArray進行存儲操作
EntityArchetype tempEntityArchetype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(typeof(PrintComponentData1), typeof(RotationEulerXYZAuthoring3));
// 使用NativeArray創(chuàng)建實體
NativeArray<Entity> tempNativeArray = new NativeArray<Entity>(5, Allocator.Temp);
World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchetype, tempNativeArray);