Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Configurable.cs
Go to the documentation of this file.
7 using UnityEngine;
8 
9 namespace droid.Runtime.Prototyping.Configurables {
13  [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
14  + "Vanilla"
15  + ConfigurableComponentMenuPath._Postfix)]
16  [ExecuteInEditMode]
17  public abstract class Configurable : PrototypingGameObject,
21  public bool RelativeToExistingValue { get { return this._relative_to_existing_value; } }
22 
23 
27  public abstract ISpace ConfigurableValueSpace { get; }
28 
31  public AbstractPrototypingEnvironment ParentEnvironment {
32  get { return this._environment; }
33  set { this._environment = value; }
34  }
35 
38  public virtual void UpdateCurrentConfiguration() { }
39 
44  public abstract void ApplyConfiguration(IConfigurableConfiguration configuration);
45 
48  public void EnvironmentReset() { }
49 
53  public virtual void PostEnvironmentSetup() { this.UpdateCurrentConfiguration(); }
54 
59  public virtual Configuration[] SampleConfigurations() {
60  return new[] {new Configuration(this.Identifier, this.ConfigurableValueSpace.Sample())};
61  }
62 
66  protected sealed override void Setup() { this.PreSetup(); }
67 
70  protected virtual void PreSetup() { }
71 
75  protected override void RegisterComponent() {
76  this.ParentEnvironment = NeodroidUtilities.RegisterComponent(this.ParentEnvironment, this);
77  }
78 
82  public virtual void Tick() {
83  if (this.SampleRandom && Application.isPlaying && this.on_tick) {
84  foreach (var v in this.SampleConfigurations()) {
85  this.ApplyConfiguration(v);
86  }
87  }
88  }
89 
90  void Update() {
91  if (this.SampleRandom && Application.isPlaying && !this.on_tick) {
92  this.Randomise();
93  }
94  }
95 
99  protected virtual void Randomise() {
100  foreach (var v in this.SampleConfigurations()) {
101  this.ApplyConfiguration(v);
102  }
103  }
104 
108  protected override void UnRegisterComponent() { this.ParentEnvironment?.UnRegister(this); }
109 
110  #region Fields
111 
114  [Header("References", order = 20)]
115  [SerializeField]
116  AbstractPrototypingEnvironment _environment = null;
117 
120  [Header("Configurable", order = 30)]
121  [SerializeField]
122  bool _relative_to_existing_value = false;
123 
124  public bool SampleRandom { get { return this._sampleRandom; } set { this._sampleRandom = value; } }
125 
126  [SerializeField] bool _sampleRandom = false;
127  [SerializeField] bool on_tick = false;
128 
129  #endregion
130  }
131 }