com.wallstop-studios.unity-helpers 2.0.0-rc76.6 → 2.0.0-rc76.8

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.
@@ -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(string conditionField, bool inverse = false)
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
  }
@@ -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
- List = list;
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
- List = method.Invoke(null, null) as string[];
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 { get; private set; }
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc76.6",
3
+ "version": "2.0.0-rc76.8",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -79,6 +79,8 @@
79
79
 
80
80
 
81
81
 
82
+
83
+
82
84
 
83
85
 
84
86