Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
SingleAxisTransformSensor.cs
Go to the documentation of this file.
1 using System;
5 using UnityEngine;
6 
7 namespace droid.Runtime.Prototyping.Sensors.Transform {
11  [AddComponentMenu(SensorComponentMenuPath._ComponentMenuPath
12  + "SingleAxisTransform"
13  + SensorComponentMenuPath._Postfix)]
14  [ExecuteInEditMode]
16  [SerializeField] [SearchableEnum] Axis _dim = Axis.X_;
17 
20  protected override void PreSetup() { }
21 
26  public override void UpdateObservation() {
27  switch (this._dim) {
28  case Axis.X_:
29  this.ObservationValue = this.transform.position.x;
30  break;
31  case Axis.Y_:
32  this.ObservationValue = this.transform.position.y;
33  break;
34  case Axis.Z_:
35  this.ObservationValue = this.transform.position.z;
36  break;
37  case Axis.Rot_x_:
38  this.ObservationValue = this.transform.rotation.eulerAngles.x;
39  break;
40  case Axis.Rot_y_:
41  this.ObservationValue = this.transform.rotation.eulerAngles.y;
42  break;
43  case Axis.Rot_z_:
44  this.ObservationValue = this.transform.rotation.eulerAngles.z;
45  break;
46  case Axis.Dir_x_:
47  this.ObservationValue = this.transform.forward.x;
48  break;
49  case Axis.Dir_y_:
50  this.ObservationValue = this.transform.forward.y;
51  break;
52  case Axis.Dir_z_:
53  this.ObservationValue = this.transform.forward.z;
54  break;
55  default: throw new ArgumentOutOfRangeException();
56  }
57  }
58 
59  void OnDrawGizmos() {
60  if (this.enabled) {
61  var position = this.transform.position;
62  switch (this._dim) {
63  case Axis.Rot_x_:
64  case Axis.X_:
65 
66  Debug.DrawLine(position, position + Vector3.right * 2, Color.green);
67  break;
68  case Axis.Rot_y_:
69  case Axis.Y_:
70 
71  Debug.DrawLine(position, position + Vector3.up * 2, Color.green);
72  break;
73  case Axis.Rot_z_:
74  case Axis.Z_:
75  Debug.DrawLine(position,
76  position + Vector3.forward * 2,
77  Color.green);
78  break;
79  case Axis.Dir_x_: break;
80  case Axis.Dir_y_: break;
81  case Axis.Dir_z_: break;
82  default: //TODO add the Direction cases
83  Gizmos.DrawIcon(position, "console.warnicon", true);
84  break;
85  }
86  }
87  }
88  }
89 }