2 using System.Collections.Generic;
8 namespace droid.Runtime.Prototyping.Displayers.ScatterPlots {
13 [AddComponentMenu(DisplayerComponentMenuPath._ComponentMenuPath
15 + DisplayerComponentMenuPath._Postfix)]
16 [RequireComponent(typeof(ParticleSystem))]
18 [SerializeField] Gradient _gradient;
19 ParticleSystem _particle_system;
21 ParticleSystem.MainModule _particle_system_main_module;
22 ParticleSystemRenderer _particle_system_renderer;
25 ParticleSystemSimulationSpace _particle_system_simulation_space = ParticleSystemSimulationSpace.World;
27 ParticleSystem.Particle[] _particles;
28 [SerializeField]
float _default_start_size = 0.6f;
30 List<float> _vs =
new List<float>();
35 protected override void Setup() {
36 this._particle_system = this.GetComponent<ParticleSystem>();
37 var em = this._particle_system.emission;
40 var sh = this._particle_system.shape;
43 this._particle_system_main_module = this._particle_system.main;
44 this._particle_system_main_module.loop =
false;
45 this._particle_system_main_module.playOnAwake =
false;
46 this._particle_system_main_module.simulationSpace = this._particle_system_simulation_space;
47 this._particle_system_main_module.simulationSpeed = 0;
48 this._particle_system_main_module.startSize = this._default_start_size;
50 this._particle_system_renderer = this.GetComponent<ParticleSystemRenderer>();
52 this._particle_system_renderer.alignment = ParticleSystemRenderSpace.World;
54 if (this._gradient == null) {
55 this._gradient =
new Gradient {
57 new GradientColorKey(
new Color(1, 0, 0), 0f),
58 new GradientColorKey(
new Color(0, 1, 0), 1f)
64 public override void Display(Double value) {
67 Debug.Log(
"Applying the double " + value +
" To " + this.name);
71 this._Values =
new[] {(float)value};
72 this.PlotSeries(this._Values);
75 public override void Display(
float[] values) {
79 foreach (var value
in values) {
83 Debug.Log(
"Applying the float array " + s +
" To " + this.name);
86 this._Values = values;
87 this.PlotSeries(values);
90 public override void Display(String values) {
93 Debug.Log(
"Applying the float array " + values +
" To " + this.name);
98 foreach (var value
in values.Split(
',')) {
99 this._vs.Add(
float.Parse(value));
102 this._Values = this._vs.ToArray();
103 this.PlotSeries(this._Values);
106 public override void Display(Vector3 value) {
throw new NotImplementedException(); }
107 public override void Display(Vector3[] value) { this.ScatterPlot(value); }
112 if (this._particles == null || this._particles.Length != points.Length) {
113 this._particles =
new ParticleSystem.Particle[points.Length];
117 if (this.Debugging) {
118 var points_str = points.Aggregate(
"",
121 + $
"({point._Pos.ToString()}, {point._Val},{point._Size})" 123 Debug.Log(
"Applying the points " + points_str +
" to " + this.name);
128 foreach (var point
in points) {
129 this._particles[i].remainingLifetime = 100000;
130 this._particles[i].position = point._Pos;
131 var clamped = Math.Min(Math.Max(0.0f, point._Val), 1.0f);
132 this._particles[i].startColor = this._gradient.Evaluate(clamped);
133 this._particles[i].startSize = point._Size;
134 this._particles[i].startSize3D = this._default_start_size.BroadcastVector3();
138 this._particle_system.SetParticles(this._particles, points.Length);
152 if (this.Debugging) {
153 Debug.Log(
"Applying the float " + values +
" To " + this.name);
157 this._Values =
new[] {values};
158 this.PlotSeries(this._Values);
165 if (this._particles == null || this._particles.Length != points.Length) {
166 this._particles =
new ParticleSystem.Particle[points.Length];
170 if (this.Debugging) {
171 var points_str = points.Aggregate(
"", (current, point) => current + point.ToString() +
", ");
172 Debug.Log(
"Applying the points " + points_str +
" To " + this.name);
177 var l = (float)points.Length;
178 foreach (var point in points) {
179 this._particles[i].remainingLifetime = 100000;
180 this._particles[i].position = point;
181 var clamped = Math.Min(Math.Max(0.0f, i / l), 1.0f);
182 this._particles[i].startColor = this._gradient.Evaluate(clamped);
183 this._particles[i].startSize = this._default_start_size;
184 this._particles[i].startSize3D = this._default_start_size.BroadcastVector3();
188 this._particle_system.SetParticles(this._particles, points.Length);
192 if (!this._particle_system) {
196 if (this._particles == null || this._particles.Length != points.Length) {
197 this._particles =
new ParticleSystem.Particle[points.Length];
201 if (this.Debugging) {
202 Debug.Log(
"Applying the series " + points +
" To " + this.name);
207 foreach (var point
in points) {
208 this._particles[i].remainingLifetime = 100000;
209 this._particles[i].position = Vector3.one * i;
210 var clamped = Math.Min(Math.Max(0.0f, point), 1.0f);
211 this._particles[i].startColor = this._gradient.Evaluate(clamped);
212 this._particles[i].startSize = this._default_start_size;
213 this._particles[i].startSize3D = this._default_start_size.BroadcastVector3();
217 this._particle_system.SetParticles(this._particles, points.Length);
224 if (!this._RetainLastPlot) {
225 if (this._particle_system) {
226 this._particle_system.Clear(
true);
237 if (!this._particle_system) {
241 if (this._particles == null || this._particles.Length != points.Length) {
242 this._particles =
new ParticleSystem.Particle[points.Length];
245 if (this.Debugging) {
246 Debug.Log(
"Applying the series " + points +
" To " + this.name);
250 var alive = this._particle_system.GetParticles(this._particles);
251 if (alive < points.Length) {
252 this._particles =
new ParticleSystem.Particle[points.Length];
256 foreach (var point
in points) {
257 this._particles[i].remainingLifetime = 100000;
258 this._particles[i].position = point._Pos;
259 this._particles[i].startColor = this._gradient.Evaluate(point._Val);
260 this._particles[i].startSize = point._Size;
261 this._particles[i].startSize3D = point._Size.BroadcastVector3();
265 this._particle_system.SetParticles(this._particles, points.Length);
override void Display(float values)
void ScatterPlot(Vector3[] points)
override void Display(Vector3[] value)
override void Display(String values)
override void Display(Points.StringPoint point)
override void Display(Points.ValuePoint[] points)
override void Display(Points.StringPoint[] points)
override void Display(Points.ValuePoint points)
override void Display(Double value)
void PlotSeries(float[] points)
override void Display(Vector3 value)
override void PlotSeries(Points.ValuePoint[] points)
override void Display(float[] values)