forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotationSystem.cs
More file actions
47 lines (41 loc) · 1.43 KB
/
Copy pathRotationSystem.cs
File metadata and controls
47 lines (41 loc) · 1.43 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.Burst;
using Unity.Entities;
using Unity.Transforms;
namespace HelloCube.EnableableComponents
{
public partial struct RotationSystem : ISystem
{
float timer;
const float interval = 1.3f;
[BurstCompile]
public void OnCreate(ref SystemState state)
{
timer = interval;
state.RequireForUpdate<Execute.EnableableComponents>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
float deltaTime = SystemAPI.Time.DeltaTime;
timer -= deltaTime;
// Toggle the enabled state of every RotationSpeed
if (timer < 0)
{
foreach (var rotationSpeedEnabled in
SystemAPI.Query<EnabledRefRW<RotationSpeed>>()
.WithOptions(EntityQueryOptions.IgnoreComponentEnabledState))
{
rotationSpeedEnabled.ValueRW = !rotationSpeedEnabled.ValueRO;
}
timer = interval;
}
// The query only matches entities whose RotationSpeed is enabled.
foreach (var (transform, speed) in
SystemAPI.Query<RefRW<LocalTransform>, RefRO<RotationSpeed>>())
{
transform.ValueRW = transform.ValueRO.RotateY(
speed.ValueRO.RadiansPerSecond * deltaTime);
}
}
}
}