Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
ConfigurableSampleToggleList.cs
Go to the documentation of this file.
3 using UnityEngine;
4 using UnityEngine.UI;
5 
6 namespace droid.Runtime.Utilities.GameObjects.NeodroidCamera {
10  public class ConfigurableSampleToggleList : MonoBehaviour {
11  Configurable[] _all_configurables = null;
12  [SerializeField] Toggle _sample_toggle_button_prefab = null;
13 
14  void Awake() {
15  this._all_configurables = FindObjectsOfType<Configurable>();
16  //this._all_configurables = FindObjectOfType<PrototypingEnvironment>().Configurables;
17 
18  foreach (var configurable in this._all_configurables) {
19  if (configurable.enabled) {
20  var button = Instantiate(this._sample_toggle_button_prefab, this.transform);
21  button.isOn = configurable.SampleRandom;
22  button.onValueChanged.AddListener(value => this.Set(configurable, value));
23  var text = button.GetComponentInChildren<Text>();
24  button.name = configurable.Identifier;
25  text.text = configurable.Identifier;
26  }
27  }
28  }
29 
30  void Toggle(IConfigurable configurable) { configurable.SampleRandom = !configurable.SampleRandom; }
31 
32  void Set(IConfigurable configurable, bool value) { configurable.SampleRandom = value; }
33  }
34 }