Entities v1.0.11
Unity v2022.3.0
参考地址:Iterate over component data with SystemAPI.Query | Entities | 1.0.11 (unity3d.com)
using Unity.Burst;
using Unity.Entities;
using Unity.Transforms;
[BurstCompile]
public partial struct CubeRotateSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
}
[BurstCompile]
public void OnDestroy(ref SystemState state)
{
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
float deltaTime = SystemAPI.Time.DeltaTime;
foreach (var (transform, speed) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<RotateSpeed>>())
{
transform.ValueRW = transform.ValueRO.RotateY(speed.ValueRO.rotateSpeed * deltaTime);
}
}
}
该文章展示了如何在Unity2022.3.0版本中利用EntitiesAPI和Burst编译器创建一个名为CubeRotateSystem的系统。该系统遍历并更新具有LocalTransform和RotateSpeed组件数据的游戏对象,根据RotateSpeed的值以Delta时间旋转Cube的Y轴。
3650

被折叠的 条评论
为什么被折叠?



