com.wallstop-studios.unity-helpers 2.0.0-rc80.2 → 2.0.0-rc80.3

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.
@@ -0,0 +1,15 @@
1
+ namespace WallstopStudios.UnityHelpers.Core.Attributes
2
+ {
3
+ using System;
4
+
5
+ [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
6
+ public sealed class ScriptableSingletonPathAttribute : Attribute
7
+ {
8
+ public readonly string resourcesPath;
9
+
10
+ public ScriptableSingletonPathAttribute(string resourcesPath)
11
+ {
12
+ this.resourcesPath = resourcesPath ?? string.Empty;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: f6e7e461ef354d009ce229352104d4db
3
+ timeCreated: 1758580433
@@ -2,6 +2,8 @@ namespace WallstopStudios.UnityHelpers.Utils
2
2
  {
3
3
  using System;
4
4
  using UnityEngine;
5
+ using WallstopStudios.UnityHelpers.Core.Attributes;
6
+ using WallstopStudios.UnityHelpers.Core.Helper;
5
7
  #if ODIN_INSPECTOR
6
8
  using Sirenix.OdinInspector;
7
9
  #endif
@@ -14,9 +16,46 @@ namespace WallstopStudios.UnityHelpers.Utils
14
16
  #endif
15
17
  where T : ScriptableObjectSingleton<T>
16
18
  {
19
+ private static string GetResourcesPath()
20
+ {
21
+ Type type = typeof(T);
22
+ ScriptableSingletonPathAttribute attribute =
23
+ ReflectionHelpers.GetAttributeSafe<ScriptableSingletonPathAttribute>(type);
24
+ if (attribute != null && !string.IsNullOrWhiteSpace(attribute.resourcesPath))
25
+ {
26
+ return attribute.resourcesPath;
27
+ }
28
+
29
+ return type.Name;
30
+ }
31
+
17
32
  protected static readonly Lazy<T> LazyInstance = new(() =>
18
33
  {
19
- T[] instances = Resources.LoadAll<T>(string.Empty);
34
+ string path = GetResourcesPath();
35
+ T[] instances = Resources.LoadAll<T>(path);
36
+
37
+ if (instances == null || instances.Length == 0)
38
+ {
39
+ T named = Resources.Load<T>(typeof(T).Name);
40
+ if (named != null)
41
+ {
42
+ instances = new[] { named };
43
+ }
44
+ }
45
+
46
+ if (instances == null || instances.Length == 0)
47
+ {
48
+ instances = Resources.LoadAll<T>(string.Empty);
49
+ }
50
+
51
+ if (instances == null)
52
+ {
53
+ Debug.LogError(
54
+ $"Failed to find ScriptableSingleton of {typeof(T).Name} - null instances."
55
+ );
56
+ return default;
57
+ }
58
+
20
59
  switch (instances.Length)
21
60
  {
22
61
  case 1:
@@ -25,7 +64,9 @@ namespace WallstopStudios.UnityHelpers.Utils
25
64
  }
26
65
  case 0:
27
66
  {
28
- Debug.LogError($"Failed to find ScriptableSingleton of type {typeof(T).Name}.");
67
+ Debug.LogError(
68
+ $"Failed to find ScriptableSingleton of type {typeof(T).Name} - empty instances."
69
+ );
29
70
  return null;
30
71
  }
31
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc80.2",
3
+ "version": "2.0.0-rc80.3",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -55,4 +55,5 @@
55
55
 
56
56
 
57
57
 
58
+
58
59