forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotationSpeedResetSphereSystem.cs
More file actions
73 lines (64 loc) · 2.83 KB
/
Copy pathRotationSpeedResetSphereSystem.cs
File metadata and controls
73 lines (64 loc) · 2.83 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Burst;
using Unity.Mathematics;
using Samples.Common;
using Unity.Transforms;
namespace Samples.Common
{
[UpdateBefore(typeof(RotationSpeedSystem))]
public class RotationSpeedResetSphereSystem : JobComponentSystem
{
struct RotationSpeedResetSphereGroup
{
[ReadOnly] public ComponentDataArray<RotationSpeedResetSphere> rotationSpeedResetSpheres;
[ReadOnly] public ComponentDataArray<Radius> spheres;
[ReadOnly] public ComponentDataArray<Position> positions;
public readonly int Length;
}
[Inject] RotationSpeedResetSphereGroup m_RotationSpeedResetSphereGroup;
struct RotationSpeedGroup
{
public ComponentDataArray<RotationSpeed> rotationSpeeds;
[ReadOnly] public ComponentDataArray<Position> positions;
public readonly int Length;
}
[Inject] RotationSpeedGroup m_RotationSpeedGroup;
[BurstCompile]
struct RotationSpeedResetSphereRotation : IJobParallelFor
{
public ComponentDataArray<RotationSpeed> rotationSpeeds;
[ReadOnly] public ComponentDataArray<Position> positions;
[ReadOnly] public ComponentDataArray<RotationSpeedResetSphere> rotationSpeedResetSpheres;
[ReadOnly] public ComponentDataArray<Radius> spheres;
[ReadOnly] public ComponentDataArray<Position> rotationSpeedResetSpherePositions;
public void Execute(int i)
{
var center = positions[i].Value;
for (int positionIndex = 0; positionIndex < rotationSpeedResetSpheres.Length; positionIndex++)
{
if (math.distance(rotationSpeedResetSpherePositions[positionIndex].Value, center) < spheres[positionIndex].radius)
{
rotationSpeeds[i] = new RotationSpeed
{
Value = rotationSpeedResetSpheres[positionIndex].speed
};
}
}
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var rotationSpeedResetSphereRotationJob = new RotationSpeedResetSphereRotation
{
rotationSpeedResetSpheres = m_RotationSpeedResetSphereGroup.rotationSpeedResetSpheres,
spheres = m_RotationSpeedResetSphereGroup.spheres,
rotationSpeeds = m_RotationSpeedGroup.rotationSpeeds,
rotationSpeedResetSpherePositions = m_RotationSpeedResetSphereGroup.positions,
positions = m_RotationSpeedGroup.positions
};
return rotationSpeedResetSphereRotationJob.Schedule(m_RotationSpeedGroup.Length, 32, inputDeps);
}
}
}