2 using System.Collections.Generic;
8 namespace droid.Runtime.Prototyping.Displayers.ScatterPlots {
12 [AddComponentMenu(DisplayerComponentMenuPath._ComponentMenuPath
14 + DisplayerComponentMenuPath._Postfix)]
15 [RequireComponent(typeof(ParticleSystem))]
17 [SerializeField] Gradient _gradient;
18 ParticleSystem _particle_system;
20 ParticleSystem.MainModule _particle_system_main_module;
21 ParticleSystemRenderer _particle_system_renderer;
24 ParticleSystemSimulationSpace _particle_system_simulation_space = ParticleSystemSimulationSpace.World;
26 ParticleSystem.Particle[] _particles;
27 [SerializeField]
float _size = 0.6f;
29 List<string> _vs =
new List<string>();
31 protected override void Setup() {
32 this._particle_system = this.GetComponent<ParticleSystem>();
33 var em = this._particle_system.emission;
36 var sh = this._particle_system.shape;
39 this._particle_system_main_module = this._particle_system.main;
40 this._particle_system_main_module.loop =
false;
41 this._particle_system_main_module.playOnAwake =
false;
42 this._particle_system_main_module.simulationSpace = this._particle_system_simulation_space;
43 this._particle_system_main_module.simulationSpeed = 0;
44 this._particle_system_main_module.startSize = this._size;
46 this._particle_system_renderer = this.GetComponent<ParticleSystemRenderer>();
48 this._particle_system_renderer.alignment = ParticleSystemRenderSpace.World;
50 if (this._gradient == null) {
51 this._gradient =
new Gradient {
53 new GradientColorKey(
new Color(1, 0, 0), 0f),
54 new GradientColorKey(
new Color(0, 1, 0), 1f)
60 public override void Display(Double value) {
63 Debug.Log(
"Applying the double " + value +
" To " + this.name);
67 this._Values =
new[] {value.ToString(CultureInfo.InvariantCulture)};
68 this.PlotSeries(this._Values);
71 public override void Display(
float[] values) {
75 foreach (var value
in values) {
79 Debug.Log(
"Applying the float array " + s +
" To " + this.name);
82 this._Values = values.Select(v => v.ToString(CultureInfo.InvariantCulture)).ToArray();
83 this.PlotSeries(values);
86 public override void Display(String values) {
89 Debug.Log(
"Applying the float array " + values +
" To " + this.name);
94 foreach (var value
in values.Split(
',')) {
98 this._Values = this._vs.ToArray();
99 this.PlotSeries(this._Values);
102 public override void Display(Vector3 value) {
throw new NotImplementedException(); }
103 public override void Display(Vector3[] value) { this.ScatterPlot(value); }
108 if (this._particles == null || this._particles.Length != points.Length) {
109 this._particles =
new ParticleSystem.Particle[points.Length];
113 if (this.Debugging) {
114 var points_str = points.Aggregate(
"",
117 + $
"({point._Pos.ToString()}, {point._Val},{point._Size})" 119 Debug.Log(
"Applying the points " + points_str +
" to " + this.name);
124 foreach (var point
in points) {
125 this._particles[i].remainingLifetime = 100000;
126 this._particles[i].position = point._Pos;
127 var clamped = Math.Min(Math.Max(0.0f, point._Val), 1.0f);
128 this._particles[i].startColor = this._gradient.Evaluate(clamped);
129 this._particles[i].startSize = point._Size;
133 this._particle_system.SetParticles(this._particles, points.Length);
143 if (this.Debugging) {
144 Debug.Log(
"Applying the float " + values +
" To " + this.name);
148 this._Values =
new[] {values.ToString(CultureInfo.InvariantCulture)};
149 this.PlotSeries(this._Values);
156 if (this._particles == null || this._particles.Length != points.Length) {
157 this._particles =
new ParticleSystem.Particle[points.Length];
161 if (this.Debugging) {
162 var points_str = points.Aggregate(
"", (current, point) => current + point.ToString() +
", ");
163 Debug.Log(
"Applying the points " + points_str +
" To " + this.name);
168 var l = (float)points.Length;
169 foreach (var point in points) {
170 this._particles[i].remainingLifetime = 100000;
171 this._particles[i].position = point;
172 var clamped = Math.Min(Math.Max(0.0f, i / l), 1.0f);
173 this._particles[i].startColor = this._gradient.Evaluate(clamped);
174 this._particles[i].startSize = 1f;
178 this._particle_system.SetParticles(this._particles, points.Length);
182 if (this._particles == null || this._particles.Length != points.Length) {
183 this._particles =
new ParticleSystem.Particle[points.Length];
187 if (this.Debugging) {
188 Debug.Log(
"Applying the series " + points +
" To " + this.name);
193 foreach (var point
in points) {
194 this._particles[i].remainingLifetime = 100000;
195 this._particles[i].position = Vector3.one * i;
196 var clamped = Math.Min(Math.Max(0.0f, point), 1.0f);
197 this._particles[i].startColor = this._gradient.Evaluate(clamped);
198 this._particles[i].startSize = 1f;
202 this._particle_system.SetParticles(this._particles, points.Length);
206 if (this._particles == null || this._particles.Length != points.Length) {
207 this._particles =
new ParticleSystem.Particle[points.Length];
211 if (this.Debugging) {
212 Debug.Log(
"Applying the series " + points +
" To " + this.name);
217 foreach (var point
in points) {
218 this._particles[i].remainingLifetime = 100000;
219 this._particles[i].position = Vector3.one * i;
220 this._particles[i].startSize = 1f;
224 this._particle_system.SetParticles(this._particles, points.Length);
231 var alive = this._particle_system.GetParticles(this._particles);
232 if (alive < points.Length) {
233 this._particles =
new ParticleSystem.Particle[points.Length];
237 foreach (var point
in points) {
238 this._particles[i].remainingLifetime = 100000;
239 this._particles[i].position = point._Pos;
240 this._particles[i].startColor = this._gradient.Evaluate(point._Val);
241 this._particles[i].startSize = point._Size;
245 this._particle_system.SetParticles(this._particles, points.Length);
override void Display(String values)
override void Display(Vector3 value)
void PlotSeries(string[] points)
override void Display(Points.ValuePoint points)
void PlotSeries(float[] points)
override void Display(Points.ValuePoint[] points)
void ScatterPlot(Vector3[] points)
override void Display(float values)
override void Display(Double value)
override void Display(Points.StringPoint[] points)
override void Display(float[] values)
override void Display(Points.StringPoint point)
override void PlotSeries(Points.ValuePoint[] points)
override void Display(Vector3[] value)