Unity ECS 纯代码生成Entity

Unity ECS 纯代码生成Entity,第1张

核心方法:EntityManager.CreateEntity()+ 多个重载 1. params : ComponentType[] types
	 Entity entity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(
            typeof(Translation),
            typeof(LocalToWorld),
            typeof(RenderMesh),
            typeof(Scale),
            typeof(Unit)
        );
2. CreateArchetype( ComponemtType tpye ,xxxx)

原型可挂载多个ComponentData,可配合NativeArray生成多个Entity

{
	var entityManager=World.DefaultGameObjectInjectionWorld.EntityManager;
	NativeArray<Entity> entityArray = new NativeArray<Entity>(10, Allocator.Temp);
    EntityArchetype entityArchetype = entityManager.CreateArchetype(typeof(RenderMesh),				   
    	typeof(LocalToWorld),typeof(Translation), typeof(RenderBounds), typeof(Rotation));
    entityManager.CreateEntity(entityArchetype,entityArray);
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/731977.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存