今天我们来研究一下第三个Sample
HelloCube_03_IJobChunk
RotationSpeed.cs 和 RotationSpeedProxy.cs 没有变化,上篇也介绍了作用,现在就不赘述了
我们直接来看RotationSpeedSystem.cs
这个类继承于JobComponentSystem抽象类
我们来读读代码:
OnCreate方法
这里复写了OnCreate方法,在此方法中保存了指定实体的查询条件
RotationSpeedJob结构体
结构体继承于IJobChunk
struct RotationSpeedJob : IJobChunk
在这个结构体中保存了Execute方法执行所需的数据
1. 每帧执行时间,用于平滑旋转
public float DeltaTime;
2.储存Rotation 原型块的组件类型为读写
public ArchetypeChunkComponentType<Rotation> RotationType;
3.储存RotationSpeed 原型块的组件类型为只读
[ReadOnly] public ArchetypeChunkComponentType<RotationSpeed> RotationSpeedType;
最后看一下执行方法 Execute
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
参数1 ArchetypeChunk