Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Sensor.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
8 using UnityEngine;
9 
10 namespace droid.Runtime.Prototyping.Sensors {
14  [ExecuteInEditMode]
15  [Serializable]
16  public abstract class Sensor : PrototypingGameObject,
17  IObserver {
20  public AbstractPrototypingEnvironment ParentEnvironment {
21  get { return this._environment; }
22  set { this._environment = value; }
23  }
24 
28  public abstract IEnumerable<float> FloatEnumerable { get; }
29 
33  public abstract void UpdateObservation();
34 
38  public void EnvironmentReset() { }
39 
40  //protected abstract void UpdateFloatEnumerable(IEnumerable<float> vals);
41 
45  protected sealed override void Setup() {
46  this.PreSetup();
47  this.UpdateObservation();
48  }
49 
52  protected virtual void PreSetup() { }
53 
57  protected override void RegisterComponent() {
58  this.ParentEnvironment =
59  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, this);
60  }
61 
65  protected override void UnRegisterComponent() { this.ParentEnvironment?.UnRegister(this); }
66 
69  protected virtual void Update() {
70  if (Application.isPlaying) {
71  if (this.FloatEnumerable == null || !this.FloatEnumerable.Any()) {
72  #if NEODROID_DEBUG
73  if (this.Debugging) {
74  Debug.LogWarning($"FloatEnumerable of {this.Identifier} is empty! Maybe you forget an assignment to it when updating observations");
75  }
76  #endif
77  }
78  }
79  }
80 
85  public override string ToString() {
86  return this.FloatEnumerable.Any() ? string.Join(",", this.FloatEnumerable) : "Empty FloatEnumerable";
87  }
88 
89  #region Fields
90 
91  [Header("References", order = 99)]
92  [SerializeField]
93  AbstractPrototypingEnvironment _environment;
94 
95  [Header("Normalisation", order = 100)]
96  [SerializeField]
97  bool _normalise_observation;
98 
99  #endregion
100  }
101 }
sealed override void Setup()
Definition: Sensor.cs:45