8 namespace droid.Runtime.Prototyping.Configurables {
12 [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
14 + ConfigurableComponentMenuPath._Postfix)]
15 [RequireComponent(typeof(Rigidbody))]
33 Vector3 _angular_velocity = Vector3.zero;
42 Rigidbody _rigidbody = null;
58 [Header(
"Observation", order = 110)]
60 Vector3 _velocity = Vector3.zero;
69 public override string PrototypingTypeName {
get {
return "RigidbodyConfigurable"; } }
73 public Vector3 Velocity {
get {
return this._velocity; }
set { this._velocity = value; } }
77 public Vector3 AngularVelocity {
78 get {
return this._angular_velocity; }
79 private set { this._angular_velocity = value; }
84 public Space3 VelocitySpace {
get {
return this._velocity_space; } }
88 public Space3 AngularSpace {
get {
return this._angular_velocity_space; } }
90 public override ISpace ConfigurableValueSpace {
get; }
95 this.Velocity = this._rigidbody.velocity;
96 this.AngularVelocity = this._rigidbody.angularVelocity;
102 this._rigidbody = this.GetComponent<Rigidbody>();
103 this._vel_x = this.Identifier +
"VelX";
104 this._vel_y = this.Identifier +
"VelY";
105 this._vel_z = this.Identifier +
"VelZ";
106 this._ang_x = this.Identifier +
"AngX";
107 this._ang_y = this.Identifier +
"AngY";
108 this._ang_z = this.Identifier +
"AngZ";
114 this.ParentEnvironment =
115 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._vel_x);
116 this.ParentEnvironment =
117 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._vel_y);
118 this.ParentEnvironment =
119 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._vel_z);
120 this.ParentEnvironment =
121 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._ang_x);
122 this.ParentEnvironment =
123 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._ang_y);
124 this.ParentEnvironment =
125 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._ang_z);
131 if (this.ParentEnvironment == null) {
135 this.ParentEnvironment.UnRegister(
this, this._vel_x);
136 this.ParentEnvironment.UnRegister(
this, this._vel_y);
137 this.ParentEnvironment.UnRegister(
this, this._vel_z);
138 this.ParentEnvironment.UnRegister(
this, this._ang_x);
139 this.ParentEnvironment.UnRegister(
this, this._ang_y);
140 this.ParentEnvironment.UnRegister(
this, this._ang_z);
147 var vel = this._rigidbody.velocity;
148 var ang = this._rigidbody.velocity;
151 if (this.VelocitySpace.DecimalGranularity >= 0) {
152 v = (int)Math.Round(v,
this.VelocitySpace.DecimalGranularity);
155 if (this.VelocitySpace._Min_Values[0].CompareTo(
this.VelocitySpace._Max_Values[0]) != 0) {
157 if (v < this.VelocitySpace._Min_Values[0] || v >
this.VelocitySpace._Max_Values[0]) {
158 Debug.Log(
string.Format(
"Configurable does not accept input{2}, outside allowed range {0} to {1}",
159 this.VelocitySpace._Min_Values[0],
160 this.VelocitySpace._Max_Values[0],
167 if (this.Debugging) {
168 Debug.Log(
"Applying " + v +
" To " + this.Identifier);
172 if (this.RelativeToExistingValue) {
174 vel.Set(v - vel.x, vel.y, vel.z);
176 vel.Set(vel.x, v - vel.y, vel.z);
178 vel.Set(vel.x, vel.y, v - vel.z);
180 ang.Set(v - ang.x, ang.y, ang.z);
182 ang.Set(ang.x, v - ang.y, ang.z);
184 ang.Set(ang.x, ang.y, v - ang.z);
188 vel.Set(v, vel.y, vel.z);
190 vel.Set(vel.x, v, vel.z);
192 vel.Set(vel.x, vel.y, v);
194 ang.Set(v, ang.y, ang.z);
196 ang.Set(ang.x, v, ang.z);
198 ang.Set(ang.x, ang.y, v);
202 this._rigidbody.velocity = vel;
203 this._rigidbody.angularVelocity = ang;
override void UnRegisterComponent()
override Configuration [] SampleConfigurations()
override void ApplyConfiguration(IConfigurableConfiguration simulator_configuration)
override void UpdateCurrentConfiguration()
override void RegisterComponent()