com.wallstop-studios.unity-helpers 2.0.0-rc76.5 → 2.0.0-rc76.7
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/AssetProcessors/SpriteLabelProcessor.cs +133 -0
- package/Editor/AssetProcessors/SpriteLabelProcessor.cs.meta +3 -0
- package/Editor/AssetProcessors.meta +3 -0
- package/Editor/CustomDrawers/StringInListeDrawer.cs +104 -25
- package/Editor/CustomDrawers/WShowIfPropertyDrawer.cs +12 -4
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs +4 -1
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs +189 -52
- package/Editor/Extensions/SerializedPropertyExtensions.cs +11 -0
- package/Editor/Sprites/ScriptableSpriteAtlas.cs +71 -1
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs +94 -34
- package/Editor/Sprites/SpriteSheetAnimationCreator.cs +1530 -0
- package/Editor/Sprites/SpriteSheetAnimationCreator.cs.meta +3 -0
- package/Runtime/Core/Attributes/WShowIfAttribute.cs +9 -1
- package/Runtime/Core/Extension/IListExtensions.cs +6 -0
- package/Runtime/Core/Helper/Helpers.cs +31 -3
- package/Runtime/Core/Helper/StringInList.cs +22 -3
- package/Runtime/Utils/UnityObjectNameComparer.cs +46 -1
- package/package.json +3 -1
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
2
2
|
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Linq;
|
|
3
5
|
using UnityEngine;
|
|
4
6
|
|
|
5
7
|
public sealed class WShowIfAttribute : PropertyAttribute
|
|
6
8
|
{
|
|
7
9
|
public readonly string conditionField;
|
|
8
10
|
public readonly bool inverse;
|
|
11
|
+
public object[] expectedValues;
|
|
9
12
|
|
|
10
|
-
public WShowIfAttribute(
|
|
13
|
+
public WShowIfAttribute(
|
|
14
|
+
string conditionField,
|
|
15
|
+
bool inverse = false,
|
|
16
|
+
object[] expectedValues = null
|
|
17
|
+
)
|
|
11
18
|
{
|
|
12
19
|
this.conditionField = conditionField;
|
|
13
20
|
this.inverse = inverse;
|
|
21
|
+
this.expectedValues = expectedValues?.ToArray() ?? Array.Empty<object>();
|
|
14
22
|
}
|
|
15
23
|
}
|
|
16
24
|
}
|
|
@@ -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
|
|
|
@@ -14,10 +14,7 @@
|
|
|
14
14
|
#if UNITY_EDITOR
|
|
15
15
|
using UnityEditor;
|
|
16
16
|
using UnityEditorInternal;
|
|
17
|
-
#else
|
|
18
|
-
using System;
|
|
19
17
|
#endif
|
|
20
|
-
|
|
21
18
|
public static partial class Helpers
|
|
22
19
|
{
|
|
23
20
|
private static readonly WaitForEndOfFrame WaitForEndOfFrame = new();
|
|
@@ -27,6 +24,37 @@
|
|
|
27
24
|
StringComparer.Ordinal
|
|
28
25
|
);
|
|
29
26
|
|
|
27
|
+
internal static string[] AllSpriteLabels;
|
|
28
|
+
|
|
29
|
+
public static string[] GetAllSpriteLabelNames()
|
|
30
|
+
{
|
|
31
|
+
#if UNITY_EDITOR
|
|
32
|
+
if (AllSpriteLabels != null)
|
|
33
|
+
{
|
|
34
|
+
return AllSpriteLabels;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
SortedSet<string> allLabels = new(StringComparer.Ordinal);
|
|
38
|
+
string[] guids = AssetDatabase.FindAssets("t:Sprite");
|
|
39
|
+
foreach (string guid in guids)
|
|
40
|
+
{
|
|
41
|
+
string path = AssetDatabase.GUIDToAssetPath(guid);
|
|
42
|
+
Object asset = AssetDatabase.LoadMainAssetAtPath(path);
|
|
43
|
+
if (asset == null)
|
|
44
|
+
{
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
allLabels.UnionWith(AssetDatabase.GetLabels(asset));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
AllSpriteLabels = allLabels.ToArray();
|
|
52
|
+
return AllSpriteLabels;
|
|
53
|
+
#else
|
|
54
|
+
return Array.Empty<string>();
|
|
55
|
+
#endif
|
|
56
|
+
}
|
|
57
|
+
|
|
30
58
|
public static string[] GetAllLayerNames()
|
|
31
59
|
{
|
|
32
60
|
#if UNITY_EDITOR
|
|
@@ -8,27 +8,46 @@
|
|
|
8
8
|
{
|
|
9
9
|
public delegate string[] GetStringList();
|
|
10
10
|
|
|
11
|
+
private bool _shouldRefresh;
|
|
12
|
+
private string[] _list;
|
|
13
|
+
private Func<string[]> _getStringList;
|
|
14
|
+
|
|
11
15
|
public StringInList(params string[] list)
|
|
12
16
|
{
|
|
13
|
-
|
|
17
|
+
_shouldRefresh = false;
|
|
18
|
+
_list = list;
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
public StringInList(Type type, string methodName)
|
|
17
22
|
{
|
|
23
|
+
_shouldRefresh = true;
|
|
18
24
|
MethodInfo method = type.GetMethod(
|
|
19
25
|
methodName,
|
|
20
26
|
BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic
|
|
21
27
|
);
|
|
22
28
|
if (method != null)
|
|
23
29
|
{
|
|
24
|
-
|
|
30
|
+
_getStringList = () => method.Invoke(null, null) as string[];
|
|
25
31
|
}
|
|
26
32
|
else
|
|
27
33
|
{
|
|
28
34
|
Debug.LogError($"NO SUCH METHOD {methodName} FOR {type}");
|
|
35
|
+
_getStringList = () => Array.Empty<string>();
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
38
|
|
|
32
|
-
public string[] List
|
|
39
|
+
public string[] List
|
|
40
|
+
{
|
|
41
|
+
get
|
|
42
|
+
{
|
|
43
|
+
if (_shouldRefresh)
|
|
44
|
+
{
|
|
45
|
+
return _getStringList();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return _list;
|
|
49
|
+
}
|
|
50
|
+
private set { _list = value; }
|
|
51
|
+
}
|
|
33
52
|
}
|
|
34
53
|
}
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.wallstop-studios.unity-helpers",
|
|
3
|
-
"version": "2.0.0-rc76.
|
|
3
|
+
"version": "2.0.0-rc76.7",
|
|
4
4
|
"displayName": "Unity Helpers",
|
|
5
5
|
"description": "Various Unity Helper Library",
|
|
6
6
|
"dependencies": {},
|
|
@@ -78,6 +78,8 @@
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
|
|
81
|
+
|
|
82
|
+
|
|
81
83
|
|
|
82
84
|
|
|
83
85
|
|