com.wallstop-studios.unity-helpers 2.0.0-rc81.3 → 2.0.0-rc81.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.
package/Editor/PrefabChecker.cs
CHANGED
|
@@ -24,7 +24,7 @@ namespace WallstopStudios.UnityHelpers.Editor
|
|
|
24
24
|
private static readonly Dictionary<Type, List<FieldInfo>> ListFieldsByType = new();
|
|
25
25
|
private static readonly Dictionary<Type, List<FieldInfo>> StringFieldsByType = new();
|
|
26
26
|
private static readonly Dictionary<Type, List<FieldInfo>> ObjectFieldsByType = new();
|
|
27
|
-
private static readonly Dictionary<Type,
|
|
27
|
+
private static readonly Dictionary<Type, RequireComponent[]> RequiredComponentsByType =
|
|
28
28
|
new();
|
|
29
29
|
|
|
30
30
|
private readonly List<string> _assetPaths = new();
|
|
@@ -486,33 +486,59 @@ namespace WallstopStudios.UnityHelpers.Editor
|
|
|
486
486
|
List<MonoBehaviour> buffer
|
|
487
487
|
)
|
|
488
488
|
{
|
|
489
|
-
Transform
|
|
490
|
-
|
|
489
|
+
using PooledResource<List<Transform>> transformBufferResource =
|
|
490
|
+
Buffers<Transform>.List.Get();
|
|
491
|
+
List<Transform> transforms = transformBufferResource.resource;
|
|
492
|
+
prefabRoot.GetComponentsInChildren(true, transforms);
|
|
493
|
+
foreach (Transform transform in transforms)
|
|
491
494
|
{
|
|
492
|
-
MonoBehaviour
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
using PooledResource<List<MonoBehaviour>> componentBuffer =
|
|
496
|
+
Buffers<MonoBehaviour>.List.Get();
|
|
497
|
+
List<MonoBehaviour> components = componentBuffer.resource;
|
|
498
|
+
transform.GetComponents(components);
|
|
499
|
+
int bufferCount = 0;
|
|
500
|
+
foreach (MonoBehaviour c in components)
|
|
501
|
+
{
|
|
502
|
+
if (c != null && c.gameObject == transform.gameObject)
|
|
503
|
+
{
|
|
504
|
+
++bufferCount;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (components.Count == bufferCount)
|
|
497
508
|
{
|
|
498
509
|
continue;
|
|
499
510
|
}
|
|
500
511
|
|
|
501
|
-
bool foundInNonNullBuffer =
|
|
512
|
+
bool foundInNonNullBuffer = false;
|
|
513
|
+
foreach (MonoBehaviour c in components)
|
|
514
|
+
{
|
|
515
|
+
if (buffer.Contains(c))
|
|
516
|
+
{
|
|
517
|
+
foundInNonNullBuffer = true;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
502
522
|
if (foundInNonNullBuffer)
|
|
503
523
|
{
|
|
504
524
|
return transform.gameObject;
|
|
505
525
|
}
|
|
506
526
|
|
|
507
|
-
if (components.
|
|
527
|
+
if (components.Count != 0 || !buffer.Exists(c => c == null))
|
|
508
528
|
{
|
|
509
529
|
continue;
|
|
510
530
|
}
|
|
511
531
|
|
|
512
|
-
HashSet<GameObject
|
|
513
|
-
.
|
|
514
|
-
|
|
515
|
-
|
|
532
|
+
using PooledResource<HashSet<GameObject>> setResource =
|
|
533
|
+
Buffers<GameObject>.HashSet.Get();
|
|
534
|
+
HashSet<GameObject> gameObjectsWithComponentsInBuffer = setResource.resource;
|
|
535
|
+
foreach (MonoBehaviour c in buffer)
|
|
536
|
+
{
|
|
537
|
+
if (c != null)
|
|
538
|
+
{
|
|
539
|
+
gameObjectsWithComponentsInBuffer.Add(c.gameObject);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
516
542
|
if (!gameObjectsWithComponentsInBuffer.Contains(transform.gameObject))
|
|
517
543
|
{
|
|
518
544
|
return transform.gameObject;
|
|
@@ -535,7 +561,7 @@ namespace WallstopStudios.UnityHelpers.Editor
|
|
|
535
561
|
)
|
|
536
562
|
.Where(field =>
|
|
537
563
|
field.IsPublic
|
|
538
|
-
|| field.
|
|
564
|
+
|| field.IsAttributeDefined<SerializeField>(out _, inherit: true)
|
|
539
565
|
)
|
|
540
566
|
.ToList()
|
|
541
567
|
);
|
|
@@ -597,15 +623,12 @@ namespace WallstopStudios.UnityHelpers.Editor
|
|
|
597
623
|
int issueCount = 0;
|
|
598
624
|
Type componentType = component.GetType();
|
|
599
625
|
|
|
600
|
-
|
|
626
|
+
RequireComponent[] required = RequiredComponentsByType.GetOrAdd(
|
|
601
627
|
componentType,
|
|
602
|
-
type =>
|
|
603
|
-
type.GetCustomAttributes(typeof(RequireComponent), true)
|
|
604
|
-
.Cast<RequireComponent>()
|
|
605
|
-
.ToList()
|
|
628
|
+
type => type.GetAllAttributesSafe<RequireComponent>(inherit: true)
|
|
606
629
|
);
|
|
607
630
|
|
|
608
|
-
if (required.
|
|
631
|
+
if (required.Length <= 0)
|
|
609
632
|
{
|
|
610
633
|
return issueCount;
|
|
611
634
|
}
|
|
@@ -688,9 +711,10 @@ namespace WallstopStudios.UnityHelpers.Editor
|
|
|
688
711
|
)
|
|
689
712
|
)
|
|
690
713
|
{
|
|
691
|
-
bool hasValidateAttribute = field
|
|
692
|
-
|
|
693
|
-
|
|
714
|
+
bool hasValidateAttribute = field.IsAttributeDefined<ValidateAssignmentAttribute>(
|
|
715
|
+
out _,
|
|
716
|
+
inherit: true
|
|
717
|
+
);
|
|
694
718
|
|
|
695
719
|
if (_onlyCheckNullObjectsWithAttribute && !hasValidateAttribute)
|
|
696
720
|
{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
2
2
|
{
|
|
3
|
+
using System;
|
|
3
4
|
using System.Collections.Generic;
|
|
4
5
|
using System.Text;
|
|
5
6
|
using System.Threading;
|
|
@@ -36,6 +37,10 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
36
37
|
|
|
37
38
|
public static byte[] GetBytes(this string input)
|
|
38
39
|
{
|
|
40
|
+
if (string.IsNullOrEmpty(input))
|
|
41
|
+
{
|
|
42
|
+
return Array.Empty<byte>();
|
|
43
|
+
}
|
|
39
44
|
return Encoding.Default.GetBytes(input);
|
|
40
45
|
}
|
|
41
46
|
|
|
@@ -99,6 +104,11 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
99
104
|
|
|
100
105
|
public static string ToPascalCase(this string value, string separator = "")
|
|
101
106
|
{
|
|
107
|
+
if (string.IsNullOrEmpty(value))
|
|
108
|
+
{
|
|
109
|
+
return string.Empty;
|
|
110
|
+
}
|
|
111
|
+
|
|
102
112
|
int startIndex = 0;
|
|
103
113
|
StringBuilder stringBuilder = StringBuilderCache.Value;
|
|
104
114
|
stringBuilder.Clear();
|
|
@@ -2,6 +2,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
4
|
using System.Collections;
|
|
5
|
+
using System.Collections.Concurrent;
|
|
5
6
|
using System.Collections.Generic;
|
|
6
7
|
using System.Linq;
|
|
7
8
|
using System.Reflection;
|
|
@@ -18,7 +19,11 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
18
19
|
public static partial class Helpers
|
|
19
20
|
{
|
|
20
21
|
private static readonly WaitForEndOfFrame WaitForEndOfFrame = new();
|
|
22
|
+
#if SINGLE_THREADED
|
|
21
23
|
private static readonly Dictionary<Type, MethodInfo> AwakeMethodsByType = new();
|
|
24
|
+
#else
|
|
25
|
+
private static readonly ConcurrentDictionary<Type, MethodInfo> AwakeMethodsByType = new();
|
|
26
|
+
#endif
|
|
22
27
|
private static readonly Object LogObject = new();
|
|
23
28
|
private static readonly Dictionary<string, Object> ObjectsByTag = new(
|
|
24
29
|
StringComparer.Ordinal
|
|
@@ -221,10 +226,23 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
221
226
|
|
|
222
227
|
public static GameObject FindChildGameObjectWithTag(this GameObject gameObject, string tag)
|
|
223
228
|
{
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
229
|
+
using PooledResource<List<Transform>> bufferResource = Buffers<Transform>.List.Get();
|
|
230
|
+
foreach (
|
|
231
|
+
Transform t in gameObject.transform.IterateOverAllChildrenRecursively(
|
|
232
|
+
bufferResource.resource,
|
|
233
|
+
includeSelf: true
|
|
234
|
+
)
|
|
235
|
+
)
|
|
236
|
+
{
|
|
237
|
+
GameObject go = t.gameObject;
|
|
238
|
+
|
|
239
|
+
if (go.CompareTag(tag))
|
|
240
|
+
{
|
|
241
|
+
return go;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return null;
|
|
228
246
|
}
|
|
229
247
|
|
|
230
248
|
public static Coroutine StartFunctionAsCoroutine(
|
|
@@ -548,10 +566,22 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
548
566
|
string tag
|
|
549
567
|
)
|
|
550
568
|
{
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
569
|
+
using PooledResource<List<Transform>> bufferResource = Buffers<Transform>.List.Get();
|
|
570
|
+
foreach (
|
|
571
|
+
Transform t in gameObject.transform.IterateOverAllChildrenRecursively(
|
|
572
|
+
bufferResource.resource,
|
|
573
|
+
includeSelf: true
|
|
574
|
+
)
|
|
575
|
+
)
|
|
576
|
+
{
|
|
577
|
+
GameObject go = t.gameObject;
|
|
578
|
+
if (go.CompareTag(tag))
|
|
579
|
+
{
|
|
580
|
+
return go;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
return null;
|
|
555
585
|
}
|
|
556
586
|
|
|
557
587
|
//https://answers.unity.com/questions/722748/refreshing-the-polygon-collider-2d-upon-sprite-cha.html
|
|
@@ -559,7 +589,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
559
589
|
{
|
|
560
590
|
if (
|
|
561
591
|
!component.TryGetComponent(out SpriteRenderer spriteRenderer)
|
|
562
|
-
|| component.TryGetComponent(out PolygonCollider2D collider)
|
|
592
|
+
|| !component.TryGetComponent(out PolygonCollider2D collider)
|
|
563
593
|
)
|
|
564
594
|
{
|
|
565
595
|
return;
|
|
@@ -577,7 +607,8 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
577
607
|
|
|
578
608
|
int pathCount = collider.pathCount = sprite.GetPhysicsShapeCount();
|
|
579
609
|
|
|
580
|
-
List<Vector2
|
|
610
|
+
using PooledResource<List<Vector2>> pathResource = Buffers<Vector2>.List.Get();
|
|
611
|
+
List<Vector2> path = pathResource.resource;
|
|
581
612
|
for (int i = 0; i < pathCount; ++i)
|
|
582
613
|
{
|
|
583
614
|
path.Clear();
|
|
@@ -712,15 +743,32 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
712
743
|
|
|
713
744
|
public static void AwakeObject(this GameObject gameObject)
|
|
714
745
|
{
|
|
715
|
-
|
|
746
|
+
using PooledResource<List<MonoBehaviour>> componentResource =
|
|
747
|
+
Buffers<MonoBehaviour>.List.Get();
|
|
748
|
+
List<MonoBehaviour> components = componentResource.resource;
|
|
749
|
+
gameObject.GetComponentsInChildren(false, components);
|
|
750
|
+
foreach (MonoBehaviour script in components)
|
|
716
751
|
{
|
|
717
752
|
MethodInfo awakeInfo = AwakeMethodsByType.GetOrAdd(
|
|
718
753
|
script.GetType(),
|
|
719
754
|
type =>
|
|
720
|
-
|
|
721
|
-
|
|
755
|
+
{
|
|
756
|
+
MethodInfo[] methods = type.GetMethods(
|
|
722
757
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
723
|
-
)
|
|
758
|
+
);
|
|
759
|
+
foreach (MethodInfo method in methods)
|
|
760
|
+
{
|
|
761
|
+
if (
|
|
762
|
+
string.Equals(method.Name, "Awake", StringComparison.Ordinal)
|
|
763
|
+
&& method.GetParameters().Length == 0
|
|
764
|
+
)
|
|
765
|
+
{
|
|
766
|
+
return method;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
724
772
|
);
|
|
725
773
|
if (awakeInfo != null)
|
|
726
774
|
{
|
|
@@ -53,8 +53,16 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
53
53
|
yield break;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
List<T
|
|
57
|
-
|
|
56
|
+
using PooledResource<List<T>> bufferResource = Buffers<T>.List.Get();
|
|
57
|
+
List<T> buffer = bufferResource.resource;
|
|
58
|
+
using PooledResource<List<Transform>> transformResource = Buffers<Transform>.List.Get();
|
|
59
|
+
foreach (
|
|
60
|
+
Transform parent in IterateOverAllParents(
|
|
61
|
+
component,
|
|
62
|
+
transformResource.resource,
|
|
63
|
+
includeSelf
|
|
64
|
+
)
|
|
65
|
+
)
|
|
58
66
|
{
|
|
59
67
|
parent.GetComponents(buffer);
|
|
60
68
|
foreach (T c in buffer)
|
|
@@ -111,7 +119,8 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
111
119
|
yield break;
|
|
112
120
|
}
|
|
113
121
|
|
|
114
|
-
List<T
|
|
122
|
+
using PooledResource<List<T>> bufferResource = Buffers<T>.List.Get();
|
|
123
|
+
List<T> buffer = bufferResource.resource;
|
|
115
124
|
if (includeSelf)
|
|
116
125
|
{
|
|
117
126
|
component.GetComponents(buffer);
|
|
@@ -249,11 +258,13 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
249
258
|
yield return transform;
|
|
250
259
|
}
|
|
251
260
|
|
|
261
|
+
using PooledResource<List<Transform>> transformResource = Buffers<Transform>.List.Get();
|
|
252
262
|
for (int i = 0; i < transform.childCount; ++i)
|
|
253
263
|
{
|
|
254
264
|
foreach (
|
|
255
265
|
Transform child in IterateOverAllChildrenRecursively(
|
|
256
266
|
transform.GetChild(i),
|
|
267
|
+
transformResource.resource,
|
|
257
268
|
includeSelf: true
|
|
258
269
|
)
|
|
259
270
|
)
|
|
@@ -315,7 +326,8 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
315
326
|
yield return transform;
|
|
316
327
|
}
|
|
317
328
|
|
|
318
|
-
Queue<Transform
|
|
329
|
+
using PooledResource<Queue<Transform>> queueResource = Buffers<Transform>.Queue.Get();
|
|
330
|
+
Queue<Transform> iteration = queueResource.resource;
|
|
319
331
|
iteration.Enqueue(transform);
|
|
320
332
|
while (iteration.TryDequeue(out Transform current))
|
|
321
333
|
{
|
|
@@ -1116,7 +1116,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
1116
1116
|
}
|
|
1117
1117
|
|
|
1118
1118
|
public static TAttribute[] GetAllAttributesSafe<TAttribute>(
|
|
1119
|
-
ICustomAttributeProvider provider,
|
|
1119
|
+
this ICustomAttributeProvider provider,
|
|
1120
1120
|
bool inherit = true
|
|
1121
1121
|
)
|
|
1122
1122
|
where TAttribute : Attribute
|
|
@@ -1144,7 +1144,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
1144
1144
|
}
|
|
1145
1145
|
|
|
1146
1146
|
public static Attribute[] GetAllAttributesSafe(
|
|
1147
|
-
ICustomAttributeProvider provider,
|
|
1147
|
+
this ICustomAttributeProvider provider,
|
|
1148
1148
|
bool inherit = true
|
|
1149
1149
|
)
|
|
1150
1150
|
{
|
|
@@ -1164,7 +1164,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
1164
1164
|
}
|
|
1165
1165
|
|
|
1166
1166
|
public static Attribute[] GetAllAttributesSafe(
|
|
1167
|
-
ICustomAttributeProvider provider,
|
|
1167
|
+
this ICustomAttributeProvider provider,
|
|
1168
1168
|
Type attributeType,
|
|
1169
1169
|
bool inherit = true
|
|
1170
1170
|
)
|
|
@@ -1192,7 +1192,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
1192
1192
|
}
|
|
1193
1193
|
|
|
1194
1194
|
public static Dictionary<string, object> GetAllAttributeValuesSafe(
|
|
1195
|
-
ICustomAttributeProvider provider,
|
|
1195
|
+
this ICustomAttributeProvider provider,
|
|
1196
1196
|
bool inherit = true
|
|
1197
1197
|
)
|
|
1198
1198
|
{
|
|
@@ -1222,7 +1222,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
1222
1222
|
}
|
|
1223
1223
|
|
|
1224
1224
|
public static MethodInfo[] GetMethodsWithAttributeSafe<TAttribute>(
|
|
1225
|
-
Type type,
|
|
1225
|
+
this Type type,
|
|
1226
1226
|
bool inherit = true
|
|
1227
1227
|
)
|
|
1228
1228
|
where TAttribute : Attribute
|
|
@@ -1251,7 +1251,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
1251
1251
|
}
|
|
1252
1252
|
|
|
1253
1253
|
public static PropertyInfo[] GetPropertiesWithAttributeSafe<TAttribute>(
|
|
1254
|
-
Type type,
|
|
1254
|
+
this Type type,
|
|
1255
1255
|
bool inherit = true
|
|
1256
1256
|
)
|
|
1257
1257
|
where TAttribute : Attribute
|
|
@@ -1280,7 +1280,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
1280
1280
|
}
|
|
1281
1281
|
|
|
1282
1282
|
public static FieldInfo[] GetFieldsWithAttributeSafe<TAttribute>(
|
|
1283
|
-
Type type,
|
|
1283
|
+
this Type type,
|
|
1284
1284
|
bool inherit = true
|
|
1285
1285
|
)
|
|
1286
1286
|
where TAttribute : Attribute
|