com.wallstop-studios.unity-helpers 2.0.0-rc73.19 → 2.0.0-rc73.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/Editor/{Sprites/AnimationCopier.cs → AnimationCopier.cs} +209 -84
  2. package/Editor/{Sprites/AnimationCreator.cs → AnimationCreator.cs} +100 -29
  3. package/Editor/AnimationEventEditor.cs +23 -10
  4. package/Editor/CustomEditors/MatchColliderToSpriteEditor.cs +1 -1
  5. package/Editor/FitTextureSizeWindow.cs +53 -14
  6. package/Editor/PrefabChecker.cs +18 -11
  7. package/Editor/SpriteAtlasGenerator.cs +914 -0
  8. package/Editor/SpriteAtlasGenerator.cs.meta +3 -0
  9. package/Editor/{Sprites/SpriteCropper.cs → SpriteCropper.cs} +143 -172
  10. package/Editor/{Sprites/SpriteSettingsApplier.cs → SpriteSettingsApplier.cs} +77 -12
  11. package/Editor/{Sprites/TextureResizerWizard.cs → TextureResizerWizard.cs} +1 -1
  12. package/Editor/{Sprites/TextureSettingsApplier.cs → TextureSettingsApplier.cs} +1 -1
  13. package/Editor/Utils/DxReadOnlyPropertyDrawer.cs +1 -1
  14. package/Editor/Utils/GUIHorizontalScope.cs +20 -0
  15. package/Editor/Utils/GUIHorizontalScope.cs.meta +3 -0
  16. package/Runtime/Core/DataStructure/Circle.cs +1 -1
  17. package/Runtime/Core/DataStructure/QuadTree.cs +4 -4
  18. package/Runtime/Core/Extension/ColorExtensions.cs +5 -5
  19. package/Runtime/Core/Extension/IEnumerableExtensions.cs +1 -1
  20. package/Runtime/Core/Extension/UnityExtensions.cs +14 -14
  21. package/Runtime/Core/Helper/DirectoryHelper.cs +0 -64
  22. package/Runtime/Core/Helper/Helpers.cs +9 -9
  23. package/Runtime/Core/Helper/Logging/UnityLogTagFormatter.cs +8 -31
  24. package/Runtime/Core/Helper/Partials/ObjectHelpers.cs +4 -5
  25. package/Runtime/Core/Helper/PathHelper.cs +1 -2
  26. package/Runtime/Core/Random/DotNetRandom.cs +1 -1
  27. package/Runtime/Core/Random/SplitMix64.cs +1 -1
  28. package/Runtime/Core/Random/SquirrelRandom.cs +7 -7
  29. package/Runtime/Core/Random/ThreadLocalRandom.cs +1 -1
  30. package/Runtime/Core/Random/WyRandom.cs +1 -1
  31. package/Runtime/Tags/AttributeEffect.cs +0 -1
  32. package/Runtime/Tags/EffectHandler.cs +1 -1
  33. package/Runtime/UI/LayeredImage.cs +161 -309
  34. package/Runtime/Utils/AnimatorEnumStateMachine.cs +1 -1
  35. package/Runtime/Utils/SetTextureImportData.cs +1 -1
  36. package/Runtime/Utils/TextureScale.cs +4 -4
  37. package/Styles/Elements/{Progress/CircularProgressBar.cs → CircularProgressBar.cs} +55 -56
  38. package/Styles/Elements/{Progress/RegularProgressBar.cs → RegularProgressBar.cs} +13 -24
  39. package/Styles/UXML/CircularProgressBar.uxml +11 -0
  40. package/Styles/UXML/CircularProgressBar.uxml.meta +10 -0
  41. package/Styles/UXML/RegularProgressBar.uxml +22 -0
  42. package/Styles/UXML/RegularProgressBar.uxml.meta +10 -0
  43. package/Styles/UXML.meta +3 -0
  44. package/package.json +1 -18
  45. package/Editor/CustomEditors/PersistentDirectoryGUI.cs +0 -796
  46. package/Editor/CustomEditors/PersistentDirectoryGUI.cs.meta +0 -3
  47. package/Editor/CustomEditors/SourceFolderEntryDrawer.cs +0 -275
  48. package/Editor/CustomEditors/SourceFolderEntryDrawer.cs.meta +0 -3
  49. package/Editor/PersistentDirectorySettings.cs +0 -248
  50. package/Editor/PersistentDirectorySettings.cs.meta +0 -3
  51. package/Editor/Sprites/ScriptableSpriteAtlas.cs +0 -95
  52. package/Editor/Sprites/ScriptableSpriteAtlas.cs.meta +0 -3
  53. package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs +0 -930
  54. package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs.meta +0 -3
  55. package/Editor/Sprites.meta +0 -3
  56. package/Styles/Elements/Progress/ArcedProgressBar.cs +0 -345
  57. package/Styles/Elements/Progress/ArcedProgressBar.cs.meta +0 -3
  58. package/Styles/Elements/Progress/GlitchProgressBar.cs +0 -416
  59. package/Styles/Elements/Progress/GlitchProgressBar.cs.meta +0 -3
  60. package/Styles/Elements/Progress/LiquidProgressBar.cs +0 -632
  61. package/Styles/Elements/Progress/LiquidProgressBar.cs.meta +0 -3
  62. package/Styles/Elements/Progress/MarchingAntsProgressBar.cs +0 -722
  63. package/Styles/Elements/Progress/MarchingAntsProgressBar.cs.meta +0 -3
  64. package/Styles/Elements/Progress/WigglyProgressBar.cs +0 -837
  65. package/Styles/Elements/Progress/WigglyProgressBar.cs.meta +0 -3
  66. package/Styles/Elements/Progress.meta +0 -3
  67. package/Styles/USS/ArcedProgressBar.uss +0 -19
  68. package/Styles/USS/ArcedProgressBar.uss.meta +0 -3
  69. package/Styles/USS/WigglyProgressBar.uss +0 -17
  70. package/Styles/USS/WigglyProgressBar.uss.meta +0 -3
  71. /package/Editor/{Sprites/AnimationCopier.cs.meta → AnimationCopier.cs.meta} +0 -0
  72. /package/Editor/{Sprites/AnimationCreator.cs.meta → AnimationCreator.cs.meta} +0 -0
  73. /package/Editor/{Sprites/SpriteCropper.cs.meta → SpriteCropper.cs.meta} +0 -0
  74. /package/Editor/{Sprites/SpriteSettingsApplier.cs.meta → SpriteSettingsApplier.cs.meta} +0 -0
  75. /package/Editor/{Sprites/TextureResizerWizard.cs.meta → TextureResizerWizard.cs.meta} +0 -0
  76. /package/Editor/{Sprites/TextureSettingsApplier.cs.meta → TextureSettingsApplier.cs.meta} +0 -0
  77. /package/Styles/Elements/{Progress/CircularProgressBar.cs.meta → CircularProgressBar.cs.meta} +0 -0
  78. /package/Styles/Elements/{Progress/RegularProgressBar.cs.meta → RegularProgressBar.cs.meta} +0 -0
@@ -1,837 +0,0 @@
1
- namespace WallstopStudios.UnityHelpers.Styles.Elements.Progress
2
- {
3
- using System.ComponentModel;
4
- using UnityEngine;
5
- using UnityEngine.UIElements;
6
-
7
- public sealed class WigglyProgressBar : VisualElement
8
- {
9
- public const string USSClassName = "wiggly-progress-bar";
10
- public const string USSTrackColorVarName = "--wiggly-track-color";
11
- public const string USSProgressColorVarName = "--wiggly-progress-color";
12
- public const string USSThicknessVarName = "--wiggly-thickness";
13
-
14
- public enum FillDirection
15
- {
16
- Forward = 0,
17
- Backward = 1,
18
- }
19
-
20
- public enum OrientationType
21
- {
22
- Horizontal = 0,
23
- Vertical = 1,
24
- }
25
-
26
- private float _progress = 0.5f;
27
-
28
- public float Progress
29
- {
30
- get => _progress;
31
- set
32
- {
33
- if (float.IsNaN(value) || float.IsInfinity(value))
34
- {
35
- return;
36
- }
37
- float newProgress = Mathf.Clamp01(value);
38
- if (!Mathf.Approximately(_progress, newProgress))
39
- {
40
- _progress = newProgress;
41
- MarkDirtyRepaint();
42
- }
43
- }
44
- }
45
-
46
- private float _amplitude = 10f;
47
-
48
- public float Amplitude
49
- {
50
- get => _amplitude;
51
- set
52
- {
53
- if (float.IsNaN(value) || float.IsInfinity(value))
54
- {
55
- return;
56
- }
57
- _amplitude = Mathf.Max(0f, value);
58
- UpdateSize();
59
- MarkDirtyRepaint();
60
- }
61
- }
62
-
63
- private float _wavelength = 50f;
64
-
65
- public float Wavelength
66
- {
67
- get => _wavelength;
68
- set
69
- {
70
- if (float.IsNaN(value) || float.IsInfinity(value))
71
- {
72
- return;
73
- }
74
- _wavelength = Mathf.Max(1f, value);
75
- MarkDirtyRepaint();
76
- }
77
- }
78
-
79
- private float _thickness = 5f;
80
-
81
- public float Thickness
82
- {
83
- get => _thickness;
84
- set
85
- {
86
- if (float.IsNaN(value) || float.IsInfinity(value))
87
- {
88
- return;
89
- }
90
- _thickness = Mathf.Max(1f, value);
91
- UpdateSize();
92
- MarkDirtyRepaint();
93
- }
94
- }
95
-
96
- private bool _roundedCaps = true;
97
-
98
- public bool RoundedCaps
99
- {
100
- get => _roundedCaps;
101
- set
102
- {
103
- _roundedCaps = value;
104
- MarkDirtyRepaint();
105
- }
106
- }
107
-
108
- private FillDirection _fillDirection = FillDirection.Forward;
109
-
110
- public FillDirection Direction
111
- {
112
- get => _fillDirection;
113
- set
114
- {
115
- _fillDirection = value;
116
- MarkDirtyRepaint();
117
- }
118
- }
119
-
120
- private Color _trackColor = Color.gray;
121
-
122
- public Color TrackColor
123
- {
124
- get => _trackColor;
125
- set
126
- {
127
- _trackColor = value;
128
- MarkDirtyRepaint();
129
- }
130
- }
131
-
132
- private Color _progressColor = new(0.2f, 0.6f, 1f);
133
-
134
- public Color ProgressColor
135
- {
136
- get => _progressColor;
137
- set
138
- {
139
- _progressColor = value;
140
- MarkDirtyRepaint();
141
- }
142
- }
143
-
144
- private int _segmentsPerWavelength = 20;
145
-
146
- public int SegmentsPerWavelength
147
- {
148
- get => _segmentsPerWavelength;
149
- set
150
- {
151
- _segmentsPerWavelength = Mathf.Max(4, value);
152
- MarkDirtyRepaint();
153
- }
154
- }
155
-
156
- private bool _animatePhase;
157
-
158
- public bool AnimatePhase
159
- {
160
- get => _animatePhase;
161
- set
162
- {
163
- if (_animatePhase == value)
164
- {
165
- return;
166
- }
167
-
168
- _animatePhase = value;
169
- if (_animatePhase && panel != null)
170
- {
171
- StartAnimationUpdate();
172
- }
173
- else
174
- {
175
- StopAnimationUpdate();
176
- }
177
-
178
- MarkDirtyRepaint();
179
- }
180
- }
181
-
182
- private float _phaseSpeed = Mathf.PI;
183
-
184
- public float PhaseSpeed
185
- {
186
- get => _phaseSpeed;
187
- set
188
- {
189
- if (float.IsNaN(value) || float.IsInfinity(value))
190
- {
191
- return;
192
- }
193
- _phaseSpeed = value;
194
- }
195
- }
196
-
197
- private bool _animateWithProgress;
198
-
199
- public bool AnimateWithProgress
200
- {
201
- get => _animateWithProgress;
202
- set
203
- {
204
- if (_animateWithProgress == value)
205
- {
206
- return;
207
- }
208
-
209
- _animateWithProgress = value;
210
- MarkDirtyRepaint();
211
- }
212
- }
213
-
214
- private float _progressPhaseFactor = 1.0f;
215
-
216
- public float ProgressPhaseFactor
217
- {
218
- get => _progressPhaseFactor;
219
- set
220
- {
221
- if (float.IsNaN(value) || float.IsInfinity(value))
222
- {
223
- return;
224
- }
225
- _progressPhaseFactor = value;
226
- MarkDirtyRepaint();
227
- }
228
- }
229
-
230
- private OrientationType _orientation = OrientationType.Horizontal;
231
-
232
- public OrientationType Orientation
233
- {
234
- get => _orientation;
235
- set
236
- {
237
- if (_orientation == value)
238
- {
239
- return;
240
- }
241
-
242
- _orientation = value;
243
- UpdateSizeAndOrientation();
244
- MarkDirtyRepaint();
245
- }
246
- }
247
-
248
- private float _arcRadius;
249
-
250
- public float ArcRadius
251
- {
252
- get => _arcRadius;
253
- set
254
- {
255
- if (float.IsNaN(value) || float.IsInfinity(value))
256
- {
257
- return;
258
- }
259
- _arcRadius = Mathf.Max(0, value);
260
- UpdateSizeAndOrientation();
261
- MarkDirtyRepaint();
262
- }
263
- }
264
-
265
- private bool _arcBottom = true;
266
-
267
- public bool ArcBottom
268
- {
269
- get => _arcBottom;
270
- set
271
- {
272
- if (_arcBottom == value)
273
- {
274
- return;
275
- }
276
-
277
- _arcBottom = value;
278
- MarkDirtyRepaint();
279
- }
280
- }
281
-
282
- private float _length = 200f;
283
-
284
- public float Length
285
- {
286
- get => _length;
287
- set
288
- {
289
- if (float.IsNaN(value) || float.IsInfinity(value))
290
- {
291
- return;
292
- }
293
- _length = Mathf.Max(0, value);
294
- UpdateSizeAndOrientation();
295
- MarkDirtyRepaint();
296
- }
297
- }
298
- private float _timeBasedPhaseOffset;
299
- private IVisualElementScheduledItem _animationUpdateItem;
300
-
301
- public new class UxmlFactory : UxmlFactory<WigglyProgressBar, UxmlTraits> { }
302
-
303
- public new class UxmlTraits : VisualElement.UxmlTraits
304
- {
305
- private readonly UxmlFloatAttributeDescription _progressAttribute = new()
306
- {
307
- name = "progress",
308
- defaultValue = 0.5f,
309
- };
310
-
311
- private readonly UxmlFloatAttributeDescription _amplitudeAttribute = new()
312
- {
313
- name = "amplitude",
314
- defaultValue = 10f,
315
- };
316
-
317
- private readonly UxmlFloatAttributeDescription _wavelengthAttribute = new()
318
- {
319
- name = "wavelength",
320
- defaultValue = 50f,
321
- };
322
-
323
- private readonly UxmlFloatAttributeDescription _thicknessAttribute = new()
324
- {
325
- name = "thickness",
326
- defaultValue = 5f,
327
- };
328
-
329
- private readonly UxmlBoolAttributeDescription _roundedCapsAttribute = new()
330
- {
331
- name = "rounded-caps",
332
- defaultValue = true,
333
- };
334
-
335
- private readonly UxmlEnumAttributeDescription<FillDirection> _fillDirectionAttribute =
336
- new() { name = "fill-direction", defaultValue = FillDirection.Forward };
337
-
338
- private readonly UxmlColorAttributeDescription _trackColorAttribute = new()
339
- {
340
- name = "track-color-attr",
341
- defaultValue = Color.gray,
342
- };
343
-
344
- private readonly UxmlColorAttributeDescription _progressColorAttribute = new()
345
- {
346
- name = "progress-color-attr",
347
- defaultValue = new Color(0.2f, 0.6f, 1.0f, 1.0f),
348
- };
349
-
350
- private readonly UxmlIntAttributeDescription _segmentsPerWavelengthAttribute = new()
351
- {
352
- name = "segments-per-wavelength",
353
- defaultValue = 20,
354
- };
355
-
356
- private readonly UxmlBoolAttributeDescription _animatePhaseAttribute = new()
357
- {
358
- name = "animate-phase",
359
- defaultValue = false,
360
- };
361
-
362
- private readonly UxmlFloatAttributeDescription _phaseSpeedAttribute = new()
363
- {
364
- name = "phase-speed",
365
- defaultValue = Mathf.PI,
366
- };
367
-
368
- private readonly UxmlBoolAttributeDescription _animateWithProgressAttribute = new()
369
- {
370
- name = "animate-with-progress",
371
- defaultValue = false,
372
- };
373
-
374
- private readonly UxmlFloatAttributeDescription _progressPhaseFactorAttribute = new()
375
- {
376
- name = "progress-phase-factor",
377
- defaultValue = 1.0f,
378
- };
379
-
380
- private readonly UxmlEnumAttributeDescription<OrientationType> _orientationAttribute =
381
- new() { name = "orientation", defaultValue = OrientationType.Horizontal };
382
-
383
- private readonly UxmlFloatAttributeDescription _arcRadiusAttribute = new()
384
- {
385
- name = "arc-radius",
386
- defaultValue = 0f,
387
- };
388
-
389
- private readonly UxmlBoolAttributeDescription _arcBottomAttribute = new()
390
- {
391
- name = "arc-bottom",
392
- defaultValue = true,
393
- };
394
-
395
- private readonly UxmlFloatAttributeDescription _lengthAttribute = new()
396
- {
397
- name = "length",
398
- defaultValue = 200f,
399
- };
400
-
401
- public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
402
- {
403
- base.Init(ve, bag, cc);
404
- if (ve is not WigglyProgressBar bar)
405
- {
406
- Debug.LogError(
407
- $"Initialization failed, expected {nameof(WigglyProgressBar)}, found {ve?.GetType()}.)"
408
- );
409
- return;
410
- }
411
-
412
- bar.Amplitude = _amplitudeAttribute.GetValueFromBag(bag, cc);
413
- bar.Thickness = _thicknessAttribute.GetValueFromBag(bag, cc);
414
- bar.Progress = _progressAttribute.GetValueFromBag(bag, cc);
415
- bar.Wavelength = _wavelengthAttribute.GetValueFromBag(bag, cc);
416
- bar.RoundedCaps = _roundedCapsAttribute.GetValueFromBag(bag, cc);
417
- bar.Direction = _fillDirectionAttribute.GetValueFromBag(bag, cc);
418
- bar.TrackColor = _trackColorAttribute.GetValueFromBag(bag, cc);
419
- bar.ProgressColor = _progressColorAttribute.GetValueFromBag(bag, cc);
420
- bar.SegmentsPerWavelength = _segmentsPerWavelengthAttribute.GetValueFromBag(
421
- bag,
422
- cc
423
- );
424
- bar.PhaseSpeed = _phaseSpeedAttribute.GetValueFromBag(bag, cc);
425
- bar.ProgressPhaseFactor = _progressPhaseFactorAttribute.GetValueFromBag(bag, cc);
426
- bar.AnimateWithProgress = _animateWithProgressAttribute.GetValueFromBag(bag, cc);
427
- bar.AnimatePhase = _animatePhaseAttribute.GetValueFromBag(bag, cc);
428
- bar.ArcBottom = _arcBottomAttribute.GetValueFromBag(bag, cc);
429
- bar.Orientation = _orientationAttribute.GetValueFromBag(bag, cc);
430
- bar.ArcRadius = _arcRadiusAttribute.GetValueFromBag(bag, cc);
431
- bar.ArcBottom = _arcBottomAttribute.GetValueFromBag(bag, cc);
432
- bar.Length = _lengthAttribute.GetValueFromBag(bag, cc);
433
-
434
- bar.UpdateSizeAndOrientation();
435
- }
436
- }
437
-
438
- public WigglyProgressBar()
439
- {
440
- AddToClassList(USSClassName);
441
- generateVisualContent += OnGenerateVisualContent;
442
- RegisterCallback<CustomStyleResolvedEvent>(OnCustomStyleResolved);
443
- RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
444
- RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
445
- UpdateSizeAndOrientation();
446
- }
447
-
448
- private void OnAttachToPanel(AttachToPanelEvent evt)
449
- {
450
- if (_animatePhase)
451
- {
452
- StartAnimationUpdate();
453
- }
454
- }
455
-
456
- private void OnDetachFromPanel(DetachFromPanelEvent evt)
457
- {
458
- StopAnimationUpdate();
459
- }
460
-
461
- private void StartAnimationUpdate()
462
- {
463
- if (panel == null || _animationUpdateItem != null)
464
- {
465
- return;
466
- }
467
-
468
- _animationUpdateItem = schedule.Execute(UpdateAnimationState).Every(16);
469
- }
470
-
471
- private void StopAnimationUpdate()
472
- {
473
- _animationUpdateItem?.Pause();
474
- _animationUpdateItem = null;
475
- }
476
-
477
- private void UpdateAnimationState(TimerState ts)
478
- {
479
- if (!_animatePhase || _phaseSpeed == 0f)
480
- {
481
- return;
482
- }
483
-
484
- _timeBasedPhaseOffset += _phaseSpeed * (ts.deltaTime / 1000f);
485
- _timeBasedPhaseOffset %= 2f * Mathf.PI;
486
- MarkDirtyRepaint();
487
- }
488
-
489
- private void UpdateSize()
490
- {
491
- float requiredHeight = _amplitude * 2f + _thickness;
492
- style.height = requiredHeight;
493
- style.minHeight = requiredHeight;
494
- }
495
-
496
- private void UpdateSizeAndOrientation()
497
- {
498
- float perpendicularWaveHeight = _amplitude * 2f + _thickness;
499
-
500
- float finalPrimaryDimension = _length;
501
- float finalPerpendicularDimension = perpendicularWaveHeight;
502
-
503
- if (
504
- !Mathf.Approximately(_arcRadius, 0)
505
- && !float.IsInfinity(_arcRadius)
506
- && !float.IsNaN(_arcRadius)
507
- && _length > 0
508
- )
509
- {
510
- float radius = Mathf.Max(_arcRadius, 0.01f);
511
- float totalAngleRadians = _length / radius;
512
- if (totalAngleRadians > 0)
513
- {
514
- float chordLength = 2 * radius * Mathf.Sin(totalAngleRadians / 2f);
515
- float sagitta = radius * (1 - Mathf.Cos(totalAngleRadians / 2f));
516
- if (!float.IsNaN(chordLength) && !float.IsNaN(sagitta))
517
- {
518
- finalPrimaryDimension = chordLength;
519
- finalPerpendicularDimension = perpendicularWaveHeight + sagitta;
520
- }
521
- }
522
- }
523
-
524
- switch (_orientation)
525
- {
526
- case OrientationType.Horizontal:
527
- {
528
- style.width = finalPrimaryDimension;
529
- style.minWidth = finalPrimaryDimension;
530
- style.height = finalPerpendicularDimension;
531
- style.minHeight = finalPerpendicularDimension;
532
- break;
533
- }
534
- case OrientationType.Vertical:
535
- {
536
- style.height = finalPrimaryDimension;
537
- style.minHeight = finalPrimaryDimension;
538
- style.width = finalPerpendicularDimension;
539
- style.minWidth = finalPerpendicularDimension;
540
- break;
541
- }
542
- default:
543
- {
544
- throw new InvalidEnumArgumentException(
545
- nameof(_orientation),
546
- (int)_orientation,
547
- typeof(OrientationType)
548
- );
549
- }
550
- }
551
- }
552
-
553
- private void OnCustomStyleResolved(CustomStyleResolvedEvent evt)
554
- {
555
- if (
556
- customStyle.TryGetValue(
557
- new CustomStyleProperty<Color>(USSTrackColorVarName),
558
- out Color trackCol
559
- )
560
- )
561
- {
562
- _trackColor = trackCol;
563
- }
564
-
565
- if (
566
- customStyle.TryGetValue(
567
- new CustomStyleProperty<Color>(USSProgressColorVarName),
568
- out Color progressCol
569
- )
570
- )
571
- {
572
- _progressColor = progressCol;
573
- }
574
-
575
- if (
576
- customStyle.TryGetValue(
577
- new CustomStyleProperty<float>(USSThicknessVarName),
578
- out float thickVal
579
- )
580
- )
581
- {
582
- Thickness = thickVal;
583
- }
584
-
585
- MarkDirtyRepaint();
586
- }
587
-
588
- private void OnGenerateVisualContent(MeshGenerationContext mgc)
589
- {
590
- Painter2D painter = mgc.painter2D;
591
- Rect rect = contentRect;
592
-
593
- if (rect.width <= 0 || rect.height <= 0 || _thickness <= 0 || _wavelength <= 0)
594
- {
595
- return;
596
- }
597
-
598
- painter.lineWidth = _thickness;
599
- painter.lineCap = _roundedCaps ? LineCap.Round : LineCap.Butt;
600
-
601
- float totalPhaseOffset = 0f;
602
- if (_animatePhase)
603
- {
604
- if (_animateWithProgress)
605
- {
606
- totalPhaseOffset += _progress * _progressPhaseFactor * 2f * Mathf.PI;
607
- }
608
- else
609
- {
610
- totalPhaseOffset += _timeBasedPhaseOffset;
611
- }
612
- }
613
-
614
- float trackLength = _length;
615
- painter.strokeColor = _trackColor;
616
- DrawWavePath(painter, rect, 0f, trackLength, totalPhaseOffset, trackLength);
617
-
618
- if (!Mathf.Approximately(_progress, 0f))
619
- {
620
- painter.strokeColor = _progressColor;
621
- float fillLength = trackLength * _progress;
622
-
623
- switch (_fillDirection)
624
- {
625
- case FillDirection.Forward:
626
- {
627
- DrawWavePath(painter, rect, 0f, fillLength, totalPhaseOffset, trackLength);
628
- break;
629
- }
630
- case FillDirection.Backward:
631
- {
632
- float startDist = trackLength - fillLength;
633
- DrawWavePath(
634
- painter,
635
- rect,
636
- startDist,
637
- trackLength,
638
- totalPhaseOffset,
639
- trackLength
640
- );
641
- break;
642
- }
643
- default:
644
- {
645
- throw new InvalidEnumArgumentException(
646
- nameof(_fillDirection),
647
- (int)_fillDirection,
648
- typeof(FillDirection)
649
- );
650
- }
651
- }
652
- }
653
- }
654
-
655
- private void DrawWavePath(
656
- Painter2D painter,
657
- Rect elementRect,
658
- float startArcDistance,
659
- float endArcDistance,
660
- float phaseOffset,
661
- float totalTrackArcLength
662
- )
663
- {
664
- if (
665
- Mathf.Approximately(startArcDistance, endArcDistance)
666
- || endArcDistance < startArcDistance
667
- || totalTrackArcLength <= 0
668
- )
669
- {
670
- return;
671
- }
672
-
673
- painter.BeginPath();
674
- bool firstPoint = true;
675
-
676
- float pathSegmentArcLength = endArcDistance - startArcDistance;
677
- int totalSegments = Mathf.Max(
678
- 2,
679
- Mathf.CeilToInt(pathSegmentArcLength / _wavelength * _segmentsPerWavelength)
680
- );
681
- float dArcDistance = pathSegmentArcLength / totalSegments;
682
-
683
- Vector2 arcCenter = Vector2.zero;
684
- float radius = Mathf.Max(_arcRadius, 0.01f);
685
- bool isStraight =
686
- Mathf.Approximately(_arcRadius, 0)
687
- || float.IsInfinity(radius)
688
- || float.IsNaN(radius);
689
-
690
- if (!isStraight)
691
- {
692
- switch (_orientation)
693
- {
694
- case OrientationType.Horizontal:
695
- {
696
- float waveBaselineY;
697
- if (!_arcBottom)
698
- {
699
- waveBaselineY = elementRect.yMin + _amplitude + _thickness / 2f;
700
- arcCenter = new Vector2(elementRect.center.x, waveBaselineY + radius);
701
- }
702
- else
703
- {
704
- waveBaselineY = elementRect.yMax - (_amplitude + _thickness / 2f);
705
- arcCenter = new Vector2(elementRect.center.x, waveBaselineY - radius);
706
- }
707
-
708
- break;
709
- }
710
- case OrientationType.Vertical:
711
- {
712
- float waveBaselineX;
713
- if (!_arcBottom)
714
- {
715
- waveBaselineX = elementRect.xMin + _amplitude + _thickness / 2f;
716
- arcCenter = new Vector2(waveBaselineX + radius, elementRect.center.y);
717
- }
718
- else
719
- {
720
- waveBaselineX = elementRect.xMax - (_amplitude + _thickness / 2f);
721
- arcCenter = new Vector2(waveBaselineX - radius, elementRect.center.y);
722
- }
723
-
724
- break;
725
- }
726
- default:
727
- {
728
- throw new InvalidEnumArgumentException(
729
- nameof(_orientation),
730
- (int)_orientation,
731
- typeof(OrientationType)
732
- );
733
- }
734
- }
735
- }
736
-
737
- for (int i = 0; i <= totalSegments; i++)
738
- {
739
- float currentArcDist = startArcDistance + i * dArcDistance;
740
- currentArcDist = Mathf.Clamp(currentArcDist, startArcDistance, endArcDistance);
741
-
742
- Vector2 basePoint;
743
- Vector2 normalDirection;
744
-
745
- if (isStraight)
746
- {
747
- switch (_orientation)
748
- {
749
- case OrientationType.Horizontal:
750
- {
751
- float baselineY = elementRect.yMin + _amplitude + _thickness / 2f;
752
- basePoint = new Vector2(elementRect.xMin + currentArcDist, baselineY);
753
- normalDirection = Vector2.up;
754
- break;
755
- }
756
- case OrientationType.Vertical:
757
- {
758
- float baselineX = elementRect.xMin + _amplitude + _thickness / 2f;
759
- basePoint = new Vector2(baselineX, elementRect.yMin + currentArcDist);
760
- normalDirection = Vector2.left;
761
- break;
762
- }
763
- default:
764
- {
765
- throw new InvalidEnumArgumentException(
766
- nameof(_orientation),
767
- (int)_orientation,
768
- typeof(OrientationType)
769
- );
770
- }
771
- }
772
- }
773
- else
774
- {
775
- float totalAngleOfTrackRad = totalTrackArcLength / radius;
776
- float startAngleOffsetRad = -totalAngleOfTrackRad / 2f;
777
- float angleForCurrentPointRad = currentArcDist / radius;
778
- float globalAngleRad = startAngleOffsetRad + angleForCurrentPointRad;
779
-
780
- switch (_orientation)
781
- {
782
- case OrientationType.Horizontal:
783
- {
784
- basePoint.x = arcCenter.x + radius * Mathf.Sin(globalAngleRad);
785
- basePoint.y =
786
- arcCenter.y
787
- + radius * Mathf.Cos(globalAngleRad) * (_arcBottom ? 1f : -1f);
788
- break;
789
- }
790
- case OrientationType.Vertical:
791
- {
792
- basePoint.x =
793
- arcCenter.x
794
- + radius * Mathf.Cos(globalAngleRad) * (_arcBottom ? 1f : -1f);
795
- basePoint.y = arcCenter.y + radius * Mathf.Sin(globalAngleRad);
796
- break;
797
- }
798
- default:
799
- {
800
- throw new InvalidEnumArgumentException(
801
- nameof(_orientation),
802
- (int)_orientation,
803
- typeof(OrientationType)
804
- );
805
- }
806
- }
807
-
808
- normalDirection = (basePoint - arcCenter).normalized;
809
- if (_arcBottom)
810
- {
811
- normalDirection *= -1f;
812
- }
813
- }
814
-
815
- float waveAngle = currentArcDist / _wavelength * 2f * Mathf.PI + phaseOffset;
816
- float waveOffsetMagnitude = _amplitude * Mathf.Sin(waveAngle);
817
- Vector2 finalPoint = basePoint + normalDirection * waveOffsetMagnitude;
818
-
819
- if (firstPoint)
820
- {
821
- painter.MoveTo(finalPoint);
822
- firstPoint = false;
823
- }
824
- else
825
- {
826
- painter.LineTo(finalPoint);
827
- }
828
-
829
- if (currentArcDist >= endArcDistance - 0.001f && i < totalSegments)
830
- {
831
- break;
832
- }
833
- }
834
- painter.Stroke();
835
- }
836
- }
837
- }