com.wallstop-studios.unity-helpers 2.0.0-rc77 → 2.0.0-rc77.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.
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
{
|
|
3
3
|
#if UNITY_EDITOR
|
|
4
4
|
using System;
|
|
5
|
-
using System.Collections.
|
|
5
|
+
using System.Collections.Immutable;
|
|
6
6
|
using System.Linq;
|
|
7
7
|
using Core.Extension;
|
|
8
8
|
using Core.Helper;
|
|
9
9
|
using UnityEditor;
|
|
10
|
-
using UnityEngine;
|
|
11
10
|
using Object = UnityEngine.Object;
|
|
12
11
|
|
|
13
12
|
public sealed class SpriteLabelProcessor : AssetPostprocessor
|
|
@@ -19,7 +18,7 @@
|
|
|
19
18
|
string[] movedFromAssetPaths
|
|
20
19
|
)
|
|
21
20
|
{
|
|
22
|
-
bool anyChanged =
|
|
21
|
+
bool anyChanged = Helpers.CachedLabels.Count == 0;
|
|
23
22
|
InitializeCacheIfNeeded();
|
|
24
23
|
|
|
25
24
|
foreach (string path in importedAssets)
|
|
@@ -46,19 +45,29 @@
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
string[] newLabels = AssetDatabase.GetLabels(mainObj);
|
|
49
|
-
if (
|
|
50
|
-
!Helpers.CachedLabels.TryGetValue(path, out string[] oldLabels)
|
|
51
|
-
|| !AreEqual(oldLabels, newLabels)
|
|
52
|
-
)
|
|
48
|
+
if (newLabels.Length != 0)
|
|
53
49
|
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
if (
|
|
51
|
+
!Helpers.CachedLabels.TryGetValue(path, out string[] oldLabels)
|
|
52
|
+
|| !AreEqual(oldLabels, newLabels)
|
|
53
|
+
)
|
|
54
|
+
{
|
|
55
|
+
anyChanged = true;
|
|
56
|
+
if (newLabels.Length == 0)
|
|
57
|
+
{
|
|
58
|
+
Helpers.CachedLabels.Remove(path);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
string[] updated = new string[newLabels.Length];
|
|
63
|
+
Array.Copy(newLabels, updated, newLabels.Length);
|
|
64
|
+
Helpers.CachedLabels[path] = updated;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (Helpers.CachedLabels.ContainsKey(path))
|
|
68
|
+
{
|
|
60
69
|
anyChanged = true;
|
|
61
|
-
Helpers.CachedLabels
|
|
70
|
+
Helpers.CachedLabels.Remove(path);
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
73
|
|
|
@@ -94,19 +103,7 @@
|
|
|
94
103
|
return false;
|
|
95
104
|
}
|
|
96
105
|
|
|
97
|
-
|
|
98
|
-
HashSet<string> setB = new(b, StringComparer.OrdinalIgnoreCase);
|
|
99
|
-
return setA.SetEquals(setB);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private static string FormatLabels(string[] arr)
|
|
103
|
-
{
|
|
104
|
-
if (arr == null || arr.Length == 0)
|
|
105
|
-
{
|
|
106
|
-
return "(none)";
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return string.Join(", ", arr);
|
|
106
|
+
return a.ToImmutableHashSet(StringComparer.Ordinal).SetEquals(b);
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
109
|
#endif
|
|
@@ -564,8 +564,11 @@
|
|
|
564
564
|
|
|
565
565
|
if (allMatch)
|
|
566
566
|
{
|
|
567
|
-
|
|
568
|
-
|
|
567
|
+
foreach (
|
|
568
|
+
Object asset in AssetDatabase
|
|
569
|
+
.LoadAllAssetsAtPath(assetPath)
|
|
570
|
+
.Concat(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath))
|
|
571
|
+
)
|
|
569
572
|
{
|
|
570
573
|
if (asset is Sprite spriteAsset && spriteAsset != null)
|
|
571
574
|
{
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
return AllSpriteLabels;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
HashSet<string> allLabels = new(StringComparer.Ordinal);
|
|
42
42
|
string[] guids = AssetDatabase.FindAssets("t:Sprite");
|
|
43
43
|
foreach (string guid in guids)
|
|
44
44
|
{
|
|
@@ -50,11 +50,15 @@
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
string[] labels = AssetDatabase.GetLabels(asset);
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (labels.Length != 0)
|
|
54
|
+
{
|
|
55
|
+
CachedLabels[path] = labels;
|
|
56
|
+
allLabels.UnionWith(labels);
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
AllSpriteLabels = allLabels.ToArray();
|
|
61
|
+
Array.Sort(AllSpriteLabels);
|
|
58
62
|
return AllSpriteLabels;
|
|
59
63
|
#else
|
|
60
64
|
return Array.Empty<string>();
|
|
@@ -58,42 +58,32 @@
|
|
|
58
58
|
|
|
59
59
|
private static int CompareNatural(string nameA, string nameB)
|
|
60
60
|
{
|
|
61
|
-
Match
|
|
62
|
-
Match
|
|
63
|
-
|
|
64
|
-
bool hasNumberA = mA.Success;
|
|
65
|
-
bool hasNumberB = mB.Success;
|
|
61
|
+
Match matchA = TrailingNumberRegex.Match(nameA);
|
|
62
|
+
Match matchB = TrailingNumberRegex.Match(nameB);
|
|
66
63
|
|
|
67
64
|
// If both have trailing numbers, compare prefix then numeric
|
|
68
|
-
if (
|
|
65
|
+
if (matchA.Success && matchB.Success)
|
|
69
66
|
{
|
|
70
|
-
string prefixA =
|
|
71
|
-
string prefixB =
|
|
67
|
+
string prefixA = matchA.Groups[1].Value;
|
|
68
|
+
string prefixB = matchB.Groups[1].Value;
|
|
72
69
|
|
|
73
|
-
int prefixCompare =
|
|
70
|
+
int prefixCompare = string.Compare(
|
|
71
|
+
prefixA,
|
|
72
|
+
prefixB,
|
|
73
|
+
StringComparison.OrdinalIgnoreCase
|
|
74
|
+
);
|
|
74
75
|
if (prefixCompare != 0)
|
|
75
76
|
{
|
|
76
77
|
return prefixCompare;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
// same prefix → compare parsed integers
|
|
80
|
-
int numA = int.Parse(
|
|
81
|
-
int numB = int.Parse(
|
|
81
|
+
int numA = int.Parse(matchA.Groups[2].Value);
|
|
82
|
+
int numB = int.Parse(matchB.Groups[2].Value);
|
|
82
83
|
return numA.CompareTo(numB);
|
|
83
84
|
}
|
|
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
85
|
|
|
91
|
-
|
|
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);
|
|
86
|
+
return string.Compare(nameA, nameB, StringComparison.OrdinalIgnoreCase);
|
|
97
87
|
}
|
|
98
88
|
}
|
|
99
89
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.wallstop-studios.unity-helpers",
|
|
3
|
-
"version": "2.0.0-rc77",
|
|
3
|
+
"version": "2.0.0-rc77.2",
|
|
4
4
|
"displayName": "Unity Helpers",
|
|
5
5
|
"description": "Various Unity Helper Library",
|
|
6
6
|
"dependencies": {},
|
|
@@ -83,6 +83,8 @@
|
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
|
|
86
|
+
|
|
87
|
+
|
|
86
88
|
|
|
87
89
|
|
|
88
90
|
|