Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
EnsureValidState.cs
Go to the documentation of this file.
5 using UnityEngine;
6 
7 namespace droid.Runtime.Prototyping.Internals.StateValidation {
12  [SerializeField] Actor _actor;
13 
14  [SerializeField] AbstractPrototypingEnvironment _environment;
15  [SerializeField] Transform _goal;
16 
17  [SerializeField] Obstruction[] _obstructions;
18  [SerializeField] bool _only_initial_state = true;
19 
20  [SerializeField] BoundingBox _playable_area;
21 
25  public override string PrototypingTypeName { get { return "ValidityChecker"; } }
26 
30  protected override void Clear() {
31  if (!this._goal) {
32  this._goal = FindObjectOfType<Transform>();
33  }
34 
35  if (!this._actor) {
36  this._actor = FindObjectOfType<Actor>();
37  }
38 
39  if (!this._environment) {
40  this._environment = FindObjectOfType<AbstractPrototypingEnvironment>();
41  }
42 
43  if (this._obstructions.Length <= 0) {
44  this._obstructions = FindObjectsOfType<Obstruction>();
45  }
46 
47  if (!this._playable_area) {
48  this._playable_area = FindObjectOfType<BoundingBox>();
49  }
50  }
51 
54  void ValidateState() {
55  if (this._only_initial_state && this._environment.CurrentFrameNumber != 0) {
56  return;
57  }
58 
59  if (this._playable_area != null && !this._playable_area.Bounds.Intersects(this._actor.ActorBounds)) {
60  this._environment.Terminate("Actor outside playable area");
61  }
62 
63  if (this._playable_area != null
64  && !this._playable_area.Bounds.Intersects(this._goal.GetComponent<Collider>().bounds)) {
65  this._environment.Terminate("Goal outside playable area");
66  }
67 
68  foreach (var obstruction in this._obstructions) {
69  if (obstruction != null
70  && obstruction.GetComponent<Collider>().bounds.Intersects(this._actor.ActorBounds)) {
71  this._environment.Terminate("Actor overlapping obstruction");
72  }
73 
74  if (obstruction != null
75  && obstruction.GetComponent<Collider>().bounds
76  .Intersects(this._goal.GetComponent<Collider>().bounds)) {
77  this._environment.Terminate("Goal overlapping obstruction");
78  }
79  }
80  }
81 
82  public override void EnvironmentReset() { }
83 
87  public override void PreStep() { this.ValidateState(); }
88 
92  public override void Step() { this.ValidateState(); }
93 
97  public override void PostStep() { this.ValidateState(); }
98  }
99 }
void Terminate(string reason="None")
Termination of an episode, can be supplied with a reason for various purposes debugging or clarificat...