forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalRotationSpeedSystem.cs
More file actions
52 lines (47 loc) · 1.71 KB
/
Copy pathLocalRotationSpeedSystem.cs
File metadata and controls
52 lines (47 loc) · 1.71 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
48
49
50
51
52
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
namespace Samples.Common
{
public class LocalRotationSpeedSystem : JobComponentSystem
{
struct LocalRotationSpeedGroup
{
public ComponentDataArray<LocalRotation> rotations;
[ReadOnly] public ComponentDataArray<LocalRotationSpeed> rotationSpeeds;
public int Length;
}
[Inject] private LocalRotationSpeedGroup m_LocalRotationSpeedGroup;
[ComputeJobOptimization]
struct LocalRotationSpeedLocalRotation : IJobParallelFor
{
public ComponentDataArray<LocalRotation> rotations;
[ReadOnly] public ComponentDataArray<LocalRotationSpeed> rotationSpeeds;
public float dt;
public void Execute(int i)
{
var speed = rotationSpeeds[i].Value;
if (speed > 0.0f)
{
rotations[i] = new LocalRotation
{
Value = math.mul(math.normalize(rotations[i].Value), math.axisAngle(math.up(),speed*dt))
};
}
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var rotationSpeedLocalRotationJob = new LocalRotationSpeedLocalRotation
{
rotations = m_LocalRotationSpeedGroup.rotations,
rotationSpeeds = m_LocalRotationSpeedGroup.rotationSpeeds,
dt = Time.deltaTime
};
return rotationSpeedLocalRotationJob.Schedule(m_LocalRotationSpeedGroup.Length, 64, inputDeps);
}
}
}