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
41 lines (36 loc) · 1.27 KB
/
Copy pathRotationSystem.cs
File metadata and controls
41 lines (36 loc) · 1.27 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
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
namespace HelloCube.GameObjectSync
{
#if !UNITY_DISABLE_MANAGED_COMPONENTS
public partial struct RotationSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<DirectoryManaged>();
state.RequireForUpdate<ExecuteGameObjectSync>();
}
// This OnUpdate accesses managed objects, so it cannot be burst compiled.
public void OnUpdate(ref SystemState state)
{
var directory = SystemAPI.ManagedAPI.GetSingleton<DirectoryManaged>();
if (!directory.RotationToggle.isOn)
{
return;
}
float deltaTime = SystemAPI.Time.DeltaTime;
foreach (var (transform, speed, go) in
SystemAPI.Query<RefRW<LocalTransform>, RefRO<RotationSpeed>, RotatorGO>())
{
transform.ValueRW = transform.ValueRO.RotateY(
speed.ValueRO.RadiansPerSecond * deltaTime);
// Update the associated GameObject's transform to match.
go.Value.transform.rotation = transform.ValueRO.Rotation;
}
}
}
#endif
}