2 using System.Collections.Generic;
7 namespace droid.Runtime.Prototyping.Displayers.ScatterPlots {
9 [AddComponentMenu(DisplayerComponentMenuPath._ComponentMenuPath
10 +
"GameObjectScatterPlotDisplayer" 11 + DisplayerComponentMenuPath._Postfix)]
13 [SerializeField] Gradient _gradient;
14 ParticleSystem _particle_system;
16 ParticleSystem.MainModule _particle_system_main_module;
17 ParticleSystemRenderer _particle_system_renderer;
20 ParticleSystemSimulationSpace _particle_system_simulation_space = ParticleSystemSimulationSpace.World;
22 ParticleSystem.Particle[] _particles;
23 [SerializeField]
float _size = 0.6f;
25 List<float> _vs =
new List<float>();
27 protected override void Setup() {
28 this._particle_system = this.GetComponent<ParticleSystem>();
29 var em = this._particle_system.emission;
32 var sh = this._particle_system.shape;
35 this._particle_system_main_module = this._particle_system.main;
36 this._particle_system_main_module.loop =
false;
37 this._particle_system_main_module.playOnAwake =
false;
38 this._particle_system_main_module.simulationSpace = this._particle_system_simulation_space;
39 this._particle_system_main_module.simulationSpeed = 0;
40 this._particle_system_main_module.startSize = this._size;
42 this._particle_system_renderer = this.GetComponent<ParticleSystemRenderer>();
44 this._particle_system_renderer.alignment = ParticleSystemRenderSpace.World;
46 if (this._gradient == null) {
47 this._gradient =
new Gradient {
49 new GradientColorKey(
new Color(1, 0, 0), 0f),
50 new GradientColorKey(
new Color(0, 1, 0), 1f)
56 public override void Display(Double value) {
59 Debug.Log(
"Applying the double " + value +
" To " + this.name);
63 this._Values =
new[] {(float)value};
64 this.PlotSeries(this._Values);
67 public override void Display(
float[] values) {
71 foreach (var value
in values) {
75 Debug.Log(
"Applying the float array " + s +
" To " + this.name);
78 this._Values = values;
79 this.PlotSeries(values);
82 public override void Display(String values) {
85 Debug.Log(
"Applying the float array " + values +
" To " + this.name);
90 foreach (var value
in values.Split(
',')) {
91 this._vs.Add(
float.Parse(value));
94 this._Values = this._vs.ToArray();
95 this.PlotSeries(this._Values);
98 public override void Display(Vector3 value) {
throw new NotImplementedException(); }
99 public override void Display(Vector3[] value) { this.ScatterPlot(value); }
104 if (this._particles == null || this._particles.Length != points.Length) {
105 this._particles =
new ParticleSystem.Particle[points.Length];
109 if (this.Debugging) {
110 var points_str = points.Aggregate(
"",
113 + $
"({point._Pos.ToString()}, {point._Val},{point._Size})" 115 Debug.Log(
"Applying the points " + points_str +
" to " + this.name);
120 foreach (var point
in points) {
121 this._particles[i].remainingLifetime = 100000;
122 this._particles[i].position = point._Pos;
123 var clamped = Math.Min(Math.Max(0.0f, point._Val), 1.0f);
124 this._particles[i].startColor = this._gradient.Evaluate(clamped);
125 this._particles[i].startSize = point._Size;
129 this._particle_system.SetParticles(this._particles, points.Length);
139 if (this.Debugging) {
140 Debug.Log(
"Applying the float " + values +
" To " + this.name);
144 this._Values =
new[] {values};
145 this.PlotSeries(this._Values);
152 if (this._particles == null || this._particles.Length != points.Length) {
153 this._particles =
new ParticleSystem.Particle[points.Length];
157 if (this.Debugging) {
158 var points_str = points.Aggregate(
"", (current, point) => current + point.ToString() +
", ");
159 Debug.Log(
"Applying the points " + points_str +
" To " + this.name);
164 var l = (float)points.Length;
165 foreach (var point in points) {
166 this._particles[i].remainingLifetime = 100000;
167 this._particles[i].position = point;
168 var clamped = Math.Min(Math.Max(0.0f, i / l), 1.0f);
169 this._particles[i].startColor = this._gradient.Evaluate(clamped);
170 this._particles[i].startSize = this._size;
174 this._particle_system.SetParticles(this._particles, points.Length);
178 if (this._particles == null || this._particles.Length != points.Length) {
179 this._particles =
new ParticleSystem.Particle[points.Length];
183 if (this.Debugging) {
184 Debug.Log(
"Applying the series " + points +
" To " + this.name);
189 foreach (var point
in points) {
190 this._particles[i].remainingLifetime = 100000;
191 this._particles[i].position = Vector3.one * i;
192 var clamped = Math.Min(Math.Max(0.0f, point), 1.0f);
193 this._particles[i].startColor = this._gradient.Evaluate(clamped);
194 this._particles[i].startSize = this._size;
198 this._particle_system.SetParticles(this._particles, points.Length);
205 var alive = this._particle_system.GetParticles(this._particles);
206 if (alive < points.Length) {
207 this._particles =
new ParticleSystem.Particle[points.Length];
211 foreach (var point
in points) {
212 this._particles[i].remainingLifetime = 100000;
213 this._particles[i].position = point._Pos;
214 this._particles[i].startColor = this._gradient.Evaluate(point._Val);
215 this._particles[i].startSize = point._Size;
219 this._particle_system.SetParticles(this._particles, points.Length);
override void Display(float values)
void ScatterPlot(Vector3[] points)
override void Display(float[] values)
override void Display(Points.StringPoint point)
override void Display(Vector3[] value)
override void Display(Points.ValuePoint[] points)
override void Display(String values)
void PlotSeries(float[] points)
override void Display(Points.ValuePoint points)
override void Display(Vector3 value)
override void PlotSeries(Points.ValuePoint[] points)
override void Display(Points.StringPoint[] points)
override void Display(Double value)