Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
IndexedScatterPlotDisplayer.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Displayers.ScatterPlots {
10  [ExecuteInEditMode]
11  [AddComponentMenu(DisplayerComponentMenuPath._ComponentMenuPath
12  + "IndexedScatterPlot"
13  + DisplayerComponentMenuPath._Postfix)]
15  [SerializeField] GameObject[] _designs = null;
16  [SerializeField] List<GameObject> _instances = null;
17 
21  protected override void Setup() { }
22 
27  public override void Display(Double value) { }
28 
29  public override void Display(float[] values) { }
30 
31  public override void Display(String values) { }
32 
33  public override void Display(Vector3 value) { throw new NotImplementedException(); }
34  public override void Display(Vector3[] value) { this.ScatterPlot(value); }
35 
36  public override void Display(Points.ValuePoint points) { this.PlotSeries(new[] {points}); }
37 
38  public override void Display(Points.ValuePoint[] points) { }
39 
40  public override void Display(Points.StringPoint point) { throw new NotImplementedException(); }
41  public override void Display(Points.StringPoint[] points) { throw new NotImplementedException(); }
42 
43  //public override void Display(Object o) { throw new NotImplementedException(); }
44  public override void Display(float values) { }
45 
46  void Update() {
47  if (this._RetainLastPlot) {
48  if (this._Values != null) {
49  PlotSeries(this._Values);
50  }
51  }
52  }
53 
54  void SpawnDesign(GameObject design, Vector3 position, Quaternion rotation) {
55  //var go = Instantiate(design, position, rotation,this.transform);
56  var go = Instantiate(design, position, design.transform.rotation, this.transform);
57  this._instances.Add(go);
58  }
59 
64  protected override void Clean() {
65  if (Application.isPlaying) {
66  this._instances.ForEach(Destroy);
67  } else {
68  this._instances.ForEach(DestroyImmediate);
69  }
70 
71  this._instances.Clear();
72 
73  base.Clean();
74  }
75 
79  public void ScatterPlot(Vector3[] points) { }
80 
81  /*public override void PlotSeries(float[] points) {
82 
83  }*/
84 
88  public override void PlotSeries(Points.ValuePoint[] points) {
89  #if NEODROID_DEBUG
90  if (this.Debugging) {
91  Debug.Log("Plotting value points");
92  }
93  #endif
94 
95  this._Values = points;
96  this.Clean();
97 
98  foreach (var point in points) {
99  var game_objects = this._designs;
100  if (game_objects != null && point._Val >= game_objects.Length) {
101  continue;
102  }
103 
104  this.SpawnDesign(this._designs[(int)point._Val], point._Pos, Quaternion.identity);
105  }
106  }
107  }
108 }