com.wallstop-studios.unity-helpers 2.0.0-rc77.1 → 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.Generic;
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 = !Helpers.CachedLabels.Any();
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
- Debug.Log(
55
- $"[SpriteLabelProcessor] Labels changed on '{path}': {FormatLabels(oldLabels)} → {FormatLabels(newLabels)}"
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
- string[] updated = new string[newLabels.Length];
59
- Array.Copy(newLabels, updated, newLabels.Length);
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[path] = updated;
70
+ Helpers.CachedLabels.Remove(path);
62
71
  }
63
72
  }
64
73
 
@@ -94,19 +103,7 @@
94
103
  return false;
95
104
  }
96
105
 
97
- HashSet<string> setA = new(a, StringComparer.OrdinalIgnoreCase);
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
@@ -38,7 +38,7 @@
38
38
  return AllSpriteLabels;
39
39
  }
40
40
 
41
- SortedSet<string> allLabels = new(StringComparer.Ordinal);
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
- CachedLabels[path] = labels;
54
- allLabels.UnionWith(labels);
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>();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc77.1",
3
+ "version": "2.0.0-rc77.2",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -85,5 +85,6 @@
85
85
 
86
86
 
87
87
 
88
+
88
89
 
89
90