forked from sarbian/SmokeScreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelMultiParticlePersistFX.cs
829 lines (668 loc) · 27.3 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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
/*
* Copyright (c) 2014, Sébastien GAGGINI AKA Sarbian, France
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using SmokeScreen;
using UnityEngine;
[EffectDefinition("MODEL_MULTI_PARTICLE_PERSIST")]
public class ModelMultiParticlePersistFX : EffectBehaviour
{
#region Persistent fields
[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 bool collide = false;
[Persistent]
public float collideRatio = 0.0f;
[Persistent]
public Vector3 localRotation = Vector3.zero;
[Persistent]
public Vector3 localPosition = Vector3.zero;
[Persistent]
public Vector3 offsetDirection = Vector3.forward;
[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 compute
// the density afterwards. Units (SI): kg / m^3.
[Persistent]
public double initialDensity = .6;
// Whether to apply Archimedes' force, gravity and other things to the
// particle.
[Persistent]
public bool physical = false;
// How much the particles stick to objects they collide with.
[Persistent]
public double stickiness = 0.9;
[Persistent]
public double dragCoefficient = 0.1;
// Current Time % timeModulo is used as the time input
[Persistent]
public float timeModulo = 10;
// For how long the effect will be running after a single Emit()
// time input is overridden to be the remaining time while it runs
[Persistent]
public float singleEmitTimer = 0;
// The initial velocity of the particles will be offset by a random amount
// lying in a disk perpendicular to the mean initial velocity whose radius
// is randomOffsetMaxRadius. This is similar to Unity's 'Random Velocity'
// Setting, except it will sample the offset from a (normal) disk rather
// than from a cube. Units (SI): m/s.
// TODO Sarbian : have the init auto fill this one
[Persistent]
public float randomInitalVelocityOffsetMaxRadius = 0.0f;
#endregion Persistent fields
public MultiInputCurve emission;
public MultiInputCurve energy;
public MultiInputCurve speed;
public MultiInputCurve grow;
public MultiInputCurve scale;
public MultiInputCurve size;
public MultiInputCurve offset;
public MultiInputCurve force;
// Logarithmic growth applied to to the particle.
// The size at time t after emission will be approximately
// (Log(logarithmicGrowth * t + 1) + 1) * initialSize, assuming grow = 0.
public MultiInputCurve logGrow;
public MultiInputCurve linGrow;
public MultiInputCurve alpha;
public MultiInputCurve logAlphaDecay;
public MultiInputCurve linAlphaDecay;
// 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);
private List<PersistentKSPParticleEmitter> persistentEmitters;
private Shader shader;
public string node_backup = string.Empty;
private bool activated = true;
public bool showUI = false;
private static readonly List<ModelMultiParticlePersistFX> list = new List<ModelMultiParticlePersistFX>();
private float singleTimerEnd = 0;
private float timeModuloDelta = 0;
public static List<ModelMultiParticlePersistFX> List
{
get
{
return list;
}
}
public bool overRideInputs = false;
public readonly float[] inputs = new float[MultiInputCurve.inputsCount];
public List<ModelMultiParticlePersistFX> Instances
{
get
{
return list;
}
}
public ModelMultiParticlePersistFX()
{
winID = baseWinID++;
//Print("Constructor");
}
//~ModelMultiParticlePersistFX()
//{
// print("DESTROY ALL HUMAN");
// list.Remove(this);
//}
// if Die() is called for a debrit of vessel then all the
// vessel gameobject are removed without an OnDestroy call
// But an OnVesselDie message is send before, so we can
// Catch in time
public void OnVesselDie()
{
//Print("OnVesselDie : EJECT EJECT EJECT !");
this.OnDestroy();
}
private void OnDestroy()
{
//Print("OnDestroy");
if (persistentEmitters != null)
{
//Print("OnDestroy is GO !");
for (int i = 0; i < persistentEmitters.Count; i++)
{
persistentEmitters[i].Detach(0);
}
}
list.Remove(this);
}
public override void OnEvent()
{
//Print("OnEvent");
if (!activated || persistentEmitters == null)
{
return;
}
singleTimerEnd = this.singleEmitTimer + Time.fixedTime;
timeModuloDelta = singleTimerEnd % timeModulo;
// Old version Emitted 1 second of particle in one go
// New version set power to 1 for singleEmitTimer seconds
//UpdateEmitters(1);
//for (int i = 0; i < persistentEmitters.Count; i++)
//{
// persistentEmitters[i].pe.Emit();
//}
}
public override void OnEvent(float power)
{
//Print("OnEvent " + power);
if (persistentEmitters == null)
{
return;
}
if ((overRideInputs || power > 0 || Time.deltaTime <= this.singleTimerEnd) && activated)
{
UpdateEmitters(power);
for (int i = 0; i < persistentEmitters.Count; i++)
{
persistentEmitters[i].fixedEmit = true;
persistentEmitters[i].pe.emit = false;
}
}
else
{
for (int j = 0; j < persistentEmitters.Count; j++)
{
persistentEmitters[j].fixedEmit = false;
persistentEmitters[j].pe.emit = false;
}
}
}
public void FixedUpdate()
{
//Print("FixedUpdate");
if (persistentEmitters == null || this.hostPart == null || this.hostPart.rb == null)
{
return;
}
SmokeScreenConfig.UpdateParticlesCount();
//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);
//}
PersistentKSPParticleEmitter[] persistentKspParticleEmitters = persistentEmitters.ToArray();
for (int i = 0; i < persistentKspParticleEmitters.Length; i++)
{
PersistentKSPParticleEmitter persistentKspParticleEmitter = persistentKspParticleEmitters[i];
persistentKspParticleEmitter.EmitterOnUpdate(this.hostPart.rb.velocity + Krakensbane.GetFrameVelocity());
}
}
private void UpdateInputs(float power)
{
if (overRideInputs)
{
return;
}
float atmDensity = 1;
float surfaceVelMach = 1;
float partTemp = 1;
float externalTemp = 1;
float time;
if (Time.fixedTime > this.singleTimerEnd)
{
// timeModuloDelta makes the transition between the two state smooth
time = (Time.fixedTime - this.timeModuloDelta) % this.timeModulo;
}
else
{
time = singleTimerEnd - Time.fixedTime;
power = 1;
}
if (hostPart != null)
{
partTemp = hostPart.temperature;
if (hostPart.vessel != null)
{
Vessel vessel = hostPart.vessel;
atmDensity = (float)vessel.atmDensity;
externalTemp = vessel.flightIntegrator.getExternalTemperature();
// FAR use a nice config file to get the atmo info for each body.
// For now I'll just use Air for all.
const double magicNumberFromFAR = 1.4 * 8.3145 * 1000 / 28.96;
double speedOfSound = Math.Sqrt((externalTemp + 273.15) * magicNumberFromFAR);
surfaceVelMach = (float)(vessel.srf_velocity.magnitude / speedOfSound);
}
else
{
atmDensity =
(float)
FlightGlobals.getAtmDensity(
FlightGlobals.getStaticPressure(hostPart.transform.position, FlightGlobals.currentMainBody));
externalTemp = FlightGlobals.getExternalTemperature(hostPart.transform.position);
const double magicNumberFromFAR = 1.4 * 8.3145 * 1000 / 28.96;
double speedOfSound = Math.Sqrt((externalTemp + 273.15) * magicNumberFromFAR);
surfaceVelMach =
(float)
((hostPart.vel - FlightGlobals.currentMainBody.getRFrmVel(hostPart.transform.position)).magnitude
/ speedOfSound);
}
}
inputs[(int)MultiInputCurve.Inputs.power] = power;
inputs[(int)MultiInputCurve.Inputs.density] = atmDensity;
inputs[(int)MultiInputCurve.Inputs.mach] = surfaceVelMach;
inputs[(int)MultiInputCurve.Inputs.parttemp] = partTemp;
inputs[(int)MultiInputCurve.Inputs.externaltemp] = externalTemp;
inputs[(int)MultiInputCurve.Inputs.time] = time;
}
public void UpdateEmitters(float power)
{
UpdateInputs(power);
for (int i = 0; i < persistentEmitters.Count; i++)
{
PersistentKSPParticleEmitter pkpe = persistentEmitters[i];
float sizePower = size.Value(inputs) * fixedScale;
pkpe.pe.minSize = Mathf.Min(pkpe.minSizeBase * sizePower, sizeClamp);
pkpe.pe.maxSize = Mathf.Min(pkpe.maxSizeBase * sizePower, sizeClamp);
float emissionPower = emission.Value(inputs);
pkpe.pe.minEmission = Mathf.FloorToInt(pkpe.minEmissionBase * emissionPower);
pkpe.pe.maxEmission = Mathf.FloorToInt(pkpe.maxEmissionBase * emissionPower);
float energyPower = energy.Value(inputs);
pkpe.pe.minEnergy = pkpe.minEnergyBase * energyPower;
pkpe.pe.maxEnergy = pkpe.maxEnergyBase * energyPower;
float velocityPower = speed.Value(inputs);
pkpe.pe.localVelocity = pkpe.localVelocityBase * velocityPower;
pkpe.pe.worldVelocity = pkpe.worldVelocityBase * velocityPower;
float forcePower = force.Value(inputs);
pkpe.pe.force = pkpe.forceBase * forcePower;
pkpe.pe.sizeGrow = grow.Value(inputs);
float currentScale = scale.Value(inputs) * fixedScale;
pkpe.pe.shape1D = pkpe.scale1DBase * currentScale;
pkpe.pe.shape2D = pkpe.scale2DBase * currentScale;
pkpe.pe.shape3D = pkpe.scale3DBase * currentScale;
pkpe.sizeClamp = sizeClamp;
pkpe.randomInitalVelocityOffsetMaxRadius = randomInitalVelocityOffsetMaxRadius;
pkpe.physical = physical && !SmokeScreenConfig.Instance.globalPhysicalDisable;
pkpe.initialDensity = initialDensity;
pkpe.dragCoefficient = dragCoefficient;
pkpe.collide = collide && !SmokeScreenConfig.Instance.globalCollideDisable;
pkpe.stickiness = stickiness;
pkpe.collideRatio = collideRatio;
pkpe.logarithmicGrow = logGrow.Value(inputs);
pkpe.linearGrow = linGrow.Value(inputs);
if (this.alpha.Value(inputs) != 1 || this.linAlphaDecay.Value(inputs) != 0 || this.logAlphaDecay.Value(inputs) != 0)
{
Color[] cols = new Color[5];
for (int t = 0; t < 5; t++)
{
float a = Mathf.Clamp01(alpha.Value(inputs) * (1 - linAlphaDecay.Value(inputs) * (t / 4) - Mathf.Log(logAlphaDecay.Value(inputs) * (t / 4) + 1)));
cols[t] = new Color(a, a, a, a);
}
pkpe.pe.colorAnimation = cols;
pkpe.pe.doesAnimateColor = true;
}
pkpe.go.transform.localPosition = localPosition
+ offsetDirection.normalized * offset.Value(inputs) * fixedScale;
pkpe.go.transform.localRotation = Quaternion.Euler(localRotation);
// Bad code is bad
try
{
pkpe.pe.particleRenderMode = (ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), renderMode);
}
catch (ArgumentException)
{
}
}
}
public void Update()
{
//Print("Update");
if (persistentEmitters == null)
{
return;
}
for (int i = 0; i < persistentEmitters.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,
persistentEmitters[i].go.transform.forward);
float currentDist = (Camera.main.transform.position - persistentEmitters[i].go.transform.position).magnitude;
persistentEmitters[i].pe.maxParticleSize = persistentEmitters[i].maxSizeBase * angle.Value(currentAngle)
* distance.Value(currentDist);
persistentEmitters[i].pe.pr.maxParticleSize = persistentEmitters[i].pe.maxParticleSize;
}
}
public override void OnInitialize()
{
//Print("Init");
// Restore the Curve config from the node content backup
// Done because I could not get the serialization of MultiInputCurve to work
if (node_backup != string.Empty)
{
Restore();
}
// 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;
}
if (persistentEmitters == null)
{
persistentEmitters = new List<PersistentKSPParticleEmitter>();
}
for (int i = 0; i < transforms.Count; i++)
{
GameObject emitterGameObject = UnityEngine.Object.Instantiate(model) as GameObject;
KSPParticleEmitter childKSPParticleEmitter = emitterGameObject.GetComponentInChildren<KSPParticleEmitter>();
if (shader != null)
{
childKSPParticleEmitter.material.shader = shader;
childKSPParticleEmitter.pr.material.shader = shader;
}
if (childKSPParticleEmitter != null)
{
PersistentKSPParticleEmitter pkpe = new PersistentKSPParticleEmitter(
emitterGameObject,
childKSPParticleEmitter,
templateKspParticleEmitter);
try
{
childKSPParticleEmitter.particleRenderMode =
(ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), renderMode);
}
catch (ArgumentException)
{
Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleRenderMode");
}
persistentEmitters.Add(pkpe);
emitterGameObject.transform.SetParent(transforms[i]);
emitterGameObject.transform.localPosition = localPosition;
emitterGameObject.transform.localRotation = Quaternion.Euler(localRotation);
}
}
UnityEngine.Object.Destroy(templateKspParticleEmitter);
list.Add(this);
}
public void Backup(ConfigNode node)
{
node_backup = SmokeScreenUtil.WriteRootNode(node);
//print("Backup node_backup is\n " + node_backup.Replace(Environment.NewLine, Environment.NewLine + "ModelMultiParticlePersistFX "));
}
public void Restore()
{
//print("Restore node_backup is\n " + node_backup.Replace(Environment.NewLine, Environment.NewLine + "ModelMultiParticlePersistFX "));
string[] text = node_backup.Split(new string[] { "\n" }, StringSplitOptions.None);
ConfigNode node = SmokeScreenUtil.RecurseFormat(SmokeScreenUtil.PreFormatConfig(text));
this.OnLoad(node);
}
public override void OnLoad(ConfigNode node)
{
//Print("OnLoad");
Backup(node);
emission = new MultiInputCurve("emission");
energy = new MultiInputCurve("energy");
speed = new MultiInputCurve("speed");
grow = new MultiInputCurve("grow", true);
scale = new MultiInputCurve("scale");
size = new MultiInputCurve("size");
offset = new MultiInputCurve("offset", true);
force = new MultiInputCurve("force", true);
logGrow = new MultiInputCurve("logGrow", true);
linGrow = new MultiInputCurve("linGrow", true);
alpha = new MultiInputCurve("alpha");
linAlphaDecay = new MultiInputCurve("linAlphaDecay", true);
logAlphaDecay = new MultiInputCurve("logAlphaDecay", true);
ConfigNode.LoadObjectFromConfig(this, node);
emission.Load(node);
energy.Load(node);
speed.Load(node);
grow.Load(node);
scale.Load(node);
size.Load(node);
offset.Load(node);
force.Load(node);
logGrow.Load(node);
linGrow.Load(node);
alpha.Load(node);
linAlphaDecay.Load(node);
logAlphaDecay.Load(node);
angle.Load("angle", node);
distance.Load("distance", node);
}
public override void OnSave(ConfigNode node)
{
//Print("OnSave");
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);
force.Save(node);
logGrow.Save(node);
linGrow.Save(node);
alpha.Save(node);
linAlphaDecay.Save(node);
logAlphaDecay.Save(node);
angle.Save(node);
distance.Save(node);
}
private static void Print(String s)
{
MonoBehaviour.print("[SmokeScreen ModelMultiParticlePersistFX] " + s);
}
// TODO : move the whole UI stuff to a dedicated class - this is getting way to big
private Rect winPos = new Rect(50, 50, 400, 100);
private static int baseWinID = 512100;
private static int winID = baseWinID;
private string nodeText = "";
private bool nodeEdit = false;
private Vector2 scrollPosition = new Vector2();
private void OnGUI()
{
if (!HighLogic.LoadedSceneIsFlight)
{
return;
}
if (showUI && hostPart != null)
{
winPos = GUILayout.Window(
winID,
winPos,
windowGUI,
hostPart.name + " " + this.effectName + " " + this.instanceName,
GUILayout.MinWidth(300));
}
}
private void windowGUI(int ID)
{
GUILayout.BeginVertical();
activated = GUILayout.Toggle(activated, "Active");
GUILayout.Space(10);
overRideInputs = GUILayout.Toggle(overRideInputs, "Manual Inputs");
GUIInput((int)MultiInputCurve.Inputs.power, "Power");
GUIInput((int)MultiInputCurve.Inputs.density, "Atmo Density");
GUIInput((int)MultiInputCurve.Inputs.mach, "Mach Speed");
GUIInput((int)MultiInputCurve.Inputs.parttemp, "Part Temperature");
GUIInput((int)MultiInputCurve.Inputs.externaltemp, "External Temperature");
if (persistentEmitters.Count > 0)
{
GUILayout.Label("Shader: " + persistentEmitters[0].pe.pr.material.shader.name);
}
GUILayout.Space(10);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Single Emit Timer"))
{
this.OnEvent();
}
if (GUILayout.Button("Clear Particles"))
{
for (int i = 0; i < persistentEmitters.Count; i++)
{
persistentEmitters[i].pe.pe.ClearParticles();
}
}
GUILayout.EndHorizontal();
GUILayout.Space(10);
nodeEdit = GUILayout.Toggle(nodeEdit, "Open Config Editor");
if (nodeEdit)
{
GUILayout.BeginHorizontal();
// Set the node with what was in the .cfg
if (GUILayout.Button("Import"))
{
nodeText = string.Copy(node_backup);
//print("Displaying node \n " + nodeText.Replace("\n", "\n" + "ModelMultiParticlePersistFX "));
}
// Rebuild the text from the active config
if (GUILayout.Button("Rebuild"))
{
ConfigNode node = new ConfigNode();
this.OnSave(node);
nodeText = SmokeScreenUtil.WriteRootNode(node);
}
// Apply the text
if (GUILayout.Button("Apply"))
{
string[] text = nodeText.Split(new string[] { "\n" }, StringSplitOptions.None);
ConfigNode node = SmokeScreenUtil.RecurseFormat(SmokeScreenUtil.PreFormatConfig(text));
this.OnLoad(node);
}
GUILayout.EndHorizontal();
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUILayout.MinHeight(300));
nodeText = GUILayout.TextArea(nodeText, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
GUILayout.EndScrollView();
}
GUILayout.EndVertical();
GUI.DragWindow();
}
private readonly bool[] boxInput = new bool[MultiInputCurve.inputsCount];
private void GUIInput(int id, string text)
{
float min = minInput(id);
float max = maxInput(id);
GUILayout.Label(
text + " Val=" + inputs[id].ToString("F3") + " Min=" + min.ToString("F2") + " Max=" + max.ToString("F2"));
if (overRideInputs)
{
GUILayout.BeginHorizontal();
boxInput[id] = GUILayout.Toggle(boxInput[id], "", GUILayout.ExpandWidth(false));
if (boxInput[id])
{
float.TryParse(
GUILayout.TextField(inputs[id].ToString("F2"), GUILayout.ExpandWidth(true), GUILayout.Width(100)),
out inputs[id]);
}
else
{
inputs[id] = GUILayout.HorizontalSlider(
inputs[id],
minInput(id),
maxInput(id),
GUILayout.ExpandWidth(true));
}
GUILayout.EndHorizontal();
}
}
private float minInput(int id)
{
float min = emission.minInput[id];
min = Mathf.Min(min, energy.minInput[id]);
min = Mathf.Min(min, speed.minInput[id]);
min = Mathf.Min(min, grow.minInput[id]);
min = Mathf.Min(min, scale.minInput[id]);
min = Mathf.Min(min, size.minInput[id]);
min = Mathf.Min(min, offset.minInput[id]);
min = Mathf.Min(min, force.minInput[id]);
min = Mathf.Min(min, logGrow.minInput[id]);
min = Mathf.Min(min, linGrow.minInput[id]);
min = Mathf.Min(min, alpha.minInput[id]);
min = Mathf.Min(min, linAlphaDecay.minInput[id]);
min = Mathf.Min(min, logAlphaDecay.minInput[id]);
return min;
}
private float maxInput(int id)
{
float max = emission.maxInput[id];
max = Mathf.Max(max, energy.maxInput[id]);
max = Mathf.Max(max, speed.maxInput[id]);
max = Mathf.Max(max, grow.maxInput[id]);
max = Mathf.Max(max, scale.maxInput[id]);
max = Mathf.Max(max, size.maxInput[id]);
max = Mathf.Max(max, offset.maxInput[id]);
max = Mathf.Max(max, force.maxInput[id]);
max = Mathf.Max(max, logGrow.maxInput[id]);
max = Mathf.Max(max, linGrow.maxInput[id]);
max = Mathf.Max(max, alpha.maxInput[id]);
max = Mathf.Max(max, linAlphaDecay.maxInput[id]);
max = Mathf.Max(max, logAlphaDecay.maxInput[id]);
return max;
}
}