forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeadingSystem.cs
More file actions
51 lines (43 loc) · 1.48 KB
/
Copy pathHeadingSystem.cs
File metadata and controls
51 lines (43 loc) · 1.48 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
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Burst;
using Unity.Mathematics;
using Unity.Transforms;
namespace Samples.Common
{
public class HeadingSystem : JobComponentSystem
{
#pragma warning disable 649
struct HeadingsGroup
{
public ComponentDataArray<Rotation> rotations;
[ReadOnly] public ComponentDataArray<Heading> headings;
public readonly int Length;
}
[Inject] private HeadingsGroup m_HeadingsGroup;
#pragma warning restore 649
[BurstCompile]
struct RotationFromHeading : IJobParallelFor
{
public ComponentDataArray<Rotation> rotations;
[ReadOnly] public ComponentDataArray<Heading> headings;
public void Execute(int i)
{
var heading = headings[i].Value;
var rotation = quaternion.LookRotationSafe(heading, math.up());
rotations[i] = new Rotation { Value = rotation };
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var rotationFromHeadingJob = new RotationFromHeading
{
rotations = m_HeadingsGroup.rotations,
headings = m_HeadingsGroup.headings,
};
var rotationFromHeadingJobHandle = rotationFromHeadingJob.Schedule(m_HeadingsGroup.Length, 64, inputDeps);
return rotationFromHeadingJobHandle;
}
}
}