Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
FlareConfigurable.cs
Go to the documentation of this file.
5 using UnityEngine;
6 
7 namespace droid.Runtime.Prototyping.Configurables.Experimental {
11  [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
12  + "Flare"
13  + ConfigurableComponentMenuPath._Postfix)]
14  [RequireComponent(typeof(Light))]
16  string _color_r;
17  string _color_g;
18  string _color_b;
19  string _shadow_strength;
20  string _intensity;
21  string _indirect_multiplier;
22 
23  Light _light;
24  Flare _flare;
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] Space3 _int_ind_sha_space = Space3.TwentyEighty + Vector3.one * 0.4f;
34 
38  protected override void PreSetup() {
39  this._shadow_strength = this.Identifier + "ShadowStrength";
40  this._color_r = this.Identifier + "ColorR";
41  this._color_g = this.Identifier + "ColorG";
42  this._color_b = this.Identifier + "ColorB";
43  this._intensity = this.Identifier + "Intensity";
44  this._indirect_multiplier = this.Identifier + "IndirectMultiplier";
45 
46  this._light = this.GetComponent<Light>();
47  }
48 
52  protected override void RegisterComponent() {
53  this.ParentEnvironment =
54  NeodroidUtilities.RegisterComponent(this.ParentEnvironment,
55  (Configurable)this,
56  this._shadow_strength);
57  this.ParentEnvironment =
58  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_r);
59  this.ParentEnvironment =
60  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_b);
61  this.ParentEnvironment =
62  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_g);
63  this.ParentEnvironment =
64  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._intensity);
65  this.ParentEnvironment =
66  NeodroidUtilities.RegisterComponent(this.ParentEnvironment,
67  (Configurable)this,
68  this._indirect_multiplier);
69  }
70 
74  protected override void UnRegisterComponent() {
75  if (this.ParentEnvironment == null) {
76  return;
77  }
78 
79  this.ParentEnvironment.UnRegister(this, this._shadow_strength);
80  this.ParentEnvironment.UnRegister(this, this._color_r);
81  this.ParentEnvironment.UnRegister(this, this._color_g);
82  this.ParentEnvironment.UnRegister(this, this._color_b);
83  this.ParentEnvironment.UnRegister(this, this._intensity);
84  this.ParentEnvironment.UnRegister(this, this._indirect_multiplier);
85  }
86 
87  public override ISpace ConfigurableValueSpace { get; }
88 
92  public override void ApplyConfiguration(IConfigurableConfiguration configuration) {
93  #if NEODROID_DEBUG
94  if (this.Debugging) {
95  DebugPrinting.ApplyPrint(this.Debugging, configuration, this.Identifier);
96  }
97  #endif
98 
99  if (configuration.ConfigurableName == this._shadow_strength) {
100  this._light.shadowStrength = configuration.ConfigurableValue;
101  } else if (configuration.ConfigurableName == this._color_r) {
102  var c = this._light.color;
103  c.r = configuration.ConfigurableValue;
104  this._light.color = c;
105  } else if (configuration.ConfigurableName == this._color_g) {
106  var c = this._light.color;
107  c.g = configuration.ConfigurableValue;
108  this._light.color = c;
109  } else if (configuration.ConfigurableName == this._color_b) {
110  var c = this._light.color;
111  c.b = configuration.ConfigurableValue;
112  this._light.color = c;
113  } else if (configuration.ConfigurableName == this._intensity) {
114  this._light.intensity = configuration.ConfigurableValue;
115  } else if (configuration.ConfigurableName == this._indirect_multiplier) {
116  this._light.bounceIntensity = configuration.ConfigurableValue;
117  }
118  }
119 
124  public override Configuration[] SampleConfigurations() {
125  var o = this._int_ind_sha_space.Sample();
126  var v = this._color_space.Sample();
127 
128  return new[] {
129  new Configuration(this._color_r, v.x),
130  new Configuration(this._color_g, v.y),
131  new Configuration(this._color_b, v.z),
132  new Configuration(this._intensity, o.x),
133  new Configuration(this._indirect_multiplier, o.y),
134  new Configuration(this._shadow_strength, o.z)
135  };
136  }
137  }
138 }
override void ApplyConfiguration(IConfigurableConfiguration configuration)