/
ModelMultiParticlePersistFX.cs
690 lines (525 loc) · 26.5 KB
/
ModelMultiParticlePersistFX.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/*
* Author: Sébastien GAGGINI AKA Sarbian, France
* License: Attribution 4.0 International (CC BY 4.0): http://creativecommons.org/licenses/by/4.0/
*
* Thanks to Nothke for all the feature ideas, testing and feedback
*
*/
using System;
using System.Collections.Generic;
using UnityEngine;
[EffectDefinition("MODEL_MULTI_PARTICLE_PERSIST")]
public class ModelMultiParticlePersistFX : EffectBehaviour
{
[Persistent]
public string modelName = string.Empty;
[Persistent]
public string transformName = string.Empty;
[Persistent]
public string shaderFileName = string.Empty;
[Persistent]
public string renderMode = "Billboard";
[Persistent]
public string collide = "false";
[Persistent]
public float collideRatio = 0.01f;
[Persistent]
public Vector3 localRotation = Vector3.zero;
[Persistent]
public Vector3 localPosition = Vector3.zero;
[Persistent]
public float fixedScale = 1;
[Persistent]
public float sizeClamp = 50;
// Initial density of the particle seen as sphere of radius size of perfect
// gas. We then assume (only true for ideally expanded exhaust) that the
// expansion is isobaric (by mixing with the atmosphere) in order to copmute
// the density afterwards. Units (SI): kg / m^3.
[Persistent]
public float initialDensity = .1f;
// Whether to apply Archimedes' force, gravity and other things to the particle.
[Persistent]
public bool physical = true;
public FXCurve emission = new FXCurve("emission", 1f);
public FXCurve energy = new FXCurve("energy", 1f);
public FXCurve speed = new FXCurve("speed", 1f);
public FXCurve grow = new FXCurve("grow", 0f);
public FXCurve scale = new FXCurve("scale", 1f);
public FXCurve size = new FXCurve("size", 1f);
public FXCurve offset = new FXCurve("offset", 0f);
public FXCurve emissionFromDensity = new FXCurve("density", 1f);
public FXCurve energyFromDensity = new FXCurve("density", 1f);
public FXCurve speedFromDensity = new FXCurve("density", 1f);
public FXCurve growFromDensity = new FXCurve("density", 0f);
public FXCurve scaleFromDensity = new FXCurve("density", 1f);
public FXCurve sizeFromDensity = new FXCurve("density", 1f);
public FXCurve offsetFromDensity = new FXCurve("density", 0f);
public FXCurve emissionFromMach = new FXCurve("mach", 1f);
public FXCurve energyFromMach = new FXCurve("mach", 1f);
public FXCurve speedFromMach = new FXCurve("mach", 1f);
public FXCurve growFromMach = new FXCurve("mach", 0f);
public FXCurve scaleFromMach = new FXCurve("mach", 1f);
public FXCurve sizeFromMach = new FXCurve("mach", 1f);
public FXCurve offsetFromMach = new FXCurve("mach", 0f);
// Those 2 curve are related to the angle and distance to cam
public FXCurve angle = new FXCurve("angle", 1f);
public FXCurve distance = new FXCurve("distance", 1f);
// Don't waste time on a division.
private const double fourThirdsPi = 4 / 3 * Math.PI;
private List<PersistantKSPParticleEmitter> peristantEmitters;
private float emissionPower;
private float minEmissionBase;
private float maxEmissionBase;
private float energyPower;
private float minEnergyBase;
private float maxEnergyBase;
private float sizePower;
private float minSizeBase;
private float maxSizeBase;
private float currentScale;
private float scale1DBase;
private Vector2 scale2DBase;
private Vector3 scale3DBase;
private float localVelocityPower;
private Vector3 localVelocityBase;
private Shader shader;
public static int activeParticles = 0;
public static int particuleDecimate = 0;
public static int particleCounter = 0;
// Particule Emitter with more than decimateFloor particules will have
// some particle culled if there is more than maximumActiveParticles active
public static int decimateFloor = 30;
public static int maximumActiveParticles = 20000;
private void OnDestroy()
{
if (peristantEmitters == null)
{
return;
}
for (int i = 0; i < peristantEmitters.Count; i++)
if (peristantEmitters[i].go != null && peristantEmitters[i].go.transform.parent != null)
{
peristantEmitters[i].pe.emit = false;
// detach from the parent so the emmitter(and its particle) don't get removed instantly
peristantEmitters[i].go.transform.parent = null;
}
}
public override void OnEvent()
{
if (peristantEmitters == null)
{
return;
}
UpdateEmitters(1);
for (int i = 0; i < peristantEmitters.Count; i++)
peristantEmitters[i].pe.Emit();
}
public override void OnEvent(float power)
{
if (peristantEmitters == null)
return;
if (power > 0f)
{
UpdateEmitters(power);
for (int i = 0; i < peristantEmitters.Count; i++)
peristantEmitters[i].pe.emit = true;
}
else
{
for (int j = 0; j < peristantEmitters.Count; j++)
peristantEmitters[j].pe.emit = false;
}
}
private List<Component> partColliders = new List<Component>();
bool addedLaunchPadCollider = false;
public void FixedUpdate()
{
if (peristantEmitters == null)
{
return;
}
ResetParticleCount();
RaycastHit hit = new RaycastHit();
bool collision = (collide != "false");
//RaycastHit vHit = new RaycastHit();
//Ray vRay = Camera.main.ScreenPointToRay(Input.mousePosition);
//if(Physics.Raycast(vRay, out vHit))
//{
// RaycastHit vHit2 = new RaycastHit();
// if (Physics.Raycast(vHit.point + vHit.normal * 10, -vHit.normal, out vHit2))
// Debug.Log(vHit2.collider.name);
//}
// "Default", "TransparentFX", "Local Scenery", "Ignore Raycast"
int mask = (1 << LayerMask.NameToLayer("Default")) | (1 << LayerMask.NameToLayer("Local Scenery"));
for (int i = 0; i < peristantEmitters.Count; i++)
{
Particle[] particles = peristantEmitters[i].pe.pe.particles;
for (int j = 0; j < particles.Length; j++)
{
// Check if we need to cull the number of particles
if (particuleDecimate != 0 && particles.Length > decimateFloor)
{
particleCounter++;
if ((particuleDecimate > 0 && (particleCounter % particuleDecimate) == 0) || (particuleDecimate < 0 && (particleCounter % particuleDecimate) != 0))
particles[j].energy = 0; // energy set to 0 remove the particle, as per Unity doc
}
if (particles[j].energy > 0)
{
particles[j].size = Mathf.Min(particles[j].size, sizeClamp);
if (physical) {
Vector3d pPos = peristantEmitters[i].pe.useWorldSpace ? particles[j].position : peristantEmitters[i].pe.transform.TransformPoint(particles[j].position);
Vector3d pVel = peristantEmitters[i].pe.useWorldSpace ? particles[j].velocity : peristantEmitters[i].pe.transform.TransformDirection(particles[j].velocity);
float r = particles[j].size;
float rMin = peristantEmitters[i].pe.minSize;
float rMax = peristantEmitters[i].pe.maxSize;
// TODO(robin): this a bad idea. There must be a way to
// keep the actual initial volume, but I'm lazy.
// N.B.: multiplications rather than Pow, Pow is slow,
// multiplication by .5 rather than division by 2 (same
// reason).
double estimatedInitialVolume = fourThirdsPi * rMin * rMin * rMin;
double currentVolume = fourThirdsPi * r * r * r;
double volumeChange = currentVolume - estimatedInitialVolume;
double density = (estimatedInitialVolume * initialDensity + volumeChange) / currentVolume;
double atmosphericDensity = FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(pPos));
Vector3d acceleration = (1 - (atmosphericDensity / density)) * FlightGlobals.getGeeForceAtPosition(pPos);
// Euler is good enough for graphics.
pVel = pVel + acceleration * TimeWarp.fixedDeltaTime;
particles[j].velocity = (peristantEmitters[i].pe.useWorldSpace ? (Vector3)pVel : peristantEmitters[i].pe.transform.InverseTransformDirection(pVel));
}
if (collision)
{
Vector3 pPos = peristantEmitters[i].pe.useWorldSpace ? particles[j].position : peristantEmitters[i].pe.transform.TransformPoint(particles[j].position);
Vector3 pVel = peristantEmitters[i].pe.useWorldSpace ? particles[j].velocity : peristantEmitters[i].pe.transform.TransformDirection(particles[j].velocity);
if (Physics.Raycast(pPos, pVel, out hit, particles[j].velocity.magnitude * 2f * TimeWarp.fixedDeltaTime, mask))
if (hit.collider.name != "Launch Pad Grate")
{
Vector3 hVel = Vector3.Exclude(hit.normal, pVel);
Vector3 reflectedNormalVelocity = hVel - pVel;
// An attempt at a better velocity change; the blob collides with some
// restitution coefficient collideRatio << 1 and we add a random horizonal term
// for flow conservation---randomness handwaved in through fluid dynamics:
Vector3 flowConservationDirection = Vector3.Exclude(hit.normal, UnityEngine.Random.onUnitSphere);
pVel = hVel + collideRatio * reflectedNormalVelocity + flowConservationDirection * (1 - collideRatio) * reflectedNormalVelocity.magnitude;
particles[j].velocity = (peristantEmitters[i].pe.useWorldSpace ? pVel : peristantEmitters[i].pe.transform.InverseTransformDirection(pVel));
}
else
{
// Don't collide with the launch pad grid and add colliders under it
if (!addedLaunchPadCollider)
AddLaunchPadColliders(hit);
}
}
}
}
peristantEmitters[i].pe.pe.particles = particles;
activeParticles += peristantEmitters[i].pe.pe.particleCount;
}
}
private const string LaunchPadColliderName = "LaunchPadColliderSmokeScreen";
private void AddLaunchPadColliders(RaycastHit hit)
{
// the Grate Collider size is (37.70, 20.22, 3.47). Way larger that the actual grate
// The current collider do not cover all this area. More are needed
Transform parentTransform = hit.collider.gameObject.transform;
// Are the collider already here ?
if (parentTransform.FindChild(LaunchPadColliderName))
{
addedLaunchPadCollider = true;
return;
}
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.name = LaunchPadColliderName;
cube.renderer.material.color = Color.green;
cube.transform.parent = parentTransform;
cube.transform.localPosition = new Vector3(8.5f, 0, 2.3f);
cube.transform.localRotation = parentTransform.localRotation;
cube.transform.localScale = new Vector3(0.1f, 7, 16);
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.name = LaunchPadColliderName;
cube.renderer.material.color = Color.green;
cube.transform.parent = parentTransform;
cube.transform.localPosition = new Vector3(7, 10.5f, 2.3f);
cube.transform.localRotation = parentTransform.localRotation * Quaternion.Euler(0, 60, 0);
cube.transform.localScale = new Vector3(7f, 7, 0.1f);
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.name = LaunchPadColliderName;
cube.renderer.material.color = Color.green;
cube.transform.parent = parentTransform;
cube.transform.localPosition = new Vector3(7, -10.5f, 2.3f);
cube.transform.localRotation = parentTransform.localRotation * Quaternion.Euler(0, -60, 0);
cube.transform.localScale = new Vector3(7f, 7, 0.1f);
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.name = LaunchPadColliderName;
cube.renderer.material.color = Color.green;
cube.transform.parent = parentTransform;
cube.transform.localPosition = new Vector3(-8.5f, 0, 2.3f);
cube.transform.localRotation = parentTransform.localRotation;
cube.transform.localScale = new Vector3(0.1f, 7, 16);
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.name = LaunchPadColliderName;
cube.renderer.material.color = Color.green;
cube.transform.parent = parentTransform;
cube.transform.localPosition = new Vector3(-7, 10.5f, 2.3f);
cube.transform.localRotation = parentTransform.localRotation * Quaternion.Euler(0, -60, 0);
cube.transform.localScale = new Vector3(7f, 7, 0.1f);
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.name = LaunchPadColliderName;
cube.renderer.material.color = Color.green;
cube.transform.parent = parentTransform;
cube.transform.localPosition = new Vector3(-7, -10.5f, 2.3f);
cube.transform.localRotation = parentTransform.localRotation * Quaternion.Euler(0, 60, 0);
cube.transform.localScale = new Vector3(7f, 7, 0.1f);
addedLaunchPadCollider = true;
}
private static float lastTime = 0;
private void ResetParticleCount()
{
if (lastTime != Time.fixedTime)
{
if (activeParticles > maximumActiveParticles)
{
int toRemove = activeParticles - maximumActiveParticles;
if (toRemove < maximumActiveParticles)
particuleDecimate = activeParticles / (toRemove + 1); // positive we remove each n
else
particuleDecimate = -activeParticles / maximumActiveParticles; // negative we keep each n
}
else
particuleDecimate = 0;
//print(activeParticles + " " + particuleDecimate + " " + particleCounter);
activeParticles = 0;
lastTime = Time.fixedTime;
}
}
public void UpdateEmitters(float power)
{
float atmDensity = 1;
float surfaceVelMach = 1;
if (hostPart != null && hostPart.vessel != null)
{
Vessel vessel = hostPart.vessel;
atmDensity = (float)vessel.atmDensity;
// does not work
//float p = (float)FlightGlobals.getStaticPressure(vessel.altitude, vessel.mainBody);
//float speedOfSound = Mathf.Sqrt(1.4f * p / atmDensity);
// Cheating for now
double speedOfSound = 343.2f;
surfaceVelMach = (float)(vessel.srf_velocity.magnitude / speedOfSound);
}
for (int i = 0; i < peristantEmitters.Count; i++)
{
sizePower = size.Value(power) * sizeFromDensity.Value(atmDensity) * sizeFromMach.Value(surfaceVelMach);
peristantEmitters[i].pe.minSize = Mathf.Min(minSizeBase * sizePower, sizeClamp);
peristantEmitters[i].pe.maxSize = Mathf.Min(maxSizeBase * sizePower, sizeClamp);
emissionPower = emission.Value(power) * emissionFromDensity.Value(atmDensity) * emissionFromMach.Value(surfaceVelMach);
peristantEmitters[i].pe.minEmission = Mathf.FloorToInt(minEmissionBase * emissionPower);
peristantEmitters[i].pe.maxEmission = Mathf.FloorToInt(maxEmissionBase * emissionPower);
energyPower = energy.Value(power) * energyFromDensity.Value(atmDensity) * energyFromMach.Value(surfaceVelMach);
peristantEmitters[i].pe.minEnergy = minEnergyBase * energyPower;
peristantEmitters[i].pe.maxEnergy = maxEnergyBase * energyPower;
localVelocityPower = speed.Value(power) * speedFromDensity.Value(atmDensity) * speedFromMach.Value(surfaceVelMach);
peristantEmitters[i].pe.localVelocity = localVelocityBase * localVelocityPower;
peristantEmitters[i].pe.sizeGrow = grow.Value(power) + growFromDensity.Value(atmDensity) + growFromMach.Value(surfaceVelMach);
currentScale = scale.Value(power) * scaleFromDensity.Value(atmDensity) * scaleFromMach.Value(surfaceVelMach);
peristantEmitters[i].pe.shape1D = scale1DBase * currentScale;
peristantEmitters[i].pe.shape2D = scale2DBase * currentScale;
peristantEmitters[i].pe.shape3D = scale3DBase * currentScale;
peristantEmitters[i].go.transform.localPosition = Vector3d.forward * ( offset.Value(power) + offsetFromDensity.Value(atmDensity) + offsetFromMach.Value(surfaceVelMach));
//print(atmDensity.ToString("F2") + " " + offset.Value(power).ToString("F2") + " " + offsetFromDensity.Value(atmDensity).ToString("F2") + " " + offsetFromMach.Value(surfaceVelMach).ToString("F2"));
}
}
public void Update()
{
if (peristantEmitters == null)
{
return;
}
for (int i = 0; i < peristantEmitters.Count; i++)
{
// using Camera.main will mess up anything multi cam but using current require adding a OnWillRenderObject() to the ksp particle emitter GameObject (? not tested)
float currentAngle = Vector3.Angle(-Camera.main.transform.forward, peristantEmitters[i].go.transform.forward);
float currentDist = (Camera.main.transform.position - peristantEmitters[i].go.transform.position).magnitude;
peristantEmitters[i].pe.maxParticleSize = peristantEmitters[i].baseMaxSize * angle.Value(currentAngle) * distance.Value(currentDist);
peristantEmitters[i].pe.pr.maxParticleSize = peristantEmitters[i].pe.maxParticleSize;
}
}
public override void OnInitialize()
{
#if TRACE
print("ModelMultiParticlePersistFX.OnInitialize called;");
#endif
// The shader loading require proper testing
// Unity doc says that "Creating materials this way supports only simple shaders (fixed function ones).
// If you need a surface shader, or vertex/pixel shaders, you'll need to create shader asset in the editor and use that."
// But importing the same shader that the one used in the editor seems to work
string filename = KSPUtil.ApplicationRootPath + "GameData/" + shaderFileName;
if (shaderFileName != String.Empty && System.IO.File.Exists(filename))
{
try
{
System.IO.TextReader shaderFile = new System.IO.StreamReader(filename);
string shaderText = shaderFile.ReadToEnd();
shader = new Material(shaderText).shader;
}
catch (Exception e)
{
print("unable to load shader " + shaderFileName + " : " + e.ToString());
}
}
List<Transform> transforms = new List<Transform>(hostPart.FindModelTransforms(transformName));
if (transforms.Count == 0)
{
print("Cannot find transform " + transformName);
return;
}
GameObject model = GameDatabase.Instance.GetModel(modelName);
if (model == null)
{
print("Cannot find model " + modelName);
return;
}
model.SetActive(true);
KSPParticleEmitter templateKspParticleEmitter = model.GetComponentInChildren<KSPParticleEmitter>();
if (templateKspParticleEmitter == null)
{
print("Cannot find particle emitter on " + modelName);
UnityEngine.Object.Destroy(model);
return;
}
if (shader != null)
templateKspParticleEmitter.material.shader = shader;
// TODO : move those in PersistantKSPParticleEmitter
scale1DBase = (templateKspParticleEmitter.shape1D *= fixedScale);
scale2DBase = (templateKspParticleEmitter.shape2D *= fixedScale);
scale3DBase = (templateKspParticleEmitter.shape3D *= fixedScale);
minEmissionBase = (float)templateKspParticleEmitter.minEmission;
maxEmissionBase = (float)templateKspParticleEmitter.maxEmission;
minEnergyBase = templateKspParticleEmitter.minEnergy;
maxEnergyBase = templateKspParticleEmitter.maxEnergy;
minSizeBase = (float)templateKspParticleEmitter.minSize;
maxSizeBase = (float)templateKspParticleEmitter.maxSize;
localVelocityBase = templateKspParticleEmitter.localVelocity;
if (peristantEmitters == null)
peristantEmitters = new List<PersistantKSPParticleEmitter>();
for (int i = 0; i < transforms.Count; i++)
{
GameObject emmitterGameObject = UnityEngine.Object.Instantiate(model) as GameObject;
KSPParticleEmitter componentInChildren = emmitterGameObject.GetComponentInChildren<KSPParticleEmitter>();
PersistantKSPParticleEmitter pkpe = new PersistantKSPParticleEmitter(emmitterGameObject, componentInChildren, templateKspParticleEmitter.maxParticleSize);
if (componentInChildren != null)
{
componentInChildren.shape1D *= fixedScale;
componentInChildren.shape2D *= fixedScale;
componentInChildren.shape3D *= fixedScale;
try
{
componentInChildren.particleRenderMode = (ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), renderMode);
}
catch (ArgumentException)
{
print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleRenderMode");
}
peristantEmitters.Add(pkpe);
}
emmitterGameObject.transform.SetParent(transforms[i]);
emmitterGameObject.transform.localPosition = localPosition;
emmitterGameObject.transform.localRotation = Quaternion.Euler(localRotation);
PersistantEmitterManager.Add(pkpe);
}
UnityEngine.Object.Destroy(templateKspParticleEmitter);
}
public override void OnLoad(ConfigNode node)
{
ConfigNode.LoadObjectFromConfig(this, node);
emission.Load("emission", node);
energy.Load("energy", node);
speed.Load("speed", node);
grow.Load("grow", node);
scale.Load("scale", node);
size.Load("size", node);
offset.Load("offset", node);
angle.Load("angle", node);
distance.Load("distance", node);
if (node.HasNode("emission"))
{
emissionFromDensity.Load("density", node.GetNode("emission"));
emissionFromMach.Load("mach", node.GetNode("emission"));
}
if (node.HasNode("energy"))
{
energyFromDensity.Load("density", node.GetNode("energy"));
energyFromMach.Load("mach", node.GetNode("energy"));
}
if (node.HasNode("speed"))
{
speedFromDensity.Load("density", node.GetNode("speed"));
speedFromMach.Load("mach", node.GetNode("speed"));
}
if (node.HasNode("grow"))
{
growFromDensity.Load("density", node.GetNode("grow"));
growFromMach.Load("mach", node.GetNode("grow"));
}
if (node.HasNode("size"))
{
sizeFromDensity.Load("density", node.GetNode("size"));
sizeFromMach.Load("mach", node.GetNode("size"));
}
if (node.HasNode("scale"))
{
scaleFromDensity.Load("density", node.GetNode("scale"));
scaleFromMach.Load("mach", node.GetNode("scale"));
}
if (node.HasNode("offset"))
{
offsetFromDensity.Load("density", node.GetNode("offset"));
offsetFromMach.Load("mach", node.GetNode("offset"));
}
}
public override void OnSave(ConfigNode node)
{
ConfigNode.CreateConfigFromObject(this, node);
emission.Save(node);
energy.Save(node);
speed.Save(node);
grow.Save(node);
scale.Save(node);
size.Save(node);
offset.Save(node);
angle.Save(node);
distance.Save(node);
ConfigNode subNode = new ConfigNode("emission");
emissionFromDensity.Save(subNode);
emissionFromMach.Save(subNode);
node.AddNode(subNode);
subNode = new ConfigNode("energy");
energyFromDensity.Save(subNode);
energyFromMach.Save(subNode);
node.AddNode(subNode);
subNode = new ConfigNode("speed");
speedFromDensity.Save(subNode);
speedFromMach.Save(subNode);
node.AddNode(subNode);
subNode = new ConfigNode("grow");
growFromDensity.Save(subNode);
growFromMach.Save(subNode);
node.AddNode(subNode);
subNode = new ConfigNode("size");
sizeFromDensity.Save(subNode);
sizeFromMach.Save(subNode);
node.AddNode(subNode);
subNode = new ConfigNode("scale");
scaleFromDensity.Save(subNode);
scaleFromMach.Save(subNode);
node.AddNode(subNode);
subNode = new ConfigNode("emoffset");
offsetFromDensity.Save(subNode);
offsetFromMach.Save(subNode);
node.AddNode(subNode);
}
private void print(String s)
{
MonoBehaviour.print(this.GetType().Name + " : " + s);
}
}