Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
SizeConfigurable.cs
Go to the documentation of this file.
5 using UnityEngine;
6 
7 namespace droid.Runtime.Prototyping.Configurables {
11  [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
12  + "Size"
13  + ConfigurableComponentMenuPath._Postfix)]
14  public class SizeConfigurable : Configurable {
18  string _x;
19 
23  string _y;
24 
28  string _z;
29 
30  [SerializeField] Space3 _space = Space3.ZeroOne;
31 
35  protected override void PreSetup() {
36  this._x = this.Identifier + "X";
37  this._y = this.Identifier + "Y";
38  this._z = this.Identifier + "Z";
39  }
40 
44  protected override void RegisterComponent() {
45  this.ParentEnvironment =
46  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._x);
47  this.ParentEnvironment =
48  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._y);
49  this.ParentEnvironment =
50  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._z);
51  }
52 
56  protected override void UnRegisterComponent() {
57  if (this.ParentEnvironment == null) {
58  return;
59  }
60 
61  this.ParentEnvironment.UnRegister(this, this._x);
62  this.ParentEnvironment.UnRegister(this, this._y);
63  this.ParentEnvironment.UnRegister(this, this._z);
64  }
65 
66  public override ISpace ConfigurableValueSpace { get; }
67 
71  public override void ApplyConfiguration(IConfigurableConfiguration configuration) {
72  #if NEODROID_DEBUG
73  if (this.Debugging) {
74  DebugPrinting.ApplyPrint(this.Debugging, configuration, this.Identifier);
75  }
76  #endif
77  var local_scale = this.transform.localScale;
78  if (configuration.ConfigurableName == this._x) {
79  local_scale.x = configuration.ConfigurableValue;
80  } else if (configuration.ConfigurableName == this._y) {
81  local_scale.y = configuration.ConfigurableValue;
82  } else if (configuration.ConfigurableName == this._z) {
83  local_scale.z = configuration.ConfigurableValue;
84  }
85 
86  this.transform.localScale = local_scale;
87  }
88 
93  public override Configuration[] SampleConfigurations() {
94  var sample = Space1.ZeroOne.Sample();
95 
96  var v = this._space.Sample();
97 
98  if (sample < .33f) {
99  return new[] {new Configuration(this._x, v.x)};
100  }
101 
102  if (sample > .66f) {
103  return new[] {new Configuration(this._y, v.y)};
104  }
105 
106  return new[] {new Configuration(this._z, v.z)};
107  }
108  }
109 }
override void ApplyConfiguration(IConfigurableConfiguration configuration)