forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleSystemCurveEditor.cs
More file actions
741 lines (696 loc) · 27.5 KB
/
ParticleSystemCurveEditor.cs
File metadata and controls
741 lines (696 loc) · 27.5 KB
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
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
internal class ParticleSystemCurveEditor
{
public const float k_PresetsHeight = 30f;
private List<CurveData> m_AddedCurves;
private List<Color> m_AvailableColors;
private Color[] m_Colors;
private CurveEditor m_CurveEditor;
private static CurveEditorSettings m_CurveEditorSettings = new CurveEditorSettings();
private DoubleCurvePresetsContentsForPopupWindow m_DoubleCurvePresets;
private int m_LastTopMostCurveID = -1;
internal static Styles s_Styles;
private void Add(CurveData cd)
{
this.m_CurveEditor.SelectNone();
this.m_AddedCurves.Add(cd);
this.ContentChanged();
SessionState.SetVector3(cd.m_UniqueName, new Vector3(cd.m_Color.r, cd.m_Color.g, cd.m_Color.b));
this.UpdateRangeBasedOnShownCurves();
}
public void AddCurve(CurveData curveData)
{
this.Add(curveData);
}
public void AddCurveDataIfNeeded(string curveName, CurveData curveData)
{
Vector3 vector = SessionState.GetVector3(curveName, Vector3.zero);
if (vector != Vector3.zero)
{
Color color = new Color(vector.x, vector.y, vector.z);
curveData.m_Color = color;
this.AddCurve(curveData);
for (int i = 0; i < this.m_AvailableColors.Count; i++)
{
if (SameColor(this.m_AvailableColors[i], color))
{
this.m_AvailableColors.RemoveAt(i);
break;
}
}
}
}
private void ContentChanged()
{
this.m_CurveEditor.animationCurves = this.CreateCurveWrapperArray();
m_CurveEditorSettings.showAxisLabels = this.m_CurveEditor.animationCurves.Length > 0;
}
private CurveWrapper CreateCurveWrapper(SerializedProperty curve, int id, int regionId, Color color, bool signedRange, CurveWrapper.GetAxisScalarsCallback getAxisScalarsCallback, CurveWrapper.SetAxisScalarsCallback setAxisScalarsCallback)
{
CurveWrapper wrapper = new CurveWrapper {
id = id,
regionId = regionId,
color = color,
renderer = new NormalCurveRenderer(curve.animationCurveValue)
};
wrapper.renderer.SetWrap(curve.animationCurveValue.preWrapMode, curve.animationCurveValue.postWrapMode);
if (wrapper.curve.keys.Length == 1)
{
wrapper.renderer.SetCustomRange(0f, 1f);
wrapper.wrapColorMultiplier = Color.clear;
}
else
{
wrapper.renderer.SetCustomRange(0f, 0f);
wrapper.wrapColorMultiplier = color;
}
wrapper.vRangeMin = !signedRange ? 0f : -1f;
wrapper.getAxisUiScalarsCallback = getAxisScalarsCallback;
wrapper.setAxisUiScalarsCallback = setAxisScalarsCallback;
return wrapper;
}
private CurveWrapper[] CreateCurveWrapperArray()
{
List<CurveWrapper> list = new List<CurveWrapper>();
int num = 0;
for (int i = 0; i < this.m_AddedCurves.Count; i++)
{
CurveData data = this.m_AddedCurves[i];
if (data.m_Visible)
{
int regionId = -1;
if (data.IsRegion())
{
regionId = ++num;
}
if (data.m_Max != null)
{
list.Add(this.CreateCurveWrapper(data.m_Max, data.m_MaxId, regionId, data.m_Color, data.m_SignedRange, data.m_GetAxisScalarsCallback, data.m_SetAxisScalarsCallback));
}
if (data.m_Min != null)
{
list.Add(this.CreateCurveWrapper(data.m_Min, data.m_MinId, regionId, data.m_Color, data.m_SignedRange, data.m_GetAxisScalarsCallback, data.m_SetAxisScalarsCallback));
}
}
}
return list.ToArray();
}
private DoubleCurve CreateDoubleCurveFromTopMostCurve()
{
int num;
if (this.m_CurveEditor.GetTopMostCurveID(out num))
{
for (int i = 0; i < this.m_AddedCurves.Count; i++)
{
CurveData data = this.m_AddedCurves[i];
if ((data.m_MaxId == num) || (data.m_MinId == num))
{
AnimationCurve maxCurve = null;
AnimationCurve minCurve = null;
if (data.m_Min != null)
{
minCurve = data.m_Min.animationCurveValue;
}
if (data.m_Max != null)
{
maxCurve = data.m_Max.animationCurveValue;
}
return new DoubleCurve(minCurve, maxCurve, data.m_SignedRange);
}
}
}
return null;
}
private void DoLabelForTopMostCurve(Rect rect)
{
int num;
if ((this.m_CurveEditor.IsDraggingCurveOrRegion() || (this.m_CurveEditor.selectedCurves.Count <= 1)) && this.m_CurveEditor.GetTopMostCurveID(out num))
{
for (int i = 0; i < this.m_AddedCurves.Count; i++)
{
if ((this.m_AddedCurves[i].m_MaxId == num) || (this.m_AddedCurves[i].m_MinId == num))
{
s_Styles.yAxisHeader.normal.textColor = this.m_AddedCurves[i].m_Color;
GUI.Label(rect, this.m_AddedCurves[i].m_DisplayName, s_Styles.yAxisHeader);
break;
}
}
}
}
private void DoOptimizeCurveButton(Rect rect)
{
if (!this.m_CurveEditor.IsDraggingCurveOrRegion())
{
Rect position = new Rect((rect.xMax - 10f) - 14f, rect.y + ((rect.height - 14f) * 0.5f), 14f, 14f);
int num = 0;
List<CurveSelection> selectedCurves = this.m_CurveEditor.selectedCurves;
if (selectedCurves.Count > 0)
{
for (int i = 0; i < selectedCurves.Count; i++)
{
CurveWrapper curveWrapperFromSelection = this.m_CurveEditor.GetCurveWrapperFromSelection(selectedCurves[i]);
num += !AnimationUtility.IsValidPolynomialCurve(curveWrapperFromSelection.curve) ? 0 : 1;
}
if ((selectedCurves.Count != num) && GUI.Button(position, s_Styles.optimizeCurveText, s_Styles.plus))
{
for (int j = 0; j < selectedCurves.Count; j++)
{
CurveWrapper wrapper2 = this.m_CurveEditor.GetCurveWrapperFromSelection(selectedCurves[j]);
if (!AnimationUtility.IsValidPolynomialCurve(wrapper2.curve))
{
wrapper2.curve.preWrapMode = WrapMode.Once;
wrapper2.curve.postWrapMode = WrapMode.Once;
wrapper2.renderer.SetWrap(WrapMode.Once, WrapMode.Once);
AnimationUtility.ConstrainToPolynomialCurve(wrapper2.curve);
wrapper2.changed = true;
}
}
this.m_CurveEditor.SelectNone();
}
}
else
{
int num4;
if (this.m_CurveEditor.GetTopMostCurveID(out num4))
{
CurveWrapper curveWrapperFromID = this.m_CurveEditor.GetCurveWrapperFromID(num4);
if (!AnimationUtility.IsValidPolynomialCurve(curveWrapperFromID.curve) && GUI.Button(position, s_Styles.optimizeCurveText, s_Styles.plus))
{
curveWrapperFromID.curve.preWrapMode = WrapMode.Once;
curveWrapperFromID.curve.postWrapMode = WrapMode.Once;
curveWrapperFromID.renderer.SetWrap(WrapMode.Once, WrapMode.Once);
AnimationUtility.ConstrainToPolynomialCurve(curveWrapperFromID.curve);
curveWrapperFromID.changed = true;
}
}
}
}
}
private void DoRemoveSelectedButton(Rect rect)
{
if (this.m_CurveEditor.animationCurves.Length != 0)
{
float width = 14f;
Rect position = new Rect(((rect.x + rect.width) - width) - 10f, rect.y + ((rect.height - width) * 0.5f), width, width);
if (GUI.Button(position, s_Styles.removeCurveText, s_Styles.minus))
{
if (this.m_CurveEditor.selectedCurves.Count > 0)
{
this.RemoveSelected();
}
else
{
this.RemoveTopMost();
}
}
}
}
private int FindIndex(SerializedProperty prop) =>
this.FindIndex(null, prop);
private int FindIndex(SerializedProperty min, SerializedProperty max)
{
if (max != null)
{
if (min == null)
{
for (int i = 0; i < this.m_AddedCurves.Count; i++)
{
if (this.m_AddedCurves[i].m_Max == max)
{
return i;
}
}
}
else
{
for (int j = 0; j < this.m_AddedCurves.Count; j++)
{
if ((this.m_AddedCurves[j].m_Max == max) && (this.m_AddedCurves[j].m_Min == min))
{
return j;
}
}
}
}
return -1;
}
public Color GetAvailableColor()
{
if (this.m_AvailableColors.Count == 0)
{
this.m_AvailableColors = new List<Color>(this.m_Colors);
}
int index = this.m_AvailableColors.Count - 1;
Color color = this.m_AvailableColors[index];
this.m_AvailableColors.RemoveAt(index);
return color;
}
public Color GetCurveColor(SerializedProperty max)
{
int num = this.FindIndex(max);
if ((num >= 0) && (num < this.m_AddedCurves.Count))
{
return this.m_AddedCurves[num].m_Color;
}
return new Color(0.8f, 0.8f, 0.8f, 0.7f);
}
public void Init()
{
if (this.m_AddedCurves == null)
{
this.m_AddedCurves = new List<CurveData>();
this.m_Colors = new Color[] { new Color(1f, 0.6196079f, 0.1294118f), new Color(0.8745098f, 0.2117647f, 0.5803922f), new Color(0f, 0.6862745f, 1f), new Color(1f, 0.9215686f, 0f), new Color(0.1960784f, 1f, 0.2666667f), new Color(0.9803922f, 0f, 0f) };
this.m_AvailableColors = new List<Color>(this.m_Colors);
m_CurveEditorSettings.useFocusColors = true;
m_CurveEditorSettings.showAxisLabels = false;
m_CurveEditorSettings.hRangeMin = 0f;
m_CurveEditorSettings.vRangeMin = 0f;
m_CurveEditorSettings.vRangeMax = 1f;
m_CurveEditorSettings.hRangeMax = 1f;
m_CurveEditorSettings.vSlider = false;
m_CurveEditorSettings.hSlider = false;
m_CurveEditorSettings.showWrapperPopups = true;
m_CurveEditorSettings.rectangleToolFlags = CurveEditorSettings.RectangleToolFlags.MiniRectangleTool;
m_CurveEditorSettings.hTickLabelOffset = 5f;
m_CurveEditorSettings.allowDraggingCurvesAndRegions = true;
m_CurveEditorSettings.allowDeleteLastKeyInCurve = false;
TickStyle style = new TickStyle {
tickColor = { color = new Color(0f, 0f, 0f, 0.2f) },
distLabel = 30,
stubs = false,
centerLabel = true
};
m_CurveEditorSettings.hTickStyle = style;
TickStyle style2 = new TickStyle {
tickColor = { color = new Color(0f, 0f, 0f, 0.2f) },
distLabel = 20,
stubs = false,
centerLabel = true
};
m_CurveEditorSettings.vTickStyle = style2;
this.m_CurveEditor = new CurveEditor(new Rect(0f, 0f, 1000f, 100f), this.CreateCurveWrapperArray(), false);
this.m_CurveEditor.settings = m_CurveEditorSettings;
this.m_CurveEditor.leftmargin = 40f;
float num = 25f;
this.m_CurveEditor.bottommargin = num;
this.m_CurveEditor.topmargin = num;
this.m_CurveEditor.rightmargin = num;
this.m_CurveEditor.SetShownHRangeInsideMargins(m_CurveEditorSettings.hRangeMin, m_CurveEditorSettings.hRangeMax);
this.m_CurveEditor.SetShownVRangeInsideMargins(m_CurveEditorSettings.vRangeMin, m_CurveEditorSettings.hRangeMax);
this.m_CurveEditor.ignoreScrollWheelUntilClicked = false;
Undo.undoRedoPerformed = (Undo.UndoRedoCallback) Delegate.Combine(Undo.undoRedoPerformed, new Undo.UndoRedoCallback(this.UndoRedoPerformed));
}
}
private void InitDoubleCurvePresets()
{
int num;
if (this.m_CurveEditor.GetTopMostCurveID(out num) && ((this.m_DoubleCurvePresets == null) || (this.m_LastTopMostCurveID != num)))
{
this.m_LastTopMostCurveID = num;
Action<DoubleCurve> presetSelectedCallback = delegate (DoubleCurve presetDoubleCurve) {
this.SetTopMostCurve(presetDoubleCurve);
InternalEditorUtility.RepaintAllViews();
};
DoubleCurve doubleCurveToSave = this.CreateDoubleCurveFromTopMostCurve();
this.m_DoubleCurvePresets = new DoubleCurvePresetsContentsForPopupWindow(doubleCurveToSave, presetSelectedCallback);
this.m_DoubleCurvePresets.InitIfNeeded();
}
}
public bool IsAdded(SerializedProperty max) =>
(this.FindIndex(null, max) != -1);
public bool IsAdded(SerializedProperty min, SerializedProperty max) =>
(this.FindIndex(min, max) != -1);
public void OnDestroy()
{
this.m_DoubleCurvePresets.GetPresetLibraryEditor().UnloadUsedLibraries();
}
public void OnDisable()
{
this.m_CurveEditor.OnDisable();
Undo.undoRedoPerformed = (Undo.UndoRedoCallback) Delegate.Remove(Undo.undoRedoPerformed, new Undo.UndoRedoCallback(this.UndoRedoPerformed));
}
public void OnGUI(Rect rect)
{
this.Init();
if (s_Styles == null)
{
s_Styles = new Styles();
}
Rect position = new Rect(rect.x, rect.y, rect.width, rect.height - 30f);
Rect rect3 = new Rect(rect.x, rect.y + position.height, rect.width, 30f);
GUI.Label(position, GUIContent.none, s_Styles.curveEditorBackground);
if (Event.current.type == EventType.Repaint)
{
this.m_CurveEditor.rect = position;
}
foreach (CurveWrapper wrapper in this.m_CurveEditor.animationCurves)
{
if ((wrapper.getAxisUiScalarsCallback != null) && (wrapper.setAxisUiScalarsCallback != null))
{
Vector2 newAxisScalars = wrapper.getAxisUiScalarsCallback();
if (newAxisScalars.y > 1000000f)
{
newAxisScalars.y = 1000000f;
wrapper.setAxisUiScalarsCallback(newAxisScalars);
}
}
}
this.m_CurveEditor.OnGUI();
this.DoLabelForTopMostCurve(new Rect(rect.x + 4f, rect.y, rect.width, 20f));
this.DoRemoveSelectedButton(new Rect(position.x, position.y, position.width, 24f));
this.DoOptimizeCurveButton(rect3);
rect3.x += 30f;
rect3.width -= 60f;
this.PresetCurveButtons(rect3, rect);
this.SaveChangedCurves();
}
private void PresetCurveButtons(Rect position, Rect curveEditorRect)
{
if (this.m_CurveEditor.animationCurves.Length != 0)
{
this.InitDoubleCurvePresets();
if (this.m_DoubleCurvePresets != null)
{
DoubleCurvePresetLibrary currentLib = this.m_DoubleCurvePresets.GetPresetLibraryEditor().GetCurrentLib();
int a = (currentLib == null) ? 0 : currentLib.Count();
int num2 = Mathf.Min(a, 9);
float width = 30f;
float height = 15f;
float num5 = 10f;
float num6 = (num2 * width) + ((num2 - 1) * num5);
float num7 = (position.width - num6) * 0.5f;
float y = (position.height - height) * 0.5f;
float x = 3f;
if (num7 > 0f)
{
x = num7;
}
this.PresetDropDown(new Rect((x - 20f) + position.x, y + position.y, 16f, 16f));
GUI.BeginGroup(position);
Color.white.a *= 0.6f;
for (int i = 0; i < num2; i++)
{
if (i > 0)
{
x += num5;
}
Rect rect = new Rect(x, y, width, height);
s_Styles.presetTooltip.tooltip = currentLib.GetName(i);
if (GUI.Button(rect, s_Styles.presetTooltip, GUIStyle.none))
{
DoubleCurve preset = currentLib.GetPreset(i) as DoubleCurve;
if (preset != null)
{
this.SetTopMostCurve(preset);
this.m_CurveEditor.ClearSelection();
}
}
if (Event.current.type == EventType.Repaint)
{
currentLib.Draw(rect, i);
}
x += width;
}
GUI.EndGroup();
}
}
}
private void PresetDropDown(Rect rect)
{
if (EditorGUI.ButtonMouseDown(rect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.inspectorTitlebarText) && (this.CreateDoubleCurveFromTopMostCurve() != null))
{
this.InitDoubleCurvePresets();
if (this.m_DoubleCurvePresets != null)
{
this.m_DoubleCurvePresets.doubleCurveToSave = this.CreateDoubleCurveFromTopMostCurve();
PopupWindow.Show(rect, this.m_DoubleCurvePresets);
}
}
}
public void Refresh()
{
this.ContentChanged();
AnimationCurvePreviewCache.ClearCache();
}
private bool Remove(int index)
{
if ((index >= 0) && (index < this.m_AddedCurves.Count))
{
Color item = this.m_AddedCurves[index].m_Color;
this.m_AvailableColors.Add(item);
SessionState.EraseVector3(this.m_AddedCurves[index].m_UniqueName);
this.m_AddedCurves.RemoveAt(index);
if (this.m_AddedCurves.Count == 0)
{
this.m_AvailableColors = new List<Color>(this.m_Colors);
}
return true;
}
Debug.Log("Invalid index in ParticleSystemCurveEditor::Remove");
return false;
}
private void RemoveAll()
{
bool flag = false;
while (this.m_AddedCurves.Count > 0)
{
flag |= this.Remove(0);
}
if (flag)
{
this.ContentChanged();
this.UpdateRangeBasedOnShownCurves();
}
}
public void RemoveCurve(SerializedProperty max)
{
this.RemoveCurve(null, max);
}
public void RemoveCurve(SerializedProperty min, SerializedProperty max)
{
if (this.Remove(this.FindIndex(min, max)))
{
this.ContentChanged();
this.UpdateRangeBasedOnShownCurves();
}
}
private void RemoveSelected()
{
bool flag = false;
List<CurveSelection> selectedCurves = this.m_CurveEditor.selectedCurves;
for (int i = 0; i < selectedCurves.Count; i++)
{
int curveID = selectedCurves[i].curveID;
for (int j = 0; j < this.m_AddedCurves.Count; j++)
{
CurveData data = this.m_AddedCurves[j];
if ((data.m_MaxId == curveID) || (data.m_MinId == curveID))
{
flag |= this.Remove(j);
break;
}
}
}
if (flag)
{
this.ContentChanged();
this.UpdateRangeBasedOnShownCurves();
}
this.m_CurveEditor.SelectNone();
}
private void RemoveTopMost()
{
int num;
if (this.m_CurveEditor.GetTopMostCurveID(out num))
{
for (int i = 0; i < this.m_AddedCurves.Count; i++)
{
CurveData data = this.m_AddedCurves[i];
if ((data.m_MaxId == num) || (data.m_MinId == num))
{
this.Remove(i);
this.ContentChanged();
this.UpdateRangeBasedOnShownCurves();
break;
}
}
}
}
private static bool SameColor(Color c1, Color c2) =>
(((Mathf.Abs((float) (c1.r - c2.r)) < 0.01f) && (Mathf.Abs((float) (c1.g - c2.g)) < 0.01f)) && (Mathf.Abs((float) (c1.b - c2.b)) < 0.01f));
private void SaveChangedCurves()
{
CurveWrapper[] animationCurves = this.m_CurveEditor.animationCurves;
bool flag = false;
for (int i = 0; i < animationCurves.Length; i++)
{
CurveWrapper cw = animationCurves[i];
if (cw.changed)
{
for (int j = 0; j < this.m_AddedCurves.Count; j++)
{
if (this.m_AddedCurves[j].m_MaxId == cw.id)
{
this.SaveCurve(this.m_AddedCurves[j].m_Max, cw);
break;
}
if (this.m_AddedCurves[j].IsRegion() && (this.m_AddedCurves[j].m_MinId == cw.id))
{
this.SaveCurve(this.m_AddedCurves[j].m_Min, cw);
break;
}
}
flag = true;
}
}
if (flag)
{
AnimationCurvePreviewCache.ClearCache();
HandleUtility.Repaint();
}
}
private void SaveCurve(SerializedProperty prop, CurveWrapper cw)
{
if (cw.curve.keys.Length == 1)
{
cw.renderer.SetCustomRange(0f, 1f);
cw.wrapColorMultiplier = Color.clear;
}
else
{
cw.renderer.SetCustomRange(0f, 0f);
cw.wrapColorMultiplier = cw.color;
}
prop.animationCurveValue = cw.curve;
cw.changed = false;
}
private void SetConstantCurve(CurveWrapper cw, float constantValue)
{
Keyframe[] keyframeArray = new Keyframe[1];
keyframeArray[0].time = 0f;
keyframeArray[0].value = constantValue;
cw.curve.keys = keyframeArray;
cw.changed = true;
}
private void SetCurve(CurveWrapper cw, AnimationCurve curve)
{
Keyframe[] destinationArray = new Keyframe[curve.keys.Length];
Array.Copy(curve.keys, destinationArray, destinationArray.Length);
cw.curve.keys = destinationArray;
cw.changed = true;
}
private void SetTopMostCurve(DoubleCurve doubleCurve)
{
int num;
if (this.m_CurveEditor.GetTopMostCurveID(out num))
{
for (int i = 0; i < this.m_AddedCurves.Count; i++)
{
CurveData data = this.m_AddedCurves[i];
if ((data.m_MaxId == num) || (data.m_MinId == num))
{
if (doubleCurve.signedRange == data.m_SignedRange)
{
if (data.m_MaxId > 0)
{
this.SetCurve(this.m_CurveEditor.GetCurveFromID(data.m_MaxId), doubleCurve.maxCurve);
}
if (data.m_MinId > 0)
{
this.SetCurve(this.m_CurveEditor.GetCurveFromID(data.m_MinId), doubleCurve.minCurve);
}
}
else
{
Debug.LogWarning("Cannot assign a curves with different signed range");
}
}
}
}
}
public void SetVisible(SerializedProperty curveProp, bool visible)
{
int num = this.FindIndex(curveProp);
if (num >= 0)
{
this.m_AddedCurves[num].m_Visible = visible;
}
}
private void UndoRedoPerformed()
{
this.ContentChanged();
}
private void UpdateRangeBasedOnShownCurves()
{
bool flag = false;
for (int i = 0; i < this.m_AddedCurves.Count; i++)
{
flag |= this.m_AddedCurves[i].m_SignedRange;
}
float num2 = !flag ? 0f : -1f;
if (num2 != m_CurveEditorSettings.vRangeMin)
{
m_CurveEditorSettings.vRangeMin = num2;
this.m_CurveEditor.settings = m_CurveEditorSettings;
this.m_CurveEditor.SetShownVRangeInsideMargins(m_CurveEditorSettings.vRangeMin, m_CurveEditorSettings.hRangeMax);
}
}
public class CurveData
{
public Color m_Color;
public GUIContent m_DisplayName;
public CurveWrapper.GetAxisScalarsCallback m_GetAxisScalarsCallback;
public SerializedProperty m_Max;
public int m_MaxId;
public SerializedProperty m_Min;
public int m_MinId;
public CurveWrapper.SetAxisScalarsCallback m_SetAxisScalarsCallback;
public bool m_SignedRange;
public string m_UniqueName;
public bool m_Visible;
private static int s_IdCounter;
public CurveData(string name, GUIContent displayName, SerializedProperty min, SerializedProperty max, Color color, bool signedRange, CurveWrapper.GetAxisScalarsCallback getAxisScalars, CurveWrapper.SetAxisScalarsCallback setAxisScalars, bool visible)
{
this.m_UniqueName = name;
this.m_DisplayName = displayName;
this.m_SignedRange = signedRange;
this.m_Min = min;
this.m_Max = max;
if (this.m_Min != null)
{
this.m_MinId = ++s_IdCounter;
}
if (this.m_Max != null)
{
this.m_MaxId = ++s_IdCounter;
}
this.m_Color = color;
this.m_GetAxisScalarsCallback = getAxisScalars;
this.m_SetAxisScalarsCallback = setAxisScalars;
this.m_Visible = visible;
if ((this.m_Max == null) || (this.m_MaxId == 0))
{
Debug.LogError("Max curve should always be valid! (Min curve can be null)");
}
}
public bool IsRegion() =>
(this.m_Min != null);
}
internal class Styles
{
public GUIStyle curveEditorBackground = "CurveEditorBackground";
public GUIContent curveLibraryPopup = new GUIContent("", "Open curve library");
public GUIStyle curveSwatch = "PopupCurveEditorSwatch";
public GUIStyle curveSwatchArea = "PopupCurveSwatchBackground";
public GUIStyle minus = "OL Minus";
public GUIContent optimizeCurveText = new GUIContent("", "Click to optimize curve. Optimized curves are defined by having at most 3 keys, with a key at both ends, and do not support loop or ping pong wrapping.");
public GUIStyle plus = "OL Plus";
public GUIContent presetTooltip = new GUIContent();
public GUIContent removeCurveText = new GUIContent("", "Remove selected curve(s)");
public GUIStyle yAxisHeader = new GUIStyle(ParticleSystemStyles.Get().label);
}
}