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