using Unity.Entities;using Unity.Mathematics;using Unity.NetCode;using Unity.Transforms;using Unity.Collections;using Unity.Burst;[UpdateInGroup(typeof(PredictedSimulationSystemGroup))][BurstCompile]public partial struct MoveCubeSystem : ISystem{[BurstCompile]public void OnCreate(ref SystemState state){var builder = new EntityQueryBuilder(Allocator.Temp).WithAll<Simulate>().WithAll<CubeInput>().WithAllRW<LocalTransform>();var query = state.GetEntityQuery(builder);state.RequireForUpdate(query);}[BurstCompile]public void OnUpdate(ref SystemState state){var moveJob = new MoveCubeJob{tick = SystemAPI.GetSingleton<NetworkTime>().ServerTick,fixedCubeSpeed = SystemAPI.Time.DeltaTime * 4};state.Dependency = moveJob.ScheduleParallel(state.Dependency);}[BurstCompile][WithAll(typeof(Simulate))]partial struct MoveCubeJob : IJobEntity{public NetworkTick tick;public float fixedCubeSpeed;public void Execute(CubeInput playerInput, ref LocalTransform trans){var moveInput = new float2(playerInput.Horizontal, playerInput.Vertical);moveInput = math.normalizesafe(moveInput) * fixedCubeSpeed;trans.Position += new float3(moveInput.x, 0, moveInput.y);}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。