8 namespace droid.Runtime.Prototyping.Configurables {
12 [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
14 + ConfigurableComponentMenuPath._Postfix)]
29 [Header(
"Observation", order = 103)]
33 [SerializeField] Vector3 _direction;
34 [SerializeField] Vector3 _rotation;
35 [SerializeField]
bool _use_environments_space =
false;
40 public override string PrototypingTypeName {
get {
return "EulerTransformConfigurable"; } }
44 public Vector3 Position {
get {
return this._position; }
set { this._position = value; } }
46 public Vector3 Direction {
get {
return this._direction; }
set { this._direction = value; } }
48 public Vector3 Rotation {
get {
return this._rotation; }
set { this._rotation = value; } }
54 public override ISpace ConfigurableValueSpace {
get; }
59 if (this._use_environments_space) {
60 this.Position = this.ParentEnvironment.TransformPoint(this.transform.position);
61 this.Direction = this.ParentEnvironment.TransformDirection(this.transform.forward);
62 this.Rotation = this.ParentEnvironment.TransformDirection(this.transform.up);
64 var transform1 = this.transform;
65 this.Position = transform1.position;
66 this.Direction = transform1.forward;
67 this.Rotation = transform1.up;
74 this.ParentEnvironment =
75 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this);
76 this.ParentEnvironment =
77 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._x);
78 this.ParentEnvironment =
79 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._y);
80 this.ParentEnvironment =
81 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._z);
82 this.ParentEnvironment =
83 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._dir_x);
84 this.ParentEnvironment =
85 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._dir_y);
86 this.ParentEnvironment =
87 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._dir_z);
88 this.ParentEnvironment =
89 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._rot_x);
90 this.ParentEnvironment =
91 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._rot_y);
92 this.ParentEnvironment =
93 NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (
Configurable)
this, this._rot_z);
100 this._x = this.Identifier +
"X_";
101 this._y = this.Identifier +
"Y_";
102 this._z = this.Identifier +
"Z_";
103 this._dir_x = this.Identifier +
"DirX_";
104 this._dir_y = this.Identifier +
"DirY_";
105 this._dir_z = this.Identifier +
"DirZ_";
106 this._rot_x = this.Identifier +
"RotX_";
107 this._rot_y = this.Identifier +
"RotY_";
108 this._rot_z = this.Identifier +
"RotZ_";
115 if (this.ParentEnvironment == null) {
119 this.ParentEnvironment.UnRegister(
this, this._x);
120 this.ParentEnvironment.UnRegister(
this, this._y);
121 this.ParentEnvironment.UnRegister(
this, this._z);
122 this.ParentEnvironment.UnRegister(
this, this._dir_x);
123 this.ParentEnvironment.UnRegister(
this, this._dir_y);
124 this.ParentEnvironment.UnRegister(
this, this._dir_z);
125 this.ParentEnvironment.UnRegister(
this, this._rot_x);
126 this.ParentEnvironment.UnRegister(
this, this._rot_y);
127 this.ParentEnvironment.UnRegister(
this, this._rot_z);
135 var transform1 = this.transform;
136 var pos = transform1.position;
137 var dir = transform1.forward;
138 var rot = transform1.up;
139 if (this._use_environments_space) {
140 pos = this.ParentEnvironment.TransformPoint(pos);
141 dir = this.ParentEnvironment.TransformDirection(dir);
142 rot = this.ParentEnvironment.TransformDirection(rot);
146 if (this.PositionSpace.DecimalGranularity >= 0) {
147 v = (int)Math.Round(v,
this.PositionSpace.DecimalGranularity);
150 if (this.PositionSpace._Min_Values[0].CompareTo(
this.PositionSpace._Max_Values[0]) != 0) {
152 if (v < this.PositionSpace._Min_Values[0] || v >
this.PositionSpace._Max_Values[0]) {
153 Debug.Log(
string.Format(
"Configurable does not accept input{2}, outside allowed range {0} to {1}",
154 this.PositionSpace._Min_Values[0],
155 this.PositionSpace._Max_Values[0],
162 if (this.Debugging) {
163 Debug.Log(
"Applying " + v +
" To " + this.Identifier);
166 if (this.RelativeToExistingValue) {
168 pos.Set(v - pos.x, pos.y, pos.z);
170 pos.Set(pos.x, v - pos.y, pos.z);
172 pos.Set(pos.x, pos.y, v - pos.z);
174 dir.Set(v - dir.x, dir.y, dir.z);
176 dir.Set(dir.x, v - dir.y, dir.z);
178 dir.Set(dir.x, dir.y, v - dir.z);
180 rot.Set(v - rot.x, rot.y, rot.z);
182 rot.Set(rot.x, v - rot.y, rot.z);
184 rot.Set(rot.x, rot.y, v - rot.z);
188 pos.Set(v, pos.y, pos.z);
190 pos.Set(pos.x, v, pos.z);
192 pos.Set(pos.x, pos.y, v);
194 dir.Set(v, dir.y, dir.z);
196 dir.Set(dir.x, v, dir.z);
198 dir.Set(dir.x, dir.y, v);
200 rot.Set(v, rot.y, rot.z);
202 rot.Set(rot.x, v, rot.z);
204 rot.Set(rot.x, rot.y, v);
211 if (this._use_environments_space) {
212 inv_pos = this.ParentEnvironment.InverseTransformPoint(pos);
213 inv_dir = this.ParentEnvironment.InverseTransformDirection(dir);
214 inv_rot = this.ParentEnvironment.InverseTransformDirection(rot);
217 this.transform.position = inv_pos;
218 this.transform.rotation = Quaternion.identity;
219 this.transform.rotation = Quaternion.LookRotation(inv_dir, inv_rot);