-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathCubeMovementSystem.cs
More file actions
47 lines (42 loc) · 1.31 KB
/
CubeMovementSystem.cs
File metadata and controls
47 lines (42 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 CubeMovementSystem : 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
{
fixedCubeSpeed = SystemAPI.Time.DeltaTime * 4
};
state.Dependency = moveJob.ScheduleParallel(state.Dependency);
}
[BurstCompile]
[WithAll(typeof(Simulate))]
partial struct MoveCubeJob : IJobEntity
{
public float fixedCubeSpeed;
public void Execute(in 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);
}
}
}