com.wallstop-studios.unity-helpers 2.0.0-rc80.2 → 2.0.0-rc80.4
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
|
+
}
|
|
@@ -56,7 +56,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
56
56
|
{
|
|
57
57
|
if (ObjectsByTag.TryGetValue(tag, out Object value))
|
|
58
58
|
{
|
|
59
|
-
if (value
|
|
59
|
+
if (value is T typed && typed != null)
|
|
60
60
|
{
|
|
61
61
|
return typed;
|
|
62
62
|
}
|
|
@@ -166,7 +166,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
166
166
|
for (int i = 0; i < transform.childCount; ++i)
|
|
167
167
|
{
|
|
168
168
|
Transform child = transform.GetChild(i);
|
|
169
|
-
EnableRecursively
|
|
169
|
+
EnableRecursively(child, enabled, exclude);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
@@ -188,10 +188,14 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
188
188
|
behavior.enabled = enabled;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
Transform transform = component as Transform
|
|
191
|
+
Transform transform = component as Transform;
|
|
192
192
|
if (transform == null)
|
|
193
193
|
{
|
|
194
|
-
|
|
194
|
+
transform = component.transform;
|
|
195
|
+
if (transform == null)
|
|
196
|
+
{
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
195
199
|
}
|
|
196
200
|
|
|
197
201
|
for (int i = 0; i < transform.childCount; ++i)
|
|
@@ -280,7 +284,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
280
284
|
}
|
|
281
285
|
|
|
282
286
|
public static void DestroyAllChildrenGameObjectsImmediately(this GameObject gameObject) =>
|
|
283
|
-
InternalDestroyAllChildrenGameObjects(gameObject, Object.DestroyImmediate);
|
|
287
|
+
InternalDestroyAllChildrenGameObjects(gameObject, go => Object.DestroyImmediate(go));
|
|
284
288
|
|
|
285
289
|
public static void PlayDestroyAllChildrenGameObjects(this GameObject gameObject) =>
|
|
286
290
|
InternalDestroyAllChildrenGameObjects(gameObject, go => go.Destroy());
|
|
@@ -301,9 +305,17 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
301
305
|
|
|
302
306
|
public static bool IsPrefab(this GameObject gameObject)
|
|
303
307
|
{
|
|
308
|
+
if (gameObject == null)
|
|
309
|
+
{
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
|
|
304
313
|
Scene scene = gameObject.scene;
|
|
305
314
|
#if UNITY_EDITOR
|
|
306
|
-
if (
|
|
315
|
+
if (
|
|
316
|
+
scene.rootCount == 1
|
|
317
|
+
&& string.Equals(scene.name, gameObject.name, StringComparison.Ordinal)
|
|
318
|
+
)
|
|
307
319
|
{
|
|
308
320
|
return true;
|
|
309
321
|
}
|
|
@@ -321,6 +333,11 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
321
333
|
|
|
322
334
|
public static bool IsPrefab(this Component component)
|
|
323
335
|
{
|
|
336
|
+
if (component == null)
|
|
337
|
+
{
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
|
|
324
341
|
return IsPrefab(component.gameObject);
|
|
325
342
|
}
|
|
326
343
|
|
|
@@ -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
|
-
|
|
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(
|
|
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.
|
|
3
|
+
"version": "2.0.0-rc80.4",
|
|
4
4
|
"displayName": "Unity Helpers",
|
|
5
5
|
"description": "Various Unity Helper Library",
|
|
6
6
|
"dependencies": {},
|
|
@@ -54,5 +54,7 @@
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
|
|
57
|
+
|
|
58
|
+
|
|
57
59
|
|
|
58
60
|
|