Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
EnvironmentalLightConfigurable.cs
Go to the documentation of this file.
6 using UnityEngine;
7 
8 namespace droid.Runtime.Prototyping.Configurables {
12  [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
13  + "EnvironmentalLight"
14  + ConfigurableComponentMenuPath._Postfix)]
15  [DisallowMultipleComponent]
17  string _color_r;
18  string _color_g;
19  string _color_b;
20  string _intensity;
21  string _reflection_intensity;
22 
23  [SerializeField]
24  Space2 _intensity_space = new Space2 {
25  _decimal_granularity = 2,
26  _Min_Values = Vector3.one * 0.0f,
27  _Max_Values = Vector3.one * 1f,
29  new DistributionSampler(DistributionEnum.Linear_) {
30  _factor
31  = -1
32  }
33  };
34 
35  [SerializeField]
36  Space3 _color_space = new Space3 {_Min_Values = Vector3.one * 0.6f, _Max_Values = Vector3.one * 1f};
37 
41  protected override void PreSetup() {
42  this._color_r = this.Identifier + "ColorR";
43  this._color_g = this.Identifier + "ColorG";
44  this._color_b = this.Identifier + "ColorB";
45  this._intensity = this.Identifier + "Intensity";
46  this._reflection_intensity = this.Identifier + "ReflectionIntensity";
47  }
48 
52  protected override void RegisterComponent() {
53  this.ParentEnvironment =
54  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_r);
55  this.ParentEnvironment =
56  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_b);
57  this.ParentEnvironment =
58  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._color_g);
59  this.ParentEnvironment =
60  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._intensity);
61  this.ParentEnvironment =
62  NeodroidUtilities.RegisterComponent(this.ParentEnvironment,
63  (Configurable)this,
64  this._reflection_intensity);
65  }
66 
70  protected override void UnRegisterComponent() {
71  if (this.ParentEnvironment == null) {
72  return;
73  }
74 
75  this.ParentEnvironment.UnRegister(this, this._color_r);
76  this.ParentEnvironment.UnRegister(this, this._color_g);
77  this.ParentEnvironment.UnRegister(this, this._color_b);
78  this.ParentEnvironment.UnRegister(this, this._intensity);
79  this.ParentEnvironment.UnRegister(this, this._reflection_intensity);
80  }
81 
82  public override ISpace ConfigurableValueSpace { get; }
83 
87  public override void ApplyConfiguration(IConfigurableConfiguration configuration) {
88  #if NEODROID_DEBUG
89  if (this.Debugging) {
90  DebugPrinting.ApplyPrint(this.Debugging, configuration, this.Identifier);
91  }
92  #endif
93  var c = RenderSettings.ambientLight;
94  if (configuration.ConfigurableName == this._color_r) {
95  c.r = configuration.ConfigurableValue;
96  } else if (configuration.ConfigurableName == this._color_g) {
97  c.g = configuration.ConfigurableValue;
98  } else if (configuration.ConfigurableName == this._color_b) {
99  c.b = configuration.ConfigurableValue;
100  } else if (configuration.ConfigurableName == this._intensity) {
101  //c.a = configuration.ConfigurableValue;
102  RenderSettings.ambientIntensity = configuration.ConfigurableValue;
103  RenderSettings.reflectionIntensity = Mathf.Clamp01(configuration.ConfigurableValue);
104  //RenderSettings.skybox.SetFloat("_Exposure", configuration.ConfigurableValue);
105  } else if (configuration.ConfigurableName == this._reflection_intensity) {
106  //c.a = configuration.ConfigurableValue;
107 // RenderSettings.reflectionIntensity = configuration.ConfigurableValue;
108  //RenderSettings.skybox.SetFloat("_Exposure", configuration.ConfigurableValue);
109  }
110 
111  RenderSettings.ambientLight = c;
112  DynamicGI.UpdateEnvironment();
113  }
114 
119  public override Configuration[] SampleConfigurations() {
120  var o = this._intensity_space.Sample();
121  var v = this._color_space.Sample();
122 
123  return new[] {
124  new Configuration(this._color_r, v.x),
125  new Configuration(this._color_g, v.y),
126  new Configuration(this._color_b, v.z),
127  new Configuration(this._intensity, o.x),
128  new Configuration(this._reflection_intensity, o.y)
129  };
130  }
131  }
132 }
override void ApplyConfiguration(IConfigurableConfiguration configuration)