com.wallstop-studios.unity-helpers 2.0.0-rc76.8 → 2.0.0-rc77
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 +6 -26
- package/Editor/CustomDrawers/WShowIfPropertyDrawer.cs +37 -4
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs +3 -2
- package/Editor/Extensions/SerializedPropertyExtensions.cs +28 -6
- package/Editor/Sprites/ScriptableSpriteAtlas.cs +1 -8
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs +22 -20
- package/Runtime/Core/Helper/Helpers.cs +7 -1
- package/package.json +3 -1
|
@@ -12,10 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
public sealed class SpriteLabelProcessor : AssetPostprocessor
|
|
14
14
|
{
|
|
15
|
-
private static readonly Dictionary<string, string[]> CachedLabels = new(
|
|
16
|
-
StringComparer.OrdinalIgnoreCase
|
|
17
|
-
);
|
|
18
|
-
|
|
19
15
|
private static void OnPostprocessAllAssets(
|
|
20
16
|
string[] importedAssets,
|
|
21
17
|
string[] deletedAssets,
|
|
@@ -23,7 +19,7 @@
|
|
|
23
19
|
string[] movedFromAssetPaths
|
|
24
20
|
)
|
|
25
21
|
{
|
|
26
|
-
bool anyChanged = !CachedLabels.Any();
|
|
22
|
+
bool anyChanged = !Helpers.CachedLabels.Any();
|
|
27
23
|
InitializeCacheIfNeeded();
|
|
28
24
|
|
|
29
25
|
foreach (string path in importedAssets)
|
|
@@ -51,7 +47,7 @@
|
|
|
51
47
|
|
|
52
48
|
string[] newLabels = AssetDatabase.GetLabels(mainObj);
|
|
53
49
|
if (
|
|
54
|
-
!CachedLabels.TryGetValue(path, out string[] oldLabels)
|
|
50
|
+
!Helpers.CachedLabels.TryGetValue(path, out string[] oldLabels)
|
|
55
51
|
|| !AreEqual(oldLabels, newLabels)
|
|
56
52
|
)
|
|
57
53
|
{
|
|
@@ -62,14 +58,14 @@
|
|
|
62
58
|
string[] updated = new string[newLabels.Length];
|
|
63
59
|
Array.Copy(newLabels, updated, newLabels.Length);
|
|
64
60
|
anyChanged = true;
|
|
65
|
-
CachedLabels[path] = updated;
|
|
61
|
+
Helpers.CachedLabels[path] = updated;
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
if (anyChanged)
|
|
70
66
|
{
|
|
71
|
-
Helpers.AllSpriteLabels =
|
|
72
|
-
.Values.SelectMany(x => x)
|
|
67
|
+
Helpers.AllSpriteLabels = Helpers
|
|
68
|
+
.CachedLabels.Values.SelectMany(x => x)
|
|
73
69
|
.Distinct()
|
|
74
70
|
.Ordered()
|
|
75
71
|
.ToArray();
|
|
@@ -78,23 +74,7 @@
|
|
|
78
74
|
|
|
79
75
|
private static void InitializeCacheIfNeeded()
|
|
80
76
|
{
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
string[] guids = AssetDatabase.FindAssets("t:Sprite");
|
|
87
|
-
foreach (string guid in guids)
|
|
88
|
-
{
|
|
89
|
-
string path = AssetDatabase.GUIDToAssetPath(guid);
|
|
90
|
-
Object asset = AssetDatabase.LoadMainAssetAtPath(path);
|
|
91
|
-
if (asset == null)
|
|
92
|
-
{
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
CachedLabels[path] = AssetDatabase.GetLabels(asset);
|
|
97
|
-
}
|
|
77
|
+
_ = Helpers.GetAllSpriteLabelNames();
|
|
98
78
|
}
|
|
99
79
|
|
|
100
80
|
private static bool AreEqual(string[] a, string[] b)
|
|
@@ -2,15 +2,23 @@
|
|
|
2
2
|
{
|
|
3
3
|
#if UNITY_EDITOR
|
|
4
4
|
using System;
|
|
5
|
+
using System.Collections.Generic;
|
|
5
6
|
using System.Reflection;
|
|
6
7
|
using Extensions;
|
|
7
8
|
using UnityEditor;
|
|
8
9
|
using UnityEngine;
|
|
9
10
|
using Core.Attributes;
|
|
11
|
+
using Core.Extension;
|
|
12
|
+
using Core.Helper;
|
|
10
13
|
|
|
11
14
|
[CustomPropertyDrawer(typeof(WShowIfAttribute))]
|
|
12
15
|
public sealed class WShowIfPropertyDrawer : PropertyDrawer
|
|
13
16
|
{
|
|
17
|
+
private static readonly Dictionary<
|
|
18
|
+
Type,
|
|
19
|
+
Dictionary<string, Func<object, object>>
|
|
20
|
+
> CachedFields = new();
|
|
21
|
+
|
|
14
22
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
15
23
|
{
|
|
16
24
|
return !ShouldShow(property) ? 0f : EditorGUI.GetPropertyHeight(property, label, true);
|
|
@@ -43,13 +51,38 @@
|
|
|
43
51
|
|
|
44
52
|
// This might not be a unity object, so fall back to reflection
|
|
45
53
|
object enclosingObject = property.GetEnclosingObject(out _);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
if (enclosingObject == null)
|
|
55
|
+
{
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Type type = enclosingObject.GetType();
|
|
60
|
+
Dictionary<string, Func<object, object>> cachedFields = CachedFields.GetOrAdd(type);
|
|
61
|
+
if (
|
|
62
|
+
!cachedFields.TryGetValue(
|
|
63
|
+
showIf.conditionField,
|
|
64
|
+
out Func<object, object> accessor
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
{
|
|
68
|
+
FieldInfo field = type.GetField(
|
|
49
69
|
showIf.conditionField,
|
|
50
70
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
51
71
|
);
|
|
52
|
-
|
|
72
|
+
if (field == null)
|
|
73
|
+
{
|
|
74
|
+
Debug.LogError(
|
|
75
|
+
$"Failed to find conditional field {showIf.conditionField} on {type.Name}!"
|
|
76
|
+
);
|
|
77
|
+
accessor = _ => null;
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
{
|
|
81
|
+
accessor = ReflectionHelpers.GetFieldGetter(field);
|
|
82
|
+
}
|
|
83
|
+
cachedFields[showIf.conditionField] = accessor;
|
|
84
|
+
}
|
|
85
|
+
object fieldValue = accessor(enclosingObject);
|
|
53
86
|
if (fieldValue is bool maybeCondition)
|
|
54
87
|
{
|
|
55
88
|
return showIf.inverse ? !maybeCondition : maybeCondition;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
using UnityEngine;
|
|
7
7
|
using UnityEditor;
|
|
8
8
|
using System.Collections.Generic;
|
|
9
|
+
using Core.Extension;
|
|
9
10
|
using Core.Helper;
|
|
10
11
|
|
|
11
12
|
[CustomPropertyDrawer(typeof(SourceFolderEntry))]
|
|
@@ -324,8 +325,8 @@
|
|
|
324
325
|
nameof(SourceFolderEntry.selectionMode)
|
|
325
326
|
);
|
|
326
327
|
SpriteSelectionMode modeValue = (SpriteSelectionMode)modeProp.intValue;
|
|
327
|
-
bool useRegex = (
|
|
328
|
-
bool useLabels = (
|
|
328
|
+
bool useRegex = modeValue.HasFlagNoAlloc(SpriteSelectionMode.Regex);
|
|
329
|
+
bool useLabels = modeValue.HasFlagNoAlloc(SpriteSelectionMode.Labels);
|
|
329
330
|
|
|
330
331
|
if (useRegex)
|
|
331
332
|
{
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
if (string.Equals(fieldName, "Array", StringComparison.Ordinal))
|
|
47
47
|
{
|
|
48
48
|
// Move to "data[i]", no need to length-check, we're guarded above
|
|
49
|
-
|
|
50
49
|
++i;
|
|
50
|
+
fieldName = pathParts[i];
|
|
51
51
|
if (
|
|
52
52
|
!int.TryParse(
|
|
53
|
-
|
|
53
|
+
fieldName
|
|
54
54
|
.Replace("data[", string.Empty, StringComparison.Ordinal)
|
|
55
55
|
.Replace("]", string.Empty, StringComparison.Ordinal),
|
|
56
56
|
out int index
|
|
@@ -61,15 +61,20 @@
|
|
|
61
61
|
fieldInfo = null;
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
|
+
|
|
64
65
|
obj = GetElementAtIndex(obj, index);
|
|
65
66
|
type = obj?.GetType();
|
|
67
|
+
UpdateField(fieldName, ref fieldInfo);
|
|
68
|
+
|
|
69
|
+
if (i == pathParts.Length - 2)
|
|
70
|
+
{
|
|
71
|
+
fieldName = pathParts[i + 1];
|
|
72
|
+
UpdateField(fieldName, ref fieldInfo);
|
|
73
|
+
}
|
|
66
74
|
continue;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
fieldName,
|
|
71
|
-
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance
|
|
72
|
-
);
|
|
77
|
+
UpdateField(fieldName, ref fieldInfo);
|
|
73
78
|
if (fieldInfo == null)
|
|
74
79
|
{
|
|
75
80
|
return null;
|
|
@@ -83,7 +88,24 @@
|
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
|
|
91
|
+
if (fieldInfo == null)
|
|
92
|
+
{
|
|
93
|
+
UpdateField(property.name, ref fieldInfo);
|
|
94
|
+
}
|
|
95
|
+
|
|
86
96
|
return obj;
|
|
97
|
+
|
|
98
|
+
void UpdateField(string fieldName, ref FieldInfo field)
|
|
99
|
+
{
|
|
100
|
+
FieldInfo newField = type?.GetField(
|
|
101
|
+
fieldName,
|
|
102
|
+
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance
|
|
103
|
+
);
|
|
104
|
+
if (newField != null)
|
|
105
|
+
{
|
|
106
|
+
field = newField;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
87
109
|
}
|
|
88
110
|
|
|
89
111
|
/// <summary>
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
{
|
|
48
48
|
SpriteSelectionMode.Regex,
|
|
49
49
|
SpriteSelectionMode.Regex | SpriteSelectionMode.Labels,
|
|
50
|
+
(SpriteSelectionMode)(-1),
|
|
50
51
|
}
|
|
51
52
|
)]
|
|
52
53
|
[Tooltip(
|
|
@@ -87,14 +88,6 @@
|
|
|
87
88
|
[Tooltip("Asset labels to include in the folders.")]
|
|
88
89
|
[StringInList(typeof(Helpers), nameof(Helpers.GetAllSpriteLabelNames))]
|
|
89
90
|
public List<string> labels = new();
|
|
90
|
-
|
|
91
|
-
public SourceFolderEntry() { }
|
|
92
|
-
|
|
93
|
-
public SourceFolderEntry(string path)
|
|
94
|
-
{
|
|
95
|
-
folderPath = path;
|
|
96
|
-
regexes = new List<string>();
|
|
97
|
-
}
|
|
98
91
|
}
|
|
99
92
|
|
|
100
93
|
[CreateAssetMenu(
|
|
@@ -501,6 +501,7 @@
|
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
503
|
|
|
504
|
+
bool allMatch = matchesAllRegexesInEntry;
|
|
504
505
|
bool matchesAllTagsInEntry = true;
|
|
505
506
|
if (
|
|
506
507
|
entry.selectionMode.HasFlagNoAlloc(SpriteSelectionMode.Labels)
|
|
@@ -537,28 +538,27 @@
|
|
|
537
538
|
}
|
|
538
539
|
}
|
|
539
540
|
}
|
|
540
|
-
}
|
|
541
541
|
|
|
542
|
-
|
|
543
|
-
switch (entry.regexAndTagLogic)
|
|
544
|
-
{
|
|
545
|
-
case SpriteSelectionBooleanLogic.And:
|
|
546
|
-
{
|
|
547
|
-
allMatch = matchesAllRegexesInEntry && matchesAllTagsInEntry;
|
|
548
|
-
break;
|
|
549
|
-
}
|
|
550
|
-
case SpriteSelectionBooleanLogic.Or:
|
|
542
|
+
switch (entry.regexAndTagLogic)
|
|
551
543
|
{
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
544
|
+
case SpriteSelectionBooleanLogic.And:
|
|
545
|
+
{
|
|
546
|
+
allMatch = matchesAllRegexesInEntry && matchesAllTagsInEntry;
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
case SpriteSelectionBooleanLogic.Or:
|
|
550
|
+
{
|
|
551
|
+
allMatch = matchesAllRegexesInEntry || matchesAllTagsInEntry;
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
default:
|
|
555
|
+
{
|
|
556
|
+
throw new InvalidEnumArgumentException(
|
|
557
|
+
nameof(entry.regexAndTagLogic),
|
|
558
|
+
(int)entry.regexAndTagLogic,
|
|
559
|
+
typeof(SpriteSelectionBooleanLogic)
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
564
|
|
|
@@ -635,6 +635,8 @@
|
|
|
635
635
|
if (addedCount > 0)
|
|
636
636
|
{
|
|
637
637
|
so.ApplyModifiedProperties();
|
|
638
|
+
config.spritesToPack.SortByName();
|
|
639
|
+
EditorUtility.SetDirty(config);
|
|
638
640
|
this.Log($"'{config.name}': Added {addedCount} sprites.");
|
|
639
641
|
}
|
|
640
642
|
else
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
StringComparer.Ordinal
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
+
internal static readonly Dictionary<string, string[]> CachedLabels = new(
|
|
28
|
+
StringComparer.OrdinalIgnoreCase
|
|
29
|
+
);
|
|
30
|
+
|
|
27
31
|
internal static string[] AllSpriteLabels;
|
|
28
32
|
|
|
29
33
|
public static string[] GetAllSpriteLabelNames()
|
|
@@ -45,7 +49,9 @@
|
|
|
45
49
|
continue;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
string[] labels = AssetDatabase.GetLabels(asset);
|
|
53
|
+
CachedLabels[path] = labels;
|
|
54
|
+
allLabels.UnionWith(labels);
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
AllSpriteLabels = allLabels.ToArray();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.wallstop-studios.unity-helpers",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc77",
|
|
4
4
|
"displayName": "Unity Helpers",
|
|
5
5
|
"description": "Various Unity Helper Library",
|
|
6
6
|
"dependencies": {},
|
|
@@ -81,6 +81,8 @@
|
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
|
|
84
|
+
|
|
85
|
+
|
|
84
86
|
|
|
85
87
|
|
|
86
88
|
|