com.wallstop-studios.unity-helpers 2.0.0-rc76.5 → 2.0.0-rc76.6
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/CustomEditors/PersistentDirectoryGUI.cs +4 -1
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs +43 -31
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs +9 -1
- package/Editor/Sprites/SpriteSheetAnimationCreator.cs +1218 -0
- package/Editor/Sprites/SpriteSheetAnimationCreator.cs.meta +3 -0
- package/Runtime/Core/Extension/IListExtensions.cs +6 -0
- package/Runtime/Utils/UnityObjectNameComparer.cs +46 -1
- package/package.json +2 -1
|
@@ -110,14 +110,20 @@
|
|
|
110
110
|
switch (inputList)
|
|
111
111
|
{
|
|
112
112
|
case T[] array:
|
|
113
|
+
{
|
|
113
114
|
Array.Sort(array, UnityObjectNameComparer<T>.Instance);
|
|
114
115
|
return;
|
|
116
|
+
}
|
|
115
117
|
case List<T> list:
|
|
118
|
+
{
|
|
116
119
|
list.Sort(UnityObjectNameComparer<T>.Instance);
|
|
117
120
|
return;
|
|
121
|
+
}
|
|
118
122
|
default:
|
|
123
|
+
{
|
|
119
124
|
inputList.InsertionSort(UnityObjectNameComparer<T>.Instance);
|
|
120
125
|
break;
|
|
126
|
+
}
|
|
121
127
|
}
|
|
122
128
|
}
|
|
123
129
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
4
|
using System.Collections.Generic;
|
|
5
|
+
using System.Text.RegularExpressions;
|
|
5
6
|
#if UNITY_EDITOR
|
|
6
7
|
using UnityEditor;
|
|
7
8
|
#endif
|
|
@@ -9,6 +10,10 @@
|
|
|
9
10
|
public sealed class UnityObjectNameComparer<T> : IComparer<T>
|
|
10
11
|
where T : UnityEngine.Object
|
|
11
12
|
{
|
|
13
|
+
private static readonly Regex TrailingNumberRegex = new(
|
|
14
|
+
@"^(.*?)(\d+)$",
|
|
15
|
+
RegexOptions.Compiled
|
|
16
|
+
);
|
|
12
17
|
public static readonly UnityObjectNameComparer<T> Instance = new();
|
|
13
18
|
|
|
14
19
|
private UnityObjectNameComparer() { }
|
|
@@ -30,7 +35,7 @@
|
|
|
30
35
|
return -1;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
int comparison =
|
|
38
|
+
int comparison = CompareNatural(x.name, y.name);
|
|
34
39
|
if (comparison != 0)
|
|
35
40
|
{
|
|
36
41
|
return comparison;
|
|
@@ -50,5 +55,45 @@
|
|
|
50
55
|
|
|
51
56
|
return comparison;
|
|
52
57
|
}
|
|
58
|
+
|
|
59
|
+
private static int CompareNatural(string nameA, string nameB)
|
|
60
|
+
{
|
|
61
|
+
Match mA = TrailingNumberRegex.Match(nameA);
|
|
62
|
+
Match mB = TrailingNumberRegex.Match(nameB);
|
|
63
|
+
|
|
64
|
+
bool hasNumberA = mA.Success;
|
|
65
|
+
bool hasNumberB = mB.Success;
|
|
66
|
+
|
|
67
|
+
// If both have trailing numbers, compare prefix then numeric
|
|
68
|
+
if (hasNumberA && hasNumberB)
|
|
69
|
+
{
|
|
70
|
+
string prefixA = mA.Groups[1].Value;
|
|
71
|
+
string prefixB = mB.Groups[1].Value;
|
|
72
|
+
|
|
73
|
+
int prefixCompare = StringComparer.OrdinalIgnoreCase.Compare(prefixA, prefixB);
|
|
74
|
+
if (prefixCompare != 0)
|
|
75
|
+
{
|
|
76
|
+
return prefixCompare;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// same prefix → compare parsed integers
|
|
80
|
+
int numA = int.Parse(mA.Groups[2].Value);
|
|
81
|
+
int numB = int.Parse(mB.Groups[2].Value);
|
|
82
|
+
return numA.CompareTo(numB);
|
|
83
|
+
}
|
|
84
|
+
// If only one has a trailing number, treat the one without number as coming first
|
|
85
|
+
|
|
86
|
+
if (hasNumberA)
|
|
87
|
+
{
|
|
88
|
+
return 1; // B (no number) comes before A
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (hasNumberB)
|
|
92
|
+
{
|
|
93
|
+
return -1; // A (no number) comes before B
|
|
94
|
+
}
|
|
95
|
+
// Neither has a trailing number → pure string compare
|
|
96
|
+
return StringComparer.OrdinalIgnoreCase.Compare(nameA, nameB);
|
|
97
|
+
}
|
|
53
98
|
}
|
|
54
99
|
}
|
package/package.json
CHANGED