forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptTemplateTest1.cs
More file actions
57 lines (46 loc) · 2.08 KB
/
Copy pathScriptTemplateTest1.cs
File metadata and controls
57 lines (46 loc) · 2.08 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
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using static Unity.Mathematics.math;
public class ScriptTemplateTest1 : JobComponentSystem
{
// This declares a new kind of job, which is a unit of work to do.
// The job is declared as an IJobForEach<Translation, Rotation>,
// meaning it will process all entities in the world that have both
// Translation and Rotation components. Change it to process the component
// types you want.
//
// The job is also tagged with the BurstCompile attribute, which means
// that the Burst compiler will optimize it for the best performance.
[BurstCompile]
struct ScriptTemplateTest1Job : IJobForEach<Translation, Rotation>
{
// Add fields here that your job needs to do its work.
// For example,
// public float deltaTime;
public void Execute(ref Translation translation, [ReadOnly] ref Rotation rotation)
{
// Implement the work to perform for each entity here.
// You should only access data that is local or that is a
// field on this job. Note that the 'rotation' parameter is
// marked as [ReadOnly], which means it cannot be modified,
// but allows this job to run in parallel with other jobs
// that want to read Rotation component data.
// For example,
// translation.Value += mul(rotation.Value, new float3(0, 0, 1)) * deltaTime;
}
}
protected override JobHandle OnUpdate(JobHandle inputDependencies)
{
var job = new ScriptTemplateTest1Job();
// Assign values to the fields on your job here, so that it has
// everything it needs to do its work when it runs later.
// For example,
// job.deltaTime = UnityEngine.Time.deltaTime;
// Now that the job is set up, schedule it to be run.
return job.Schedule(this, inputDependencies);
}
}