Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
RotationActuator.cs
Go to the documentation of this file.
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Actuators {
10  [AddComponentMenu(ActuatorComponentMenuPath._ComponentMenuPath
11  + "Rotation"
12  + ActuatorComponentMenuPath._Postfix)]
13  public class RotationActuator : Actuator {
16  [SerializeField]
17  protected Space _Relative_To = Space.Self;
18 
19  string _rot_x = "RotX";
20  string _rot_y = "RotY";
21  string _rot_z = "RotZ";
22 
23  string _rot_w = "RotW";
24  //new Space1 MotionSpace = Space1.ZeroOne;
25 
29  public override string PrototypingTypeName { get { return "Rotation"; } }
30 
34  protected override void Setup() {
35  this._rot_x = this.Identifier + "RotX";
36  this._rot_y = this.Identifier + "RotY";
37  this._rot_z = this.Identifier + "RotZ";
38  this._rot_w = this.Identifier + "RotW";
39  }
40 
44  protected override void RegisterComponent() {
45  this.Parent =
46  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, (Actuator)this, this._rot_x);
47  this.Parent =
48  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, (Actuator)this, this._rot_y);
49  this.Parent =
50  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, (Actuator)this, this._rot_z);
51  this.Parent =
52  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, (Actuator)this, this._rot_w);
53  }
54 
58  protected override void UnRegisterComponent() {
59  this.Parent?.UnRegister(this, this._rot_x);
60  this.Parent?.UnRegister(this, this._rot_y);
61  this.Parent?.UnRegister(this, this._rot_z);
62  this.Parent?.UnRegister(this, this._rot_w);
63  }
64 
69  protected override void InnerApplyMotion(IMotion motion) {
70  var transform_rotation = this.transform.rotation;
71  if (motion.ActuatorName == this._rot_x) {
72  transform_rotation.x = motion.Strength;
73  } else if (motion.ActuatorName == this._rot_y) {
74  transform_rotation.y = motion.Strength;
75  } else if (motion.ActuatorName == this._rot_z) {
76  transform_rotation.z = motion.Strength;
77  } else if (motion.ActuatorName == this._rot_w) {
78  transform_rotation.z = motion.Strength;
79  }
80 
81  this.transform.rotation = transform_rotation;
82  }
83  }
84 }