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.
- package/Editor/{Sprites/AnimationCopier.cs → AnimationCopier.cs} +209 -84
- package/Editor/{Sprites/AnimationCreator.cs → AnimationCreator.cs} +100 -29
- package/Editor/AnimationEventEditor.cs +23 -10
- package/Editor/CustomEditors/MatchColliderToSpriteEditor.cs +1 -1
- package/Editor/FitTextureSizeWindow.cs +53 -14
- package/Editor/PrefabChecker.cs +18 -11
- package/Editor/SpriteAtlasGenerator.cs +914 -0
- package/Editor/SpriteAtlasGenerator.cs.meta +3 -0
- package/Editor/{Sprites/SpriteCropper.cs → SpriteCropper.cs} +143 -172
- package/Editor/{Sprites/SpriteSettingsApplier.cs → SpriteSettingsApplier.cs} +77 -12
- package/Editor/{Sprites/TextureResizerWizard.cs → TextureResizerWizard.cs} +1 -1
- package/Editor/{Sprites/TextureSettingsApplier.cs → TextureSettingsApplier.cs} +1 -1
- package/Editor/Utils/DxReadOnlyPropertyDrawer.cs +1 -1
- package/Editor/Utils/GUIHorizontalScope.cs +20 -0
- package/Editor/Utils/GUIHorizontalScope.cs.meta +3 -0
- package/Runtime/Core/DataStructure/Circle.cs +1 -1
- package/Runtime/Core/DataStructure/QuadTree.cs +4 -4
- package/Runtime/Core/Extension/ColorExtensions.cs +5 -5
- package/Runtime/Core/Extension/IEnumerableExtensions.cs +1 -1
- package/Runtime/Core/Extension/UnityExtensions.cs +14 -14
- package/Runtime/Core/Helper/DirectoryHelper.cs +0 -64
- package/Runtime/Core/Helper/Helpers.cs +9 -9
- package/Runtime/Core/Helper/Logging/UnityLogTagFormatter.cs +8 -31
- package/Runtime/Core/Helper/Partials/ObjectHelpers.cs +4 -5
- package/Runtime/Core/Helper/PathHelper.cs +1 -2
- package/Runtime/Core/Random/DotNetRandom.cs +1 -1
- package/Runtime/Core/Random/SplitMix64.cs +1 -1
- package/Runtime/Core/Random/SquirrelRandom.cs +7 -7
- package/Runtime/Core/Random/ThreadLocalRandom.cs +1 -1
- package/Runtime/Core/Random/WyRandom.cs +1 -1
- package/Runtime/Tags/AttributeEffect.cs +0 -1
- package/Runtime/Tags/EffectHandler.cs +1 -1
- package/Runtime/UI/LayeredImage.cs +161 -309
- package/Runtime/Utils/AnimatorEnumStateMachine.cs +1 -1
- package/Runtime/Utils/SetTextureImportData.cs +1 -1
- package/Runtime/Utils/TextureScale.cs +4 -4
- package/Styles/Elements/{Progress/CircularProgressBar.cs → CircularProgressBar.cs} +55 -56
- package/Styles/Elements/{Progress/RegularProgressBar.cs → RegularProgressBar.cs} +13 -24
- package/Styles/UXML/CircularProgressBar.uxml +11 -0
- package/Styles/UXML/CircularProgressBar.uxml.meta +10 -0
- package/Styles/UXML/RegularProgressBar.uxml +22 -0
- package/Styles/UXML/RegularProgressBar.uxml.meta +10 -0
- package/Styles/UXML.meta +3 -0
- package/package.json +1 -18
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs +0 -796
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs.meta +0 -3
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs +0 -275
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs.meta +0 -3
- package/Editor/PersistentDirectorySettings.cs +0 -248
- package/Editor/PersistentDirectorySettings.cs.meta +0 -3
- package/Editor/Sprites/ScriptableSpriteAtlas.cs +0 -95
- package/Editor/Sprites/ScriptableSpriteAtlas.cs.meta +0 -3
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs +0 -930
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs.meta +0 -3
- package/Editor/Sprites.meta +0 -3
- package/Styles/Elements/Progress/ArcedProgressBar.cs +0 -345
- package/Styles/Elements/Progress/ArcedProgressBar.cs.meta +0 -3
- package/Styles/Elements/Progress/GlitchProgressBar.cs +0 -416
- package/Styles/Elements/Progress/GlitchProgressBar.cs.meta +0 -3
- package/Styles/Elements/Progress/LiquidProgressBar.cs +0 -632
- package/Styles/Elements/Progress/LiquidProgressBar.cs.meta +0 -3
- package/Styles/Elements/Progress/MarchingAntsProgressBar.cs +0 -722
- package/Styles/Elements/Progress/MarchingAntsProgressBar.cs.meta +0 -3
- package/Styles/Elements/Progress/WigglyProgressBar.cs +0 -837
- package/Styles/Elements/Progress/WigglyProgressBar.cs.meta +0 -3
- package/Styles/Elements/Progress.meta +0 -3
- package/Styles/USS/ArcedProgressBar.uss +0 -19
- package/Styles/USS/ArcedProgressBar.uss.meta +0 -3
- package/Styles/USS/WigglyProgressBar.uss +0 -17
- package/Styles/USS/WigglyProgressBar.uss.meta +0 -3
- /package/Editor/{Sprites/AnimationCopier.cs.meta → AnimationCopier.cs.meta} +0 -0
- /package/Editor/{Sprites/AnimationCreator.cs.meta → AnimationCreator.cs.meta} +0 -0
- /package/Editor/{Sprites/SpriteCropper.cs.meta → SpriteCropper.cs.meta} +0 -0
- /package/Editor/{Sprites/SpriteSettingsApplier.cs.meta → SpriteSettingsApplier.cs.meta} +0 -0
- /package/Editor/{Sprites/TextureResizerWizard.cs.meta → TextureResizerWizard.cs.meta} +0 -0
- /package/Editor/{Sprites/TextureSettingsApplier.cs.meta → TextureSettingsApplier.cs.meta} +0 -0
- /package/Styles/Elements/{Progress/CircularProgressBar.cs.meta → CircularProgressBar.cs.meta} +0 -0
- /package/Styles/Elements/{Progress/RegularProgressBar.cs.meta → RegularProgressBar.cs.meta} +0 -0
|
@@ -1,722 +0,0 @@
|
|
|
1
|
-
namespace WallstopStudios.UnityHelpers.Styles.Elements.Progress
|
|
2
|
-
{
|
|
3
|
-
using System.Collections.Generic;
|
|
4
|
-
using System.ComponentModel;
|
|
5
|
-
using UnityEngine;
|
|
6
|
-
using UnityEngine.UIElements;
|
|
7
|
-
|
|
8
|
-
public sealed class MarchingAntsProgressBar : VisualElement
|
|
9
|
-
{
|
|
10
|
-
public enum OrientationType
|
|
11
|
-
{
|
|
12
|
-
Horizontal = 0,
|
|
13
|
-
Vertical = 1,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public const string USSClassName = "marching-ants-progress-bar";
|
|
17
|
-
public const string USSTrackClassName = USSClassName + "__track";
|
|
18
|
-
public const string USSFillContainerClassName = USSClassName + "__fill-container";
|
|
19
|
-
public const string USSFillClassName = USSClassName + "__fill";
|
|
20
|
-
public const string USSTrackColorVarName = "--ants-track-color";
|
|
21
|
-
public const string USSProgressColorVarName = "--ants-progress-color";
|
|
22
|
-
public const string USSThicknessVarName = "--ants-thickness";
|
|
23
|
-
public const string USSBorderRadiusVarName = "--ants-border-radius";
|
|
24
|
-
public const string USSDashOnVarName = "--ants-dash-on";
|
|
25
|
-
public const string USSDashOffVarName = "--ants-dash-off";
|
|
26
|
-
|
|
27
|
-
private readonly VisualElement _trackElement;
|
|
28
|
-
private readonly VisualElement _fillContainer;
|
|
29
|
-
private readonly VisualElement _fillElement;
|
|
30
|
-
private float _progress = 0.5f;
|
|
31
|
-
public float Progress
|
|
32
|
-
{
|
|
33
|
-
get => _progress;
|
|
34
|
-
set
|
|
35
|
-
{
|
|
36
|
-
if (float.IsNaN(value) || float.IsInfinity(value))
|
|
37
|
-
{
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
_progress = Mathf.Clamp01(value);
|
|
41
|
-
UpdateFillContainerSize();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private Color _trackColor = new(0.4f, 0.4f, 0.4f, 1f);
|
|
46
|
-
public Color TrackColor
|
|
47
|
-
{
|
|
48
|
-
get => _trackColor;
|
|
49
|
-
set
|
|
50
|
-
{
|
|
51
|
-
_trackColor = value;
|
|
52
|
-
_trackElement?.MarkDirtyRepaint();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private Color _progressColor = Color.white;
|
|
57
|
-
public Color ProgressColor
|
|
58
|
-
{
|
|
59
|
-
get => _progressColor;
|
|
60
|
-
set
|
|
61
|
-
{
|
|
62
|
-
_progressColor = value;
|
|
63
|
-
_fillElement?.MarkDirtyRepaint();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private float _thickness = 3f;
|
|
68
|
-
public float Thickness
|
|
69
|
-
{
|
|
70
|
-
get => _thickness;
|
|
71
|
-
set
|
|
72
|
-
{
|
|
73
|
-
if (float.IsNaN(value) || float.IsInfinity(value))
|
|
74
|
-
{
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
_thickness = Mathf.Max(1f, value);
|
|
78
|
-
UpdateTrackAndFillElements();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private float _borderRadius = 5f;
|
|
83
|
-
public float BorderRadius
|
|
84
|
-
{
|
|
85
|
-
get => _borderRadius;
|
|
86
|
-
set
|
|
87
|
-
{
|
|
88
|
-
_borderRadius = Mathf.Max(0, value);
|
|
89
|
-
UpdateTrackAndFillElements();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private OrientationType _orientation = OrientationType.Horizontal;
|
|
94
|
-
public OrientationType Orientation
|
|
95
|
-
{
|
|
96
|
-
get => _orientation;
|
|
97
|
-
set
|
|
98
|
-
{
|
|
99
|
-
if (_orientation == value)
|
|
100
|
-
{
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
_orientation = value;
|
|
105
|
-
UpdateFillContainerSize();
|
|
106
|
-
UpdateTrackAndFillElements();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private float _dashOnLength = 4f;
|
|
111
|
-
public float DashOnLength
|
|
112
|
-
{
|
|
113
|
-
get => _dashOnLength;
|
|
114
|
-
set
|
|
115
|
-
{
|
|
116
|
-
if (float.IsNaN(value) || float.IsInfinity(value))
|
|
117
|
-
{
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
_dashOnLength = Mathf.Max(1f, value);
|
|
121
|
-
UpdateTrackAndFillElements();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private float _dashOffLength = 4f;
|
|
126
|
-
public float DashOffLength
|
|
127
|
-
{
|
|
128
|
-
get => _dashOffLength;
|
|
129
|
-
set
|
|
130
|
-
{
|
|
131
|
-
if (float.IsNaN(value) || float.IsInfinity(value))
|
|
132
|
-
{
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
_dashOffLength = Mathf.Max(1f, value);
|
|
136
|
-
UpdateTrackAndFillElements();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private bool _animate = true;
|
|
141
|
-
public bool Animate
|
|
142
|
-
{
|
|
143
|
-
get => _animate;
|
|
144
|
-
set
|
|
145
|
-
{
|
|
146
|
-
if (_animate == value)
|
|
147
|
-
{
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
_animate = value;
|
|
152
|
-
if (_animate)
|
|
153
|
-
{
|
|
154
|
-
StartAnimationUpdate();
|
|
155
|
-
}
|
|
156
|
-
else
|
|
157
|
-
{
|
|
158
|
-
StopAnimationUpdate();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
private float _animationSpeed = 40f;
|
|
164
|
-
public float AnimationSpeed
|
|
165
|
-
{
|
|
166
|
-
get => _animationSpeed;
|
|
167
|
-
set
|
|
168
|
-
{
|
|
169
|
-
if (float.IsNaN(value) || float.IsInfinity(value))
|
|
170
|
-
{
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
_animationSpeed = value;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
private float _currentDashOffset;
|
|
178
|
-
private IVisualElementScheduledItem _animationUpdateItem;
|
|
179
|
-
private readonly List<Vector2> _pathPoints = new();
|
|
180
|
-
private bool _pathDirty = true;
|
|
181
|
-
private Rect _lastKnownRect = Rect.zero;
|
|
182
|
-
|
|
183
|
-
public new class UxmlFactory : UxmlFactory<MarchingAntsProgressBar, UxmlTraits> { }
|
|
184
|
-
|
|
185
|
-
public new class UxmlTraits : VisualElement.UxmlTraits
|
|
186
|
-
{
|
|
187
|
-
private readonly UxmlFloatAttributeDescription _progressAttribute = new()
|
|
188
|
-
{
|
|
189
|
-
name = "progress",
|
|
190
|
-
defaultValue = 0.5f,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
private readonly UxmlColorAttributeDescription _trackColorAttribute = new()
|
|
194
|
-
{
|
|
195
|
-
name = "track-color",
|
|
196
|
-
defaultValue = new Color(0.4f, 0.4f, 0.4f, 1),
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
private readonly UxmlColorAttributeDescription _progressColorAttribute = new()
|
|
200
|
-
{
|
|
201
|
-
name = "progress-color",
|
|
202
|
-
defaultValue = Color.white,
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
private readonly UxmlFloatAttributeDescription _thicknessAttribute = new()
|
|
206
|
-
{
|
|
207
|
-
name = "thickness",
|
|
208
|
-
defaultValue = 3f,
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
private readonly UxmlFloatAttributeDescription _borderRadiusAttribute = new()
|
|
212
|
-
{
|
|
213
|
-
name = "border-radius",
|
|
214
|
-
defaultValue = 5f,
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
private readonly UxmlEnumAttributeDescription<OrientationType> _orientationAttribute =
|
|
218
|
-
new() { name = "orientation", defaultValue = OrientationType.Horizontal };
|
|
219
|
-
|
|
220
|
-
private readonly UxmlFloatAttributeDescription _dashOnLengthAttribute = new()
|
|
221
|
-
{
|
|
222
|
-
name = "dash-on",
|
|
223
|
-
defaultValue = 4f,
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
private readonly UxmlFloatAttributeDescription _dashOffLengthAttribute = new()
|
|
227
|
-
{
|
|
228
|
-
name = "dash-off",
|
|
229
|
-
defaultValue = 4f,
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
private readonly UxmlBoolAttributeDescription _animateAttribute = new()
|
|
233
|
-
{
|
|
234
|
-
name = "animate",
|
|
235
|
-
defaultValue = true,
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
private readonly UxmlFloatAttributeDescription _animationSpeedAttribute = new()
|
|
239
|
-
{
|
|
240
|
-
name = "animation-speed",
|
|
241
|
-
defaultValue = 40f,
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
|
|
245
|
-
{
|
|
246
|
-
base.Init(ve, bag, cc);
|
|
247
|
-
|
|
248
|
-
if (ve is not MarchingAntsProgressBar bar)
|
|
249
|
-
{
|
|
250
|
-
Debug.LogError(
|
|
251
|
-
$"Initialization failed, expected {nameof(MarchingAntsProgressBar)}, found {ve?.GetType()}.)"
|
|
252
|
-
);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
bar.Thickness = _thicknessAttribute.GetValueFromBag(bag, cc);
|
|
256
|
-
bar.BorderRadius = _borderRadiusAttribute.GetValueFromBag(bag, cc);
|
|
257
|
-
bar.DashOnLength = _dashOnLengthAttribute.GetValueFromBag(bag, cc);
|
|
258
|
-
bar.DashOffLength = _dashOffLengthAttribute.GetValueFromBag(bag, cc);
|
|
259
|
-
bar.Orientation = _orientationAttribute.GetValueFromBag(bag, cc);
|
|
260
|
-
bar.TrackColor = _trackColorAttribute.GetValueFromBag(bag, cc);
|
|
261
|
-
bar.ProgressColor = _progressColorAttribute.GetValueFromBag(bag, cc);
|
|
262
|
-
bar.AnimationSpeed = _animationSpeedAttribute.GetValueFromBag(bag, cc);
|
|
263
|
-
bar.Animate = _animateAttribute.GetValueFromBag(bag, cc);
|
|
264
|
-
bar.Progress = _progressAttribute.GetValueFromBag(bag, cc);
|
|
265
|
-
if (
|
|
266
|
-
!bar.style.height.Equals(StyleKeyword.Initial)
|
|
267
|
-
&& bar.style.height.value == 0
|
|
268
|
-
&& bar.style.height.keyword == StyleKeyword.None
|
|
269
|
-
)
|
|
270
|
-
{
|
|
271
|
-
bar.style.height = 20;
|
|
272
|
-
}
|
|
273
|
-
if (
|
|
274
|
-
!bar.style.width.Equals(StyleKeyword.Initial)
|
|
275
|
-
&& bar.style.width.value == 0
|
|
276
|
-
&& bar.style.width.keyword == StyleKeyword.None
|
|
277
|
-
)
|
|
278
|
-
{
|
|
279
|
-
bar.style.width = 200;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
bar._pathDirty = true;
|
|
283
|
-
bar.schedule.Execute(() => bar.UpdateFillElementSize(bar.contentRect))
|
|
284
|
-
.ExecuteLater(0);
|
|
285
|
-
bar.UpdateFillContainerSize();
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
public MarchingAntsProgressBar()
|
|
290
|
-
{
|
|
291
|
-
AddToClassList(USSClassName);
|
|
292
|
-
_trackElement = new VisualElement { name = "track", pickingMode = PickingMode.Ignore };
|
|
293
|
-
_trackElement.AddToClassList(USSTrackClassName);
|
|
294
|
-
_trackElement.style.position = Position.Absolute;
|
|
295
|
-
_trackElement.style.left = 0;
|
|
296
|
-
_trackElement.style.top = 0;
|
|
297
|
-
_trackElement.style.width = Length.Percent(100);
|
|
298
|
-
_trackElement.style.height = Length.Percent(100);
|
|
299
|
-
_trackElement.generateVisualContent += DrawTrackOrFill;
|
|
300
|
-
Add(_trackElement);
|
|
301
|
-
_fillContainer = new VisualElement
|
|
302
|
-
{
|
|
303
|
-
name = "fill-container",
|
|
304
|
-
pickingMode = PickingMode.Ignore,
|
|
305
|
-
};
|
|
306
|
-
_fillContainer.AddToClassList(USSFillContainerClassName);
|
|
307
|
-
_fillContainer.style.overflow = Overflow.Hidden;
|
|
308
|
-
_fillContainer.style.position = Position.Absolute;
|
|
309
|
-
_fillContainer.style.left = 0;
|
|
310
|
-
_fillContainer.style.top = 0;
|
|
311
|
-
_fillContainer.style.width = Length.Percent(100);
|
|
312
|
-
_fillContainer.style.height = Length.Percent(100);
|
|
313
|
-
Add(_fillContainer);
|
|
314
|
-
_fillElement = new VisualElement { name = "fill", pickingMode = PickingMode.Ignore };
|
|
315
|
-
_fillElement.AddToClassList(USSFillClassName);
|
|
316
|
-
_fillElement.style.position = Position.Absolute;
|
|
317
|
-
_fillElement.style.left = 0;
|
|
318
|
-
_fillElement.style.top = 0;
|
|
319
|
-
_fillElement.generateVisualContent += DrawTrackOrFill;
|
|
320
|
-
_fillContainer.Add(_fillElement);
|
|
321
|
-
RegisterCallbacks();
|
|
322
|
-
UpdateFillContainerSize();
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
private void RegisterCallbacks()
|
|
326
|
-
{
|
|
327
|
-
RegisterCallback<CustomStyleResolvedEvent>(OnCustomStyleResolved);
|
|
328
|
-
RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
|
|
329
|
-
RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
|
|
330
|
-
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private void OnGeometryChanged(GeometryChangedEvent evt)
|
|
334
|
-
{
|
|
335
|
-
if (evt.newRect == evt.oldRect && evt.newRect == _lastKnownRect)
|
|
336
|
-
{
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (_lastKnownRect != evt.newRect)
|
|
341
|
-
{
|
|
342
|
-
_pathDirty = true;
|
|
343
|
-
_lastKnownRect = evt.newRect;
|
|
344
|
-
UpdateFillElementSize(evt.newRect);
|
|
345
|
-
UpdateTrackAndFillElements();
|
|
346
|
-
UpdateFillContainerSize();
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
private void UpdateFillElementSize(Rect trackRect)
|
|
351
|
-
{
|
|
352
|
-
if (_fillElement == null)
|
|
353
|
-
{
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
_fillElement.style.width = trackRect.width;
|
|
357
|
-
_fillElement.style.height = trackRect.height;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
private void OnAttachToPanel(AttachToPanelEvent evt)
|
|
361
|
-
{
|
|
362
|
-
if (_animate)
|
|
363
|
-
{
|
|
364
|
-
StartAnimationUpdate();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
private void OnDetachFromPanel(DetachFromPanelEvent evt)
|
|
369
|
-
{
|
|
370
|
-
StopAnimationUpdate();
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
private void StartAnimationUpdate()
|
|
374
|
-
{
|
|
375
|
-
if (!_animate || panel == null || _animationUpdateItem != null)
|
|
376
|
-
{
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
_animationUpdateItem = schedule.Execute(UpdateAnimation).Every(16);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
private void StopAnimationUpdate()
|
|
384
|
-
{
|
|
385
|
-
_animationUpdateItem?.Pause();
|
|
386
|
-
_animationUpdateItem = null;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
private void UpdateAnimation(TimerState ts)
|
|
390
|
-
{
|
|
391
|
-
if (!_animate || panel == null || _animationSpeed == 0f)
|
|
392
|
-
{
|
|
393
|
-
StopAnimationUpdate();
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
float totalPatternLength = _dashOnLength + _dashOffLength;
|
|
398
|
-
if (totalPatternLength <= 0)
|
|
399
|
-
{
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
_currentDashOffset += _animationSpeed * (ts.deltaTime / 1000f);
|
|
404
|
-
_currentDashOffset =
|
|
405
|
-
(_currentDashOffset % totalPatternLength + totalPatternLength) % totalPatternLength;
|
|
406
|
-
_fillElement?.MarkDirtyRepaint();
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
private void UpdateTrackAndFillElements()
|
|
410
|
-
{
|
|
411
|
-
_pathDirty = true;
|
|
412
|
-
_trackElement?.MarkDirtyRepaint();
|
|
413
|
-
_fillElement?.MarkDirtyRepaint();
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
private void UpdateFillContainerSize()
|
|
417
|
-
{
|
|
418
|
-
if (_fillContainer == null)
|
|
419
|
-
{
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
switch (_orientation)
|
|
424
|
-
{
|
|
425
|
-
case OrientationType.Horizontal:
|
|
426
|
-
{
|
|
427
|
-
_fillContainer.style.width = Length.Percent(_progress * 100f);
|
|
428
|
-
_fillContainer.style.height = Length.Percent(100f);
|
|
429
|
-
_fillContainer.style.top = 0;
|
|
430
|
-
_fillContainer.style.bottom = StyleKeyword.Auto;
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
case OrientationType.Vertical:
|
|
434
|
-
{
|
|
435
|
-
_fillContainer.style.width = Length.Percent(100f);
|
|
436
|
-
_fillContainer.style.height = Length.Percent(_progress * 100f);
|
|
437
|
-
_fillContainer.style.top = StyleKeyword.Auto;
|
|
438
|
-
_fillContainer.style.bottom = 0;
|
|
439
|
-
break;
|
|
440
|
-
}
|
|
441
|
-
default:
|
|
442
|
-
{
|
|
443
|
-
throw new InvalidEnumArgumentException(
|
|
444
|
-
nameof(_orientation),
|
|
445
|
-
(int)_orientation,
|
|
446
|
-
typeof(OrientationType)
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
private void OnCustomStyleResolved(CustomStyleResolvedEvent evt)
|
|
453
|
-
{
|
|
454
|
-
if (
|
|
455
|
-
customStyle.TryGetValue(
|
|
456
|
-
new CustomStyleProperty<Color>(USSTrackColorVarName),
|
|
457
|
-
out Color tc
|
|
458
|
-
)
|
|
459
|
-
)
|
|
460
|
-
{
|
|
461
|
-
TrackColor = tc;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
if (
|
|
465
|
-
customStyle.TryGetValue(
|
|
466
|
-
new CustomStyleProperty<Color>(USSProgressColorVarName),
|
|
467
|
-
out Color pc
|
|
468
|
-
)
|
|
469
|
-
)
|
|
470
|
-
{
|
|
471
|
-
ProgressColor = pc;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
if (
|
|
475
|
-
customStyle.TryGetValue(
|
|
476
|
-
new CustomStyleProperty<float>(USSThicknessVarName),
|
|
477
|
-
out float th
|
|
478
|
-
)
|
|
479
|
-
)
|
|
480
|
-
{
|
|
481
|
-
Thickness = th;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (
|
|
485
|
-
customStyle.TryGetValue(
|
|
486
|
-
new CustomStyleProperty<float>(USSBorderRadiusVarName),
|
|
487
|
-
out float br
|
|
488
|
-
)
|
|
489
|
-
)
|
|
490
|
-
{
|
|
491
|
-
BorderRadius = br;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
if (
|
|
495
|
-
customStyle.TryGetValue(
|
|
496
|
-
new CustomStyleProperty<float>(USSDashOnVarName),
|
|
497
|
-
out float don
|
|
498
|
-
)
|
|
499
|
-
)
|
|
500
|
-
{
|
|
501
|
-
DashOnLength = don;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
if (
|
|
505
|
-
customStyle.TryGetValue(
|
|
506
|
-
new CustomStyleProperty<float>(USSDashOffVarName),
|
|
507
|
-
out float doff
|
|
508
|
-
)
|
|
509
|
-
)
|
|
510
|
-
{
|
|
511
|
-
DashOffLength = doff;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
private void DrawTrackOrFill(MeshGenerationContext mgc)
|
|
516
|
-
{
|
|
517
|
-
Painter2D painter = mgc.painter2D;
|
|
518
|
-
VisualElement targetElement = mgc.visualElement;
|
|
519
|
-
Rect rect = targetElement.contentRect;
|
|
520
|
-
|
|
521
|
-
Color color;
|
|
522
|
-
float dashOffset;
|
|
523
|
-
bool isFillElement = targetElement == _fillElement;
|
|
524
|
-
if (isFillElement)
|
|
525
|
-
{
|
|
526
|
-
color = _progressColor;
|
|
527
|
-
dashOffset = _currentDashOffset;
|
|
528
|
-
}
|
|
529
|
-
else
|
|
530
|
-
{
|
|
531
|
-
color = _trackColor;
|
|
532
|
-
dashOffset = 0f;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
if (
|
|
536
|
-
rect.width <= 0
|
|
537
|
-
|| rect.height <= 0
|
|
538
|
-
|| _thickness <= 0
|
|
539
|
-
|| _dashOnLength + _dashOffLength <= 0
|
|
540
|
-
)
|
|
541
|
-
{
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
if (_pathDirty || _pathPoints.Count == 0 || _lastKnownRect != contentRect)
|
|
546
|
-
{
|
|
547
|
-
_lastKnownRect = contentRect;
|
|
548
|
-
if (_lastKnownRect is { width: > 0, height: > 0 })
|
|
549
|
-
{
|
|
550
|
-
CalculatePathPoints(_lastKnownRect, _borderRadius);
|
|
551
|
-
_pathDirty = false;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
if (_pathPoints.Count < 2)
|
|
555
|
-
{
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
painter.strokeColor = color;
|
|
560
|
-
painter.lineWidth = _thickness;
|
|
561
|
-
painter.lineCap = LineCap.Butt;
|
|
562
|
-
float patternLength = _dashOnLength + _dashOffLength;
|
|
563
|
-
bool isDrawingDash;
|
|
564
|
-
float remainingInSegment;
|
|
565
|
-
float wrappedOffset = (dashOffset % patternLength + patternLength) % patternLength;
|
|
566
|
-
if (wrappedOffset >= _dashOnLength)
|
|
567
|
-
{
|
|
568
|
-
isDrawingDash = false;
|
|
569
|
-
remainingInSegment = _dashOffLength - (wrappedOffset - _dashOnLength);
|
|
570
|
-
}
|
|
571
|
-
else
|
|
572
|
-
{
|
|
573
|
-
isDrawingDash = true;
|
|
574
|
-
remainingInSegment = _dashOnLength - wrappedOffset;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (Mathf.Approximately(remainingInSegment, 0))
|
|
578
|
-
{
|
|
579
|
-
isDrawingDash = !isDrawingDash;
|
|
580
|
-
remainingInSegment = isDrawingDash ? _dashOnLength : _dashOffLength;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
painter.BeginPath();
|
|
584
|
-
for (int i = 0; i < _pathPoints.Count - 1; i++)
|
|
585
|
-
{
|
|
586
|
-
Vector2 p1 = _pathPoints[i];
|
|
587
|
-
Vector2 p2 = _pathPoints[i + 1];
|
|
588
|
-
Vector2 segmentVector = p2 - p1;
|
|
589
|
-
float segmentLength = segmentVector.magnitude;
|
|
590
|
-
if (Mathf.Approximately(segmentLength, 0))
|
|
591
|
-
{
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
Vector2 segmentDir = segmentVector / segmentLength;
|
|
596
|
-
float distanceCoveredOnSegment = 0f;
|
|
597
|
-
while (distanceCoveredOnSegment < segmentLength)
|
|
598
|
-
{
|
|
599
|
-
float lengthToProcess = Mathf.Min(
|
|
600
|
-
remainingInSegment,
|
|
601
|
-
segmentLength - distanceCoveredOnSegment
|
|
602
|
-
);
|
|
603
|
-
|
|
604
|
-
Vector2 currentDrawStart = p1 + segmentDir * distanceCoveredOnSegment;
|
|
605
|
-
Vector2 currentDrawEnd = currentDrawStart + segmentDir * lengthToProcess;
|
|
606
|
-
if (isDrawingDash)
|
|
607
|
-
{
|
|
608
|
-
painter.MoveTo(currentDrawStart);
|
|
609
|
-
painter.LineTo(currentDrawEnd);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
distanceCoveredOnSegment += lengthToProcess;
|
|
613
|
-
remainingInSegment -= lengthToProcess;
|
|
614
|
-
if (Mathf.Approximately(remainingInSegment, 0))
|
|
615
|
-
{
|
|
616
|
-
isDrawingDash = !isDrawingDash;
|
|
617
|
-
remainingInSegment = isDrawingDash ? _dashOnLength : _dashOffLength;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
painter.Stroke();
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
private void CalculatePathPoints(Rect r, float borderRadius)
|
|
625
|
-
{
|
|
626
|
-
_pathPoints.Clear();
|
|
627
|
-
const int segmentsPerCorner = 8;
|
|
628
|
-
float radius = Mathf.Min(borderRadius, r.height / 2f, r.width / 2f);
|
|
629
|
-
if (radius < 0.01f)
|
|
630
|
-
{
|
|
631
|
-
radius = 0;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
Vector2 currentPoint = new(r.xMin + radius, r.yMin);
|
|
635
|
-
_pathPoints.Add(currentPoint);
|
|
636
|
-
currentPoint = new Vector2(r.xMax - radius, r.yMin);
|
|
637
|
-
_pathPoints.Add(currentPoint);
|
|
638
|
-
if (radius > 0)
|
|
639
|
-
{
|
|
640
|
-
AddArcPoints(
|
|
641
|
-
_pathPoints,
|
|
642
|
-
new Vector2(r.xMax - radius, r.yMin + radius),
|
|
643
|
-
radius,
|
|
644
|
-
270f,
|
|
645
|
-
90f,
|
|
646
|
-
segmentsPerCorner
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
currentPoint = new Vector2(r.xMax, r.yMax - radius);
|
|
651
|
-
_pathPoints.Add(currentPoint);
|
|
652
|
-
if (radius > 0)
|
|
653
|
-
{
|
|
654
|
-
AddArcPoints(
|
|
655
|
-
_pathPoints,
|
|
656
|
-
new Vector2(r.xMax - radius, r.yMax - radius),
|
|
657
|
-
radius,
|
|
658
|
-
0f,
|
|
659
|
-
90f,
|
|
660
|
-
segmentsPerCorner
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
currentPoint = new Vector2(r.xMin + radius, r.yMax);
|
|
665
|
-
_pathPoints.Add(currentPoint);
|
|
666
|
-
if (radius > 0)
|
|
667
|
-
{
|
|
668
|
-
AddArcPoints(
|
|
669
|
-
_pathPoints,
|
|
670
|
-
new Vector2(r.xMin + radius, r.yMax - radius),
|
|
671
|
-
radius,
|
|
672
|
-
90f,
|
|
673
|
-
90f,
|
|
674
|
-
segmentsPerCorner
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
currentPoint = new Vector2(r.xMin, r.yMin + radius);
|
|
679
|
-
_pathPoints.Add(currentPoint);
|
|
680
|
-
if (radius > 0)
|
|
681
|
-
{
|
|
682
|
-
AddArcPoints(
|
|
683
|
-
_pathPoints,
|
|
684
|
-
new Vector2(r.xMin + radius, r.yMin + radius),
|
|
685
|
-
radius,
|
|
686
|
-
180f,
|
|
687
|
-
90f,
|
|
688
|
-
segmentsPerCorner
|
|
689
|
-
);
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
if (_pathPoints.Count > 0)
|
|
693
|
-
{
|
|
694
|
-
_pathPoints.Add(_pathPoints[0]);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
private static void AddArcPoints(
|
|
699
|
-
List<Vector2> points,
|
|
700
|
-
Vector2 center,
|
|
701
|
-
float radius,
|
|
702
|
-
float startAngleDeg,
|
|
703
|
-
float sweepAngleDeg,
|
|
704
|
-
int segments
|
|
705
|
-
)
|
|
706
|
-
{
|
|
707
|
-
float startRad = startAngleDeg * Mathf.Deg2Rad;
|
|
708
|
-
float endRad = (startAngleDeg + sweepAngleDeg) * Mathf.Deg2Rad;
|
|
709
|
-
float angleStep = (endRad - startRad) / Mathf.Max(1, segments);
|
|
710
|
-
for (int i = 1; i <= segments; i++)
|
|
711
|
-
{
|
|
712
|
-
float currentRad = startRad + i * angleStep;
|
|
713
|
-
points.Add(
|
|
714
|
-
new Vector2(
|
|
715
|
-
center.x + radius * Mathf.Cos(currentRad),
|
|
716
|
-
center.y + radius * Mathf.Sin(currentRad)
|
|
717
|
-
)
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|