Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
LightConfigurable.cs
Go to the documentation of this file.
6 using UnityEngine;
7 
8 namespace droid.Runtime.Prototyping.Configurables {
12  [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
13  + "Light"
14  + ConfigurableComponentMenuPath._Postfix)]
15  [RequireComponent(typeof(Light))]
17  string _color_r;
18  string _color_g;
19  string _color_b;
20  string _shadow_strength;
21  string _intensity;
22  string _indirect_multiplier;
23 
24  Light _light;
25 
26  [SerializeField]
27  Space3 _color_space = new Space3 {
28  _decimal_granularity = 2,
29  _Min_Values = Vector3.one * 0.7f,
30  _Max_Values = Vector3.one * 1f
31  };
32 
33  [SerializeField]
34  Space3 _int_ind_sha_space = new Space3 {
35  _decimal_granularity = 2,
36  _Min_Values = Vector3.one * 0.0f,
37  _Max_Values = Vector3.one * 1f,
39  new DistributionSampler(DistributionEnum.Linear_) {
40  _factor
41  = -1
42  }
43  };
44 
48  protected override void PreSetup() {
49  this._shadow_strength = this.Identifier + "ShadowStrength";
50  this._color_r = this.Identifier + "ColorR";
51  this._color_g = this.Identifier + "ColorG";
52  this._color_b = this.Identifier + "ColorB";
53  this._intensity = this.Identifier + "Intensity";
54  this._indirect_multiplier = this.Identifier + "IndirectMultiplier";
55 
56  this._light = this.GetComponent<Light>();
57  }
58 
62  protected override void RegisterComponent() {
63  this.ParentEnvironment =
64  NeodroidUtilities.RegisterComponent(this.ParentEnvironment,
65  (Configurable)this,
66  this._shadow_strength);
67  this.ParentEnvironment =
68  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_r);
69  this.ParentEnvironment =
70  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_b);
71  this.ParentEnvironment =
72  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_g);
73  this.ParentEnvironment =
74  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._intensity);
75  this.ParentEnvironment =
76  NeodroidUtilities.RegisterComponent(this.ParentEnvironment,
77  (Configurable)this,
78  this._indirect_multiplier);
79  }
80 
84  protected override void UnRegisterComponent() {
85  if (this.ParentEnvironment == null) {
86  return;
87  }
88 
89  this.ParentEnvironment.UnRegister(this, this._shadow_strength);
90  this.ParentEnvironment.UnRegister(this, this._color_r);
91  this.ParentEnvironment.UnRegister(this, this._color_g);
92  this.ParentEnvironment.UnRegister(this, this._color_b);
93  this.ParentEnvironment.UnRegister(this, this._intensity);
94  this.ParentEnvironment.UnRegister(this, this._indirect_multiplier);
95  }
96 
97  public override ISpace ConfigurableValueSpace { get; }
98 
102  public override void ApplyConfiguration(IConfigurableConfiguration configuration) {
103  #if NEODROID_DEBUG
104  if (this.Debugging) {
105  DebugPrinting.ApplyPrint(this.Debugging, configuration, this.Identifier);
106  }
107  #endif
108 
109  if (configuration.ConfigurableName == this._shadow_strength) {
110  this._light.shadowStrength = configuration.ConfigurableValue;
111  } else if (configuration.ConfigurableName == this._color_r) {
112  var c = this._light.color;
113  c.r = configuration.ConfigurableValue;
114  this._light.color = c;
115  } else if (configuration.ConfigurableName == this._color_g) {
116  var c = this._light.color;
117  c.g = configuration.ConfigurableValue;
118  this._light.color = c;
119  } else if (configuration.ConfigurableName == this._color_b) {
120  var c = this._light.color;
121  c.b = configuration.ConfigurableValue;
122  this._light.color = c;
123  } else if (configuration.ConfigurableName == this._intensity) {
124  this._light.intensity = configuration.ConfigurableValue;
125  } else if (configuration.ConfigurableName == this._indirect_multiplier) {
126  this._light.bounceIntensity = configuration.ConfigurableValue;
127  }
128  }
129 
134  public override Configuration[] SampleConfigurations() {
135  var o = this._int_ind_sha_space.Sample();
136  var v = this._color_space.Sample();
137 
138  return new[] {
139  new Configuration(this._color_r, v.x),
140  new Configuration(this._color_g, v.y),
141  new Configuration(this._color_b, v.z),
142  new Configuration(this._intensity, o.x),
143  new Configuration(this._indirect_multiplier, o.y),
144  new Configuration(this._shadow_strength, o.z)
145  };
146  }
147  }
148 }
override void ApplyConfiguration(IConfigurableConfiguration configuration)