Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
HelloRotationSpeedSystem.cs
Go to the documentation of this file.
1 #if ECS_EXISTS
2 using Unity.Burst;
3 using Unity.Collections;
4 using Unity.Entities;
5 using Unity.Jobs;
6 using Unity.Mathematics;
7 using Unity.Transforms;
8 using UnityEngine;
9 
10 // This system updates all entities in the scene with both a HelloRotationSpeed and Rotation component.
11 namespace droid.Runtime.EcsPrototyping
12 {
13  public class HelloRotationSpeedSystem : JobComponentSystem
14  {
15  // Use the [BurstCompile] attribute to compile a job with Burst. You may see significant speed ups, so try it!
16  [BurstCompile]
17  struct HelloRotationSpeedJob : IJobProcessComponentData<Rotation, HelloRotationSpeed>
18  {
19  // The [ReadOnly] attribute tells the job scheduler that this job cannot write to dT.
20  [ReadOnly] public float DeltaT;
21 
22  // rotation is read/write in this job
23  public void Execute(ref Rotation rotation, [ReadOnly] ref HelloRotationSpeed rotSpeed)
24  {
25  // Rotate something about its up vector at the speed given by HelloRotationSpeed.
26  rotation.Value =
27  math.mul(math.normalize(rotation.Value), quaternion.AxisAngle(math.up(), rotSpeed.rotationalMultiplier * this.DeltaT));
28  }
29  }
30 
31  // OnUpdate runs on the main thread.
32  protected override JobHandle OnUpdate(JobHandle inputDependencies)
33  {
34  var job = new HelloRotationSpeedJob(){
35  DeltaT = Time.deltaTime
36  };
37 
38  return job.Schedule(this, inputDependencies);
39  }
40  }
41 }
42 #endif