unity要学ecs吗_学习Unity 2019 ECS 框架(一)

HelloCube

ForEach

ForEach是一个合体的Cubes共同旋转的简单场景。

RotatingCube挂载了RotationSpeed Convert to Entity,将该GameObject转换为Entity,该物体的GameEngine Component是Transform,作为一个旋转单位,保存为实体貌似也是正确的,ECS中C作为数据集合,作为rotation component我认为也是可以的(更正:RotationSpeedAuthoring没有处理旋转,只是单纯记了个数据,因此它不是Component)。

public class RotationSpeedSystem_ForEach : ComponentSystem

对应ECS中的Systsem,也是Component,Unity ECS竟然可以一个脚本同时作为System和Component,此处处理的RotationCube的旋转,是个Component,同时这个场景中只有单个旋转需要处理,同时作为System专门处理物体旋转也行。

RotationSpeedAuthoring_ForEach继承了MonoBehaviour,因此需要在场景内的GameObject上挂载,接着它又实现了IConvertGameObjectToEntity接口,里面只有一个接口方法void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem);

这个接口是转化为实体,将GameObject的Behaviour转化为实体?不应该是Component么,Convert方法里new RotationSpeed_ForEach,这应该是个真正的实体了。

public voidConvert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)

{var data = new RotationSpeed_ForEach { RadiansPerSecond =math.radians(DegreesPerSecond) };

dstManager.AddComponentData(entity, data);

}

EntityManager在Unity.Entities命名空间下,里面有各种AddComponent/AddComponentData方法,Convert实例化了RotationSpeed_ForEach,关于RotationSpeed_ForEach它属于Component,实现了IComponentData接口,这个接口非常简单==过于简单,啥都没有只是说了这个接口的含义,嗯,长成这样

namespaceUnity.Entities

{public interfaceIComponentData

{

}

}

这样看来Unity的ECS框架和普通ECS很不一样,从Component可以直接创建Entity,我认为继承自MonoBehavious的类是组件࿰

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值