com.wallstop-studios.unity-helpers 2.0.0-rc80.7 → 2.0.0-rc80.9
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 +3 -1
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs +13 -6
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs +32 -23
- package/Runtime/Core/Attributes/ParentComponent.cs +8 -13
- package/Runtime/Core/Attributes/SiblingComponentAttribute.cs +22 -12
- package/Runtime/Core/DataStructure/KDTree.cs +15 -9
- package/Runtime/Core/DataStructure/QuadTree.cs +21 -7
- package/Runtime/Core/DataStructure/RTree.cs +15 -5
- package/Runtime/Core/Extension/UnityExtensions.cs +26 -12
- package/Runtime/Core/Extension/WallstopStudiosLogger.cs +52 -23
- package/Runtime/Core/Helper/FormattingHelpers.cs +2 -2
- package/Runtime/Core/Helper/Helpers.cs +0 -27
- package/Runtime/Core/Helper/Partials/TransformHelpers.cs +7 -4
- package/Runtime/Core/Helper/WallMath.cs +1 -1
- package/Runtime/Tags/EffectHandler.cs +41 -34
- package/Runtime/Utils/Buffers.cs +62 -46
- package/Runtime/Utils/MatchColliderToSprite.cs +2 -1
- package/Runtime/Utils/SpriteRendererMetadata.cs +16 -20
- package/package.json +1 -26
package/Editor/PrefabChecker.cs
CHANGED
|
@@ -401,7 +401,9 @@ namespace WallstopStudios.UnityHelpers.Editor
|
|
|
401
401
|
issuesForThisPrefab++;
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
List<MonoBehaviour
|
|
404
|
+
using PooledResource<List<MonoBehaviour>> componentBufferResource =
|
|
405
|
+
Buffers<MonoBehaviour>.List.Get();
|
|
406
|
+
List<MonoBehaviour> componentBuffer = componentBufferResource.resource;
|
|
405
407
|
prefab.GetComponentsInChildren(true, componentBuffer);
|
|
406
408
|
|
|
407
409
|
foreach (MonoBehaviour script in componentBuffer)
|
|
@@ -5,6 +5,8 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
5
5
|
using System.Linq;
|
|
6
6
|
using System.Reflection;
|
|
7
7
|
using UnityEngine;
|
|
8
|
+
using WallstopStudios.UnityHelpers.Core.Helper;
|
|
9
|
+
using WallstopStudios.UnityHelpers.Utils;
|
|
8
10
|
|
|
9
11
|
[AttributeUsage(AttributeTargets.Method)]
|
|
10
12
|
public sealed class AnimationEventAttribute : Attribute
|
|
@@ -48,11 +50,9 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
if (
|
|
51
|
-
definedMethod.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
)[0]
|
|
55
|
-
is AnimationEventAttribute { ignoreDerived: true }
|
|
53
|
+
definedMethod.IsAttributeDefined(
|
|
54
|
+
out AnimationEventAttribute attribute
|
|
55
|
+
) && attribute.ignoreDerived
|
|
56
56
|
)
|
|
57
57
|
{
|
|
58
58
|
ignoreDerived.Add((type, definedMethod.Name));
|
|
@@ -63,7 +63,14 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
63
63
|
}
|
|
64
64
|
);
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
using PooledResource<List<KeyValuePair<Type, List<MethodInfo>>>> methodBufferResource =
|
|
67
|
+
Buffers<KeyValuePair<Type, List<MethodInfo>>>.List.Get();
|
|
68
|
+
List<KeyValuePair<Type, List<MethodInfo>>> methodBuffer = methodBufferResource.resource;
|
|
69
|
+
foreach (KeyValuePair<Type, List<MethodInfo>> entry in typesToMethods)
|
|
70
|
+
{
|
|
71
|
+
methodBuffer.Add(entry);
|
|
72
|
+
}
|
|
73
|
+
foreach (KeyValuePair<Type, List<MethodInfo>> entry in methodBuffer)
|
|
67
74
|
{
|
|
68
75
|
if (entry.Value.Count <= 0)
|
|
69
76
|
{
|
|
@@ -9,6 +9,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
9
9
|
using Helper;
|
|
10
10
|
using JetBrains.Annotations;
|
|
11
11
|
using UnityEngine;
|
|
12
|
+
using WallstopStudios.UnityHelpers.Utils;
|
|
12
13
|
|
|
13
14
|
[AttributeUsage(AttributeTargets.Field)]
|
|
14
15
|
[MeansImplicitUse]
|
|
@@ -38,7 +39,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
38
39
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
39
40
|
);
|
|
40
41
|
return fields
|
|
41
|
-
.Where(field =>
|
|
42
|
+
.Where(field => field.IsAttributeDefined<ChildComponentAttribute>(out _))
|
|
42
43
|
.Select(field => (field, ReflectionHelpers.GetFieldSetter(field)))
|
|
43
44
|
.ToArray();
|
|
44
45
|
}
|
|
@@ -46,19 +47,24 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
46
47
|
|
|
47
48
|
foreach ((FieldInfo field, Action<object, object> setter) in fields)
|
|
48
49
|
{
|
|
50
|
+
if (!field.IsAttributeDefined(out ChildComponentAttribute customAttribute))
|
|
51
|
+
{
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
Type fieldType = field.FieldType;
|
|
50
56
|
bool isArray = fieldType.IsArray;
|
|
51
57
|
Type childComponentType = isArray ? fieldType.GetElementType() : fieldType;
|
|
52
|
-
|
|
53
58
|
bool foundChild;
|
|
54
|
-
ChildComponentAttribute customAttribute =
|
|
55
|
-
field.GetCustomAttribute<ChildComponentAttribute>();
|
|
56
59
|
if (customAttribute.onlyDescendents)
|
|
57
60
|
{
|
|
58
61
|
if (isArray)
|
|
59
62
|
{
|
|
60
63
|
ChildCache.Clear();
|
|
61
|
-
|
|
64
|
+
using PooledResource<List<Transform>> childBufferResource =
|
|
65
|
+
Buffers<Transform>.List.Get();
|
|
66
|
+
List<Transform> childBuffer = childBufferResource.resource;
|
|
67
|
+
foreach (Transform child in component.IterateOverAllChildren(childBuffer))
|
|
62
68
|
{
|
|
63
69
|
foreach (
|
|
64
70
|
Component childComponent in child.GetComponentsInChildren(
|
|
@@ -89,19 +95,21 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
89
95
|
|
|
90
96
|
IList instance = ReflectionHelpers.CreateList(childComponentType);
|
|
91
97
|
foundChild = false;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
child.GetComponentsInChildren(
|
|
97
|
-
childComponentType,
|
|
98
|
-
customAttribute.includeInactive
|
|
99
|
-
)
|
|
100
|
-
)
|
|
101
|
-
)
|
|
98
|
+
using PooledResource<List<Transform>> childBufferResource =
|
|
99
|
+
Buffers<Transform>.List.Get();
|
|
100
|
+
List<Transform> childBuffer = childBufferResource.resource;
|
|
101
|
+
foreach (Transform child in component.IterateOverAllChildren(childBuffer))
|
|
102
102
|
{
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
foreach (
|
|
104
|
+
Component childComponent in child.GetComponentsInChildren(
|
|
105
|
+
childComponentType,
|
|
106
|
+
customAttribute.includeInactive
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
{
|
|
110
|
+
instance.Add(childComponent);
|
|
111
|
+
foundChild = true;
|
|
112
|
+
}
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
setter(component, instance);
|
|
@@ -110,8 +118,13 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
110
118
|
{
|
|
111
119
|
foundChild = false;
|
|
112
120
|
Component childComponent = null;
|
|
121
|
+
using PooledResource<List<Transform>> childBufferResource =
|
|
122
|
+
Buffers<Transform>.List.Get();
|
|
123
|
+
List<Transform> childBuffer = childBufferResource.resource;
|
|
113
124
|
foreach (
|
|
114
|
-
Transform child in component.IterateOverAllChildrenRecursivelyBreadthFirst(
|
|
125
|
+
Transform child in component.IterateOverAllChildrenRecursivelyBreadthFirst(
|
|
126
|
+
childBuffer
|
|
127
|
+
)
|
|
115
128
|
)
|
|
116
129
|
{
|
|
117
130
|
childComponent = child.GetComponent(childComponentType);
|
|
@@ -199,11 +212,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
199
212
|
}
|
|
200
213
|
}
|
|
201
214
|
|
|
202
|
-
if (
|
|
203
|
-
!foundChild
|
|
204
|
-
&& field.GetCustomAttributes(typeof(ChildComponentAttribute), false)[0]
|
|
205
|
-
is ChildComponentAttribute { optional: false }
|
|
206
|
-
)
|
|
215
|
+
if (!foundChild && !customAttribute.optional)
|
|
207
216
|
{
|
|
208
217
|
component.LogError($"Unable to find child component of type {fieldType}");
|
|
209
218
|
}
|
|
@@ -37,9 +37,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
37
37
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
38
38
|
);
|
|
39
39
|
return fields
|
|
40
|
-
.Where(field =>
|
|
41
|
-
Attribute.IsDefined(field, typeof(ParentComponentAttribute))
|
|
42
|
-
)
|
|
40
|
+
.Where(field => field.IsAttributeDefined<ParentComponentAttribute>(out _))
|
|
43
41
|
.Select(field => (field, ReflectionHelpers.GetFieldSetter(field)))
|
|
44
42
|
.ToArray();
|
|
45
43
|
}
|
|
@@ -47,14 +45,16 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
47
45
|
|
|
48
46
|
foreach ((FieldInfo field, Action<object, object> setter) in fields)
|
|
49
47
|
{
|
|
48
|
+
if (!field.IsAttributeDefined(out ParentComponentAttribute customAttribute))
|
|
49
|
+
{
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
50
53
|
Type fieldType = field.FieldType;
|
|
51
54
|
bool isArray = fieldType.IsArray;
|
|
52
55
|
Type parentComponentType = isArray ? fieldType.GetElementType() : fieldType;
|
|
53
|
-
|
|
54
56
|
bool foundParent;
|
|
55
|
-
|
|
56
|
-
field.GetCustomAttribute<ParentComponentAttribute>();
|
|
57
|
-
if (field.GetCustomAttribute<ParentComponentAttribute>().onlyAncestors)
|
|
57
|
+
if (customAttribute.onlyAncestors)
|
|
58
58
|
{
|
|
59
59
|
Transform parent = component.transform.parent;
|
|
60
60
|
if (parent == null)
|
|
@@ -138,7 +138,6 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
138
138
|
)
|
|
139
139
|
{
|
|
140
140
|
parentComponentType = fieldType.GenericTypeArguments[0];
|
|
141
|
-
|
|
142
141
|
Component[] parents = component.GetComponentsInParent(
|
|
143
142
|
parentComponentType,
|
|
144
143
|
customAttribute.includeInactive
|
|
@@ -171,11 +170,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
171
170
|
}
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
if (
|
|
175
|
-
!foundParent
|
|
176
|
-
&& field.GetCustomAttributes(typeof(ParentComponentAttribute), false)[0]
|
|
177
|
-
is ParentComponentAttribute { optional: false }
|
|
178
|
-
)
|
|
173
|
+
if (!foundParent && !customAttribute.optional)
|
|
179
174
|
{
|
|
180
175
|
component.LogError($"Unable to find parent component of type {fieldType}");
|
|
181
176
|
}
|
|
@@ -9,6 +9,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
9
9
|
using Helper;
|
|
10
10
|
using JetBrains.Annotations;
|
|
11
11
|
using UnityEngine;
|
|
12
|
+
using WallstopStudios.UnityHelpers.Utils;
|
|
12
13
|
|
|
13
14
|
[AttributeUsage(AttributeTargets.Field)]
|
|
14
15
|
[MeansImplicitUse]
|
|
@@ -35,9 +36,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
35
36
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
36
37
|
);
|
|
37
38
|
return fields
|
|
38
|
-
.Where(field =>
|
|
39
|
-
Attribute.IsDefined(field, typeof(SiblingComponentAttribute))
|
|
40
|
-
)
|
|
39
|
+
.Where(field => field.IsAttributeDefined<SiblingComponentAttribute>(out _))
|
|
41
40
|
.Select(field => (field, ReflectionHelpers.GetFieldSetter(field)))
|
|
42
41
|
.ToArray();
|
|
43
42
|
}
|
|
@@ -52,14 +51,22 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
52
51
|
bool foundSibling;
|
|
53
52
|
if (isArray)
|
|
54
53
|
{
|
|
55
|
-
Component
|
|
56
|
-
|
|
54
|
+
using PooledResource<List<Component>> componentBufferResource =
|
|
55
|
+
Buffers<Component>.List.Get();
|
|
56
|
+
List<Component> siblingComponents = componentBufferResource.resource;
|
|
57
|
+
component.GetComponents(siblingComponentType, siblingComponents);
|
|
58
|
+
foundSibling = 0 < siblingComponents.Count;
|
|
57
59
|
|
|
58
60
|
Array correctTypedArray = ReflectionHelpers.CreateArray(
|
|
59
61
|
siblingComponentType,
|
|
60
|
-
siblingComponents.
|
|
62
|
+
siblingComponents.Count
|
|
61
63
|
);
|
|
62
|
-
|
|
64
|
+
for (int i = 0; i < siblingComponents.Count; i++)
|
|
65
|
+
{
|
|
66
|
+
Component siblingComponent = siblingComponents[i];
|
|
67
|
+
correctTypedArray.SetValue(siblingComponent, i);
|
|
68
|
+
}
|
|
69
|
+
|
|
63
70
|
setter(component, correctTypedArray);
|
|
64
71
|
}
|
|
65
72
|
else if (
|
|
@@ -69,15 +76,18 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
69
76
|
{
|
|
70
77
|
siblingComponentType = fieldType.GenericTypeArguments[0];
|
|
71
78
|
|
|
72
|
-
Component
|
|
79
|
+
using PooledResource<List<Component>> componentBufferResource =
|
|
80
|
+
Buffers<Component>.List.Get();
|
|
81
|
+
List<Component> siblingComponents = componentBufferResource.resource;
|
|
82
|
+
component.GetComponents(siblingComponentType, siblingComponents);
|
|
73
83
|
|
|
74
84
|
IList instance = ReflectionHelpers.CreateList(
|
|
75
85
|
siblingComponentType,
|
|
76
|
-
|
|
86
|
+
siblingComponents.Count
|
|
77
87
|
);
|
|
78
88
|
|
|
79
89
|
foundSibling = false;
|
|
80
|
-
foreach (Component siblingComponent in
|
|
90
|
+
foreach (Component siblingComponent in siblingComponents)
|
|
81
91
|
{
|
|
82
92
|
instance.Add(siblingComponent);
|
|
83
93
|
foundSibling = true;
|
|
@@ -105,8 +115,8 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
105
115
|
|
|
106
116
|
if (
|
|
107
117
|
!foundSibling
|
|
108
|
-
&& field.
|
|
109
|
-
|
|
118
|
+
&& field.IsAttributeDefined(out SiblingComponentAttribute customAttribute)
|
|
119
|
+
&& !customAttribute.optional
|
|
110
120
|
)
|
|
111
121
|
{
|
|
112
122
|
component.LogError($"Unable to find sibling component of type {fieldType}");
|
|
@@ -200,12 +200,12 @@ namespace WallstopStudios.UnityHelpers.Core.DataStructure
|
|
|
200
200
|
return elementsInRange;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
Stack<KDTreeNode
|
|
204
|
-
nodesToVisit.
|
|
203
|
+
using PooledResource<Stack<KDTreeNode>> stackResource = Buffers<KDTreeNode>.Stack.Get();
|
|
204
|
+
Stack<KDTreeNode> nodesToVisit = stackResource.resource;
|
|
205
205
|
nodesToVisit.Push(_head);
|
|
206
206
|
|
|
207
|
-
List<KDTreeNode
|
|
208
|
-
resultBuffer.
|
|
207
|
+
using PooledResource<List<KDTreeNode>> resultResource = Buffers<KDTreeNode>.List.Get();
|
|
208
|
+
List<KDTreeNode> resultBuffer = resultResource.resource;
|
|
209
209
|
|
|
210
210
|
while (nodesToVisit.TryPop(out KDTreeNode currentNode))
|
|
211
211
|
{
|
|
@@ -266,8 +266,8 @@ namespace WallstopStudios.UnityHelpers.Core.DataStructure
|
|
|
266
266
|
|
|
267
267
|
public List<T> GetElementsInBounds(Bounds bounds, List<T> elementsInBounds)
|
|
268
268
|
{
|
|
269
|
-
Stack<KDTreeNode
|
|
270
|
-
return GetElementsInBounds(bounds, elementsInBounds,
|
|
269
|
+
using PooledResource<Stack<KDTreeNode>> stackResource = Buffers<KDTreeNode>.Stack.Get();
|
|
270
|
+
return GetElementsInBounds(bounds, elementsInBounds, stackResource.resource);
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
public List<T> GetElementsInBounds(
|
|
@@ -333,9 +333,15 @@ namespace WallstopStudios.UnityHelpers.Core.DataStructure
|
|
|
333
333
|
List<T> nearestNeighbors
|
|
334
334
|
)
|
|
335
335
|
{
|
|
336
|
-
Stack<KDTreeNode
|
|
337
|
-
|
|
338
|
-
|
|
336
|
+
using PooledResource<Stack<KDTreeNode>> nodeBufferResource =
|
|
337
|
+
Buffers<KDTreeNode>.Stack.Get();
|
|
338
|
+
Stack<KDTreeNode> nodeBuffer = nodeBufferResource.resource;
|
|
339
|
+
using PooledResource<HashSet<T>> nearestNeighborBufferResource =
|
|
340
|
+
Buffers<T>.HashSet.Get();
|
|
341
|
+
HashSet<T> nearestNeighborBuffer = nearestNeighborBufferResource.resource;
|
|
342
|
+
using PooledResource<List<Entry>> nearestNeighborsCacheResource =
|
|
343
|
+
Buffers<Entry>.List.Get();
|
|
344
|
+
List<Entry> nearestNeighborsCache = nearestNeighborsCacheResource.resource;
|
|
339
345
|
GetApproximateNearestNeighbors(
|
|
340
346
|
position,
|
|
341
347
|
count,
|
|
@@ -181,11 +181,15 @@ namespace WallstopStudios.UnityHelpers.Core.DataStructure
|
|
|
181
181
|
return elementsInRange;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
Stack<QuadTreeNode
|
|
184
|
+
using PooledResource<Stack<QuadTreeNode>> nodesToVisitResource =
|
|
185
|
+
Buffers<QuadTreeNode>.Stack.Get();
|
|
186
|
+
Stack<QuadTreeNode> nodesToVisit = nodesToVisitResource.resource;
|
|
185
187
|
nodesToVisit.Clear();
|
|
186
188
|
nodesToVisit.Push(_head);
|
|
187
189
|
|
|
188
|
-
List<QuadTreeNode
|
|
190
|
+
using PooledResource<List<QuadTreeNode>> resultResource =
|
|
191
|
+
Buffers<QuadTreeNode>.List.Get();
|
|
192
|
+
List<QuadTreeNode> resultBuffer = resultResource.resource;
|
|
189
193
|
resultBuffer.Clear();
|
|
190
194
|
|
|
191
195
|
while (nodesToVisit.TryPop(out QuadTreeNode currentNode))
|
|
@@ -249,7 +253,9 @@ namespace WallstopStudios.UnityHelpers.Core.DataStructure
|
|
|
249
253
|
|
|
250
254
|
public List<T> GetElementsInBounds(Bounds bounds, List<T> elementsInBounds)
|
|
251
255
|
{
|
|
252
|
-
|
|
256
|
+
using PooledResource<Stack<QuadTreeNode>> stackResource =
|
|
257
|
+
Buffers<QuadTreeNode>.Stack.Get();
|
|
258
|
+
return GetElementsInBounds(bounds, elementsInBounds, stackResource.resource);
|
|
253
259
|
}
|
|
254
260
|
|
|
255
261
|
public List<T> GetElementsInBounds(
|
|
@@ -318,10 +324,18 @@ namespace WallstopStudios.UnityHelpers.Core.DataStructure
|
|
|
318
324
|
List<T> nearestNeighbors
|
|
319
325
|
)
|
|
320
326
|
{
|
|
321
|
-
Stack<QuadTreeNode
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
List<
|
|
327
|
+
using PooledResource<Stack<QuadTreeNode>> nodeBufferResource =
|
|
328
|
+
Buffers<QuadTreeNode>.Stack.Get();
|
|
329
|
+
Stack<QuadTreeNode> nodeBuffer = nodeBufferResource.resource;
|
|
330
|
+
using PooledResource<List<QuadTreeNode>> childrenBufferResource =
|
|
331
|
+
Buffers<QuadTreeNode>.List.Get();
|
|
332
|
+
List<QuadTreeNode> childrenBuffer = childrenBufferResource.resource;
|
|
333
|
+
using PooledResource<HashSet<T>> nearestNeighborBufferResource =
|
|
334
|
+
Buffers<T>.HashSet.Get();
|
|
335
|
+
HashSet<T> nearestNeighborBuffer = nearestNeighborBufferResource.resource;
|
|
336
|
+
using PooledResource<List<Entry>> nearestNeighborsCacheResource =
|
|
337
|
+
Buffers<Entry>.List.Get();
|
|
338
|
+
List<Entry> nearestNeighborsCache = nearestNeighborsCacheResource.resource;
|
|
325
339
|
GetApproximateNearestNeighbors(
|
|
326
340
|
position,
|
|
327
341
|
count,
|
|
@@ -191,8 +191,10 @@ namespace WallstopStudios.UnityHelpers.Core.DataStructure
|
|
|
191
191
|
|
|
192
192
|
public IEnumerable<T> GetElementsInBounds(Bounds bounds)
|
|
193
193
|
{
|
|
194
|
-
Stack<RTreeNode<T
|
|
195
|
-
|
|
194
|
+
using PooledResource<Stack<RTreeNode<T>>> nodeBufferResource = Buffers<
|
|
195
|
+
RTreeNode<T>
|
|
196
|
+
>.Stack.Get();
|
|
197
|
+
return GetElementsInBounds(bounds, nodeBufferResource.resource);
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
public IEnumerable<T> GetElementsInBounds(Bounds bounds, Stack<RTreeNode<T>> nodeBuffer)
|
|
@@ -254,9 +256,17 @@ namespace WallstopStudios.UnityHelpers.Core.DataStructure
|
|
|
254
256
|
List<T> nearestNeighbors
|
|
255
257
|
)
|
|
256
258
|
{
|
|
257
|
-
Stack<RTreeNode<T
|
|
258
|
-
|
|
259
|
-
|
|
259
|
+
using PooledResource<Stack<RTreeNode<T>>> nodeBufferResource = Buffers<
|
|
260
|
+
RTreeNode<T>
|
|
261
|
+
>.Stack.Get();
|
|
262
|
+
Stack<RTreeNode<T>> nodeBuffer = nodeBufferResource.resource;
|
|
263
|
+
using PooledResource<List<RTreeNode<T>>> childrenBufferResource = Buffers<
|
|
264
|
+
RTreeNode<T>
|
|
265
|
+
>.List.Get();
|
|
266
|
+
List<RTreeNode<T>> childrenBuffer = childrenBufferResource.resource;
|
|
267
|
+
using PooledResource<HashSet<T>> nearestNeighborBufferResource =
|
|
268
|
+
Buffers<T>.HashSet.Get();
|
|
269
|
+
HashSet<T> nearestNeighborBuffer = nearestNeighborBufferResource.resource;
|
|
260
270
|
GetApproximateNearestNeighbors(
|
|
261
271
|
position,
|
|
262
272
|
count,
|
|
@@ -36,15 +36,21 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
36
36
|
|
|
37
37
|
public static Rect GetWorldRect(this RectTransform transform)
|
|
38
38
|
{
|
|
39
|
-
Vector3[]
|
|
39
|
+
using PooledResource<Vector3[]> fourCornersResource =
|
|
40
|
+
WallstopFastArrayPool<Vector3>.Get(4);
|
|
41
|
+
Vector3[] fourCorners = fourCornersResource.resource;
|
|
40
42
|
transform.GetWorldCorners(fourCorners);
|
|
41
|
-
|
|
42
|
-
float
|
|
43
|
-
float
|
|
44
|
-
float
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
float minX = float.MaxValue;
|
|
44
|
+
float maxX = float.MinValue;
|
|
45
|
+
float minY = float.MaxValue;
|
|
46
|
+
float maxY = float.MinValue;
|
|
47
|
+
foreach (Vector3 corner in fourCorners)
|
|
48
|
+
{
|
|
49
|
+
minX = Mathf.Min(minX, corner.x);
|
|
50
|
+
maxX = Mathf.Max(maxX, corner.x);
|
|
51
|
+
minY = Mathf.Min(minY, corner.y);
|
|
52
|
+
maxY = Mathf.Max(maxY, corner.y);
|
|
53
|
+
}
|
|
48
54
|
|
|
49
55
|
return new Rect(minX, minY, maxX - minX, maxY - minY);
|
|
50
56
|
}
|
|
@@ -385,7 +391,9 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
385
391
|
List<FastVector3Int> convexHull = new() { startPoint };
|
|
386
392
|
_ = points.Remove(startPoint);
|
|
387
393
|
FastVector3Int currentPoint = convexHull[0];
|
|
388
|
-
List<FastVector3Int
|
|
394
|
+
using PooledResource<List<FastVector3Int>> colinearPointsResource =
|
|
395
|
+
Buffers<FastVector3Int>.List.Get();
|
|
396
|
+
List<FastVector3Int> colinearPoints = colinearPointsResource.resource;
|
|
389
397
|
int counter = 0;
|
|
390
398
|
while (true)
|
|
391
399
|
{
|
|
@@ -623,7 +631,9 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
623
631
|
)
|
|
624
632
|
{
|
|
625
633
|
List<FastVector3Int> convexHull = gridPositions.BuildConvexHull(grid, random);
|
|
626
|
-
List<HullEdge
|
|
634
|
+
using PooledResource<List<HullEdge>> concaveHullEdgesResource =
|
|
635
|
+
Buffers<HullEdge>.List.Get();
|
|
636
|
+
List<HullEdge> concaveHullEdges = concaveHullEdgesResource.resource;
|
|
627
637
|
|
|
628
638
|
SortedSet<HullEdge> data = new(ConcaveHullComparer.Instance);
|
|
629
639
|
for (int i = 0; i < convexHull.Count; ++i)
|
|
@@ -649,7 +659,9 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
649
659
|
new(gridPositions, CellToWorld, maybeBounds.Value, bucketSize: bucketSize);
|
|
650
660
|
|
|
651
661
|
QuadTree<FastVector3Int> quadTree = NewQuadTree();
|
|
652
|
-
List<FastVector3Int
|
|
662
|
+
using PooledResource<List<FastVector3Int>> neighborsBuffer =
|
|
663
|
+
Buffers<FastVector3Int>.List.Get();
|
|
664
|
+
List<FastVector3Int> neighbors = neighborsBuffer.resource;
|
|
653
665
|
while (0 < data.Count)
|
|
654
666
|
{
|
|
655
667
|
HullEdge edge = data.Max;
|
|
@@ -870,7 +882,9 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
870
882
|
return rhsAngle.CompareTo(lhsAngle);
|
|
871
883
|
}
|
|
872
884
|
|
|
873
|
-
List<FastVector3Int
|
|
885
|
+
using PooledResource<List<FastVector3Int>> clockwisePointsResource =
|
|
886
|
+
Buffers<FastVector3Int>.List.Get();
|
|
887
|
+
List<FastVector3Int> clockwisePoints = clockwisePointsResource.resource;
|
|
874
888
|
void FindNearestNeighborsAndPutInClockwisePoints()
|
|
875
889
|
{
|
|
876
890
|
clockwisePoints.Clear();
|
|
@@ -21,7 +21,7 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
21
21
|
createDefaultDecorators: true
|
|
22
22
|
);
|
|
23
23
|
|
|
24
|
-
private static
|
|
24
|
+
private static Thread UnityMainThread;
|
|
25
25
|
private const int LogsPerCacheClean = 5;
|
|
26
26
|
|
|
27
27
|
private static bool LoggingEnabled = true;
|
|
@@ -33,18 +33,10 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
33
33
|
|
|
34
34
|
private static readonly Dictionary<string, object> GenericObject = new();
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
|
37
|
+
private static void InitializeMainThread()
|
|
37
38
|
{
|
|
38
|
-
#if ENABLE_UBERLOGGING
|
|
39
|
-
/*
|
|
40
|
-
Unity throws exceptions if you try to log on something that isn't the main thread.
|
|
41
|
-
Sometimes, it's nice to log in async Tasks. Assume that the first initialization of
|
|
42
|
-
this class will be done by the Unity main thread and then check every time we log.
|
|
43
|
-
If the logging thread is not the unity main thread, then do nothing
|
|
44
|
-
(instead of throwing...)
|
|
45
|
-
*/
|
|
46
39
|
UnityMainThread = Thread.CurrentThread;
|
|
47
|
-
#endif
|
|
48
40
|
}
|
|
49
41
|
|
|
50
42
|
public static void GlobalEnableLogging(this Object component)
|
|
@@ -129,7 +121,7 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
129
121
|
bool pretty = true
|
|
130
122
|
)
|
|
131
123
|
{
|
|
132
|
-
#if ENABLE_UBERLOGGING
|
|
124
|
+
#if ENABLE_UBERLOGGING || DEBUG_LOGGING
|
|
133
125
|
LogDebug(component, message, e, pretty);
|
|
134
126
|
#endif
|
|
135
127
|
}
|
|
@@ -142,10 +134,23 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
142
134
|
bool pretty = true
|
|
143
135
|
)
|
|
144
136
|
{
|
|
145
|
-
#if ENABLE_UBERLOGGING
|
|
137
|
+
#if ENABLE_UBERLOGGING || DEBUG_LOGGING
|
|
146
138
|
if (LoggingAllowed(component))
|
|
147
139
|
{
|
|
148
|
-
|
|
140
|
+
if (Equals(Thread.CurrentThread, UnityMainThread))
|
|
141
|
+
{
|
|
142
|
+
LogInstance.Log(message, component, e, pretty);
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
{
|
|
146
|
+
FormattableString localMessage = message;
|
|
147
|
+
Object localComponent = component;
|
|
148
|
+
Exception localE = e;
|
|
149
|
+
bool localPretty = pretty;
|
|
150
|
+
UnityMainThreadDispatcher.Instance.RunOnMainThread(() =>
|
|
151
|
+
LogInstance.Log(localMessage, localComponent, localE, localPretty)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
149
154
|
}
|
|
150
155
|
#endif
|
|
151
156
|
}
|
|
@@ -158,10 +163,23 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
158
163
|
bool pretty = true
|
|
159
164
|
)
|
|
160
165
|
{
|
|
161
|
-
#if ENABLE_UBERLOGGING
|
|
166
|
+
#if ENABLE_UBERLOGGING || WARN_LOGGING
|
|
162
167
|
if (LoggingAllowed(component))
|
|
163
168
|
{
|
|
164
|
-
|
|
169
|
+
if (Equals(Thread.CurrentThread, UnityMainThread))
|
|
170
|
+
{
|
|
171
|
+
LogInstance.LogWarn(message, component, e, pretty);
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
{
|
|
175
|
+
FormattableString localMessage = message;
|
|
176
|
+
Object localComponent = component;
|
|
177
|
+
Exception localE = e;
|
|
178
|
+
bool localPretty = pretty;
|
|
179
|
+
UnityMainThreadDispatcher.Instance.RunOnMainThread(() =>
|
|
180
|
+
LogInstance.LogWarn(localMessage, localComponent, localE, localPretty)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
165
183
|
}
|
|
166
184
|
#endif
|
|
167
185
|
}
|
|
@@ -174,10 +192,23 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
174
192
|
bool pretty = true
|
|
175
193
|
)
|
|
176
194
|
{
|
|
177
|
-
#if ENABLE_UBERLOGGING
|
|
195
|
+
#if ENABLE_UBERLOGGING || ERROR_LOGGING
|
|
178
196
|
if (LoggingAllowed(component))
|
|
179
197
|
{
|
|
180
|
-
|
|
198
|
+
if (Equals(Thread.CurrentThread, UnityMainThread))
|
|
199
|
+
{
|
|
200
|
+
LogInstance.LogError(message, component, e, pretty);
|
|
201
|
+
}
|
|
202
|
+
else
|
|
203
|
+
{
|
|
204
|
+
FormattableString localMessage = message;
|
|
205
|
+
Object localComponent = component;
|
|
206
|
+
Exception localE = e;
|
|
207
|
+
bool localPretty = pretty;
|
|
208
|
+
UnityMainThreadDispatcher.Instance.RunOnMainThread(() =>
|
|
209
|
+
LogInstance.LogError(localMessage, localComponent, localE, localPretty)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
181
212
|
}
|
|
182
213
|
#endif
|
|
183
214
|
}
|
|
@@ -187,8 +218,8 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
187
218
|
{
|
|
188
219
|
if (Interlocked.Increment(ref _cacheAccessCount) % LogsPerCacheClean == 0)
|
|
189
220
|
{
|
|
190
|
-
List<Object
|
|
191
|
-
buffer.
|
|
221
|
+
using PooledResource<List<Object>> bufferResource = Buffers<Object>.List.Get();
|
|
222
|
+
List<Object> buffer = bufferResource.resource;
|
|
192
223
|
foreach (Object disabled in Disabled)
|
|
193
224
|
{
|
|
194
225
|
buffer.Add(disabled);
|
|
@@ -203,9 +234,7 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
203
234
|
}
|
|
204
235
|
}
|
|
205
236
|
|
|
206
|
-
return LoggingEnabled
|
|
207
|
-
&& Equals(Thread.CurrentThread, UnityMainThread)
|
|
208
|
-
&& !Disabled.Contains(component);
|
|
237
|
+
return LoggingEnabled && !Disabled.Contains(component);
|
|
209
238
|
}
|
|
210
239
|
}
|
|
211
240
|
}
|
|
@@ -28,8 +28,8 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
StringBuilder
|
|
32
|
-
stringBuilder.
|
|
31
|
+
using PooledResource<StringBuilder> stringBuilderResource = Buffers.StringBuilder.Get();
|
|
32
|
+
StringBuilder stringBuilder = stringBuilderResource.resource;
|
|
33
33
|
stringBuilder.AppendFormat("{0:0.##} ", len);
|
|
34
34
|
stringBuilder.Append(ByteSizes[order]);
|
|
35
35
|
return stringBuilder.ToString();
|
|
@@ -227,33 +227,6 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
227
227
|
.FirstOrDefault(child => child.CompareTag(tag));
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
public static bool HasLineOfSight(
|
|
231
|
-
Vector2 initialLocation,
|
|
232
|
-
Vector2 direction,
|
|
233
|
-
Transform transform,
|
|
234
|
-
float totalDistance,
|
|
235
|
-
float delta
|
|
236
|
-
)
|
|
237
|
-
{
|
|
238
|
-
int hits = Physics2D.RaycastNonAlloc(initialLocation, direction, Buffers.RaycastHits);
|
|
239
|
-
for (int i = 0; i < hits; ++i)
|
|
240
|
-
{
|
|
241
|
-
RaycastHit2D hit = Buffers.RaycastHits[i];
|
|
242
|
-
if (hit.transform != transform)
|
|
243
|
-
{
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
float distanceToEdge = totalDistance - hit.distance;
|
|
248
|
-
if (delta <= distanceToEdge)
|
|
249
|
-
{
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
230
|
public static Coroutine StartFunctionAsCoroutine(
|
|
258
231
|
this MonoBehaviour monoBehaviour,
|
|
259
232
|
Action action,
|
|
@@ -18,7 +18,8 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
18
18
|
return buffer;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
List<T
|
|
21
|
+
using PooledResource<List<T>> bufferResource = Buffers<T>.List.Get();
|
|
22
|
+
List<T> internalBuffer = bufferResource.resource;
|
|
22
23
|
if (includeSelf)
|
|
23
24
|
{
|
|
24
25
|
component.GetComponents(internalBuffer);
|
|
@@ -75,7 +76,8 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
75
76
|
return buffer;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
List<T
|
|
79
|
+
using PooledResource<List<T>> internalBufferResource = Buffers<T>.List.Get();
|
|
80
|
+
List<T> internalBuffer = internalBufferResource.resource;
|
|
79
81
|
if (includeSelf)
|
|
80
82
|
{
|
|
81
83
|
component.GetComponents(internalBuffer);
|
|
@@ -344,8 +346,9 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
344
346
|
buffer.Add(transform);
|
|
345
347
|
}
|
|
346
348
|
|
|
347
|
-
Queue<Transform
|
|
348
|
-
|
|
349
|
+
using PooledResource<Queue<Transform>> iterationResource =
|
|
350
|
+
Buffers<Transform>.Queue.Get();
|
|
351
|
+
Queue<Transform> iteration = iterationResource.resource;
|
|
349
352
|
iteration.Enqueue(transform);
|
|
350
353
|
while (iteration.TryDequeue(out Transform current))
|
|
351
354
|
{
|
|
@@ -160,7 +160,7 @@ namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
|
160
160
|
|
|
161
161
|
public static bool Approximately(this float lhs, float rhs, float tolerance = 0.045f)
|
|
162
162
|
{
|
|
163
|
-
return Mathf.Abs(lhs - rhs) <= tolerance;
|
|
163
|
+
return Mathf.Abs(lhs - rhs) <= Mathf.Abs(tolerance);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -2,7 +2,6 @@ namespace WallstopStudios.UnityHelpers.Tags
|
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
4
|
using System.Collections.Generic;
|
|
5
|
-
using System.Linq;
|
|
6
5
|
using Core.Attributes;
|
|
7
6
|
using Core.Extension;
|
|
8
7
|
using Core.Helper;
|
|
@@ -60,7 +59,7 @@ namespace WallstopStudios.UnityHelpers.Tags
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
string serializableName = appliedEffect.effect.name;
|
|
63
|
-
if (string.Equals(effect.name, serializableName))
|
|
62
|
+
if (string.Equals(effect.name, serializableName, StringComparison.Ordinal))
|
|
64
63
|
{
|
|
65
64
|
maybeHandle = appliedEffect;
|
|
66
65
|
break;
|
|
@@ -212,9 +211,7 @@ namespace WallstopStudios.UnityHelpers.Tags
|
|
|
212
211
|
}
|
|
213
212
|
|
|
214
213
|
List<CosmeticEffectData> instancedCosmeticData = null;
|
|
215
|
-
|
|
216
214
|
AttributeEffect effect = handle.effect;
|
|
217
|
-
|
|
218
215
|
foreach (CosmeticEffectData cosmeticEffectData in effect.cosmeticEffects)
|
|
219
216
|
{
|
|
220
217
|
CosmeticEffectData cosmeticEffect = cosmeticEffectData;
|
|
@@ -237,11 +234,12 @@ namespace WallstopStudios.UnityHelpers.Tags
|
|
|
237
234
|
(instancedCosmeticData ??= new List<CosmeticEffectData>()).Add(cosmeticEffect);
|
|
238
235
|
}
|
|
239
236
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
)
|
|
237
|
+
using PooledResource<List<CosmeticEffectComponent>> cosmeticEffectsResource =
|
|
238
|
+
Buffers<CosmeticEffectComponent>.List.Get();
|
|
239
|
+
List<CosmeticEffectComponent> cosmeticEffectsBuffer =
|
|
240
|
+
cosmeticEffectsResource.resource;
|
|
241
|
+
cosmeticEffect.GetComponents(cosmeticEffectsBuffer);
|
|
242
|
+
foreach (CosmeticEffectComponent cosmeticComponent in cosmeticEffectsBuffer)
|
|
245
243
|
{
|
|
246
244
|
cosmeticComponent.OnApplyEffect(gameObject);
|
|
247
245
|
}
|
|
@@ -274,11 +272,12 @@ namespace WallstopStudios.UnityHelpers.Tags
|
|
|
274
272
|
continue;
|
|
275
273
|
}
|
|
276
274
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
)
|
|
275
|
+
using PooledResource<List<CosmeticEffectComponent>> cosmeticEffectsResource =
|
|
276
|
+
Buffers<CosmeticEffectComponent>.List.Get();
|
|
277
|
+
List<CosmeticEffectComponent> cosmeticEffectsBuffer =
|
|
278
|
+
cosmeticEffectsResource.resource;
|
|
279
|
+
cosmeticEffect.GetComponents(cosmeticEffectsBuffer);
|
|
280
|
+
foreach (CosmeticEffectComponent cosmeticComponent in cosmeticEffectsBuffer)
|
|
282
281
|
{
|
|
283
282
|
cosmeticComponent.OnApplyEffect(gameObject);
|
|
284
283
|
}
|
|
@@ -294,11 +293,13 @@ namespace WallstopStudios.UnityHelpers.Tags
|
|
|
294
293
|
)
|
|
295
294
|
)
|
|
296
295
|
{
|
|
296
|
+
if (handle.effect?.cosmeticEffects == null)
|
|
297
|
+
{
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
297
301
|
// If we don't have instanced cosmetic effects, then they were applied directly to the cosmetic data
|
|
298
|
-
foreach (
|
|
299
|
-
CosmeticEffectData cosmeticEffectData in handle.effect.cosmeticEffects
|
|
300
|
-
?? Enumerable.Empty<CosmeticEffectData>()
|
|
301
|
-
)
|
|
302
|
+
foreach (CosmeticEffectData cosmeticEffectData in handle.effect.cosmeticEffects)
|
|
302
303
|
{
|
|
303
304
|
if (cosmeticEffectData.RequiresInstancing)
|
|
304
305
|
{
|
|
@@ -308,11 +309,12 @@ namespace WallstopStudios.UnityHelpers.Tags
|
|
|
308
309
|
continue;
|
|
309
310
|
}
|
|
310
311
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
)
|
|
312
|
+
using PooledResource<List<CosmeticEffectComponent>> cosmeticEffectsResource =
|
|
313
|
+
Buffers<CosmeticEffectComponent>.List.Get();
|
|
314
|
+
List<CosmeticEffectComponent> cosmeticEffectsBuffer =
|
|
315
|
+
cosmeticEffectsResource.resource;
|
|
316
|
+
cosmeticEffectData.GetComponents(cosmeticEffectsBuffer);
|
|
317
|
+
foreach (CosmeticEffectComponent cosmeticComponent in cosmeticEffectsBuffer)
|
|
316
318
|
{
|
|
317
319
|
cosmeticComponent.OnRemoveEffect(gameObject);
|
|
318
320
|
}
|
|
@@ -321,23 +323,28 @@ namespace WallstopStudios.UnityHelpers.Tags
|
|
|
321
323
|
return;
|
|
322
324
|
}
|
|
323
325
|
|
|
324
|
-
foreach (
|
|
325
|
-
CosmeticEffectComponent cosmeticComponent in cosmeticDatas.SelectMany(
|
|
326
|
-
cosmeticData => cosmeticData.GetComponents<CosmeticEffectComponent>()
|
|
327
|
-
)
|
|
328
|
-
)
|
|
326
|
+
foreach (CosmeticEffectData cosmeticData in cosmeticDatas)
|
|
329
327
|
{
|
|
330
|
-
|
|
328
|
+
using PooledResource<List<CosmeticEffectComponent>> cosmeticEffectsResource =
|
|
329
|
+
Buffers<CosmeticEffectComponent>.List.Get();
|
|
330
|
+
List<CosmeticEffectComponent> cosmeticEffectsBuffer =
|
|
331
|
+
cosmeticEffectsResource.resource;
|
|
332
|
+
cosmeticData.GetComponents(cosmeticEffectsBuffer);
|
|
333
|
+
foreach (CosmeticEffectComponent cosmeticComponent in cosmeticEffectsBuffer)
|
|
334
|
+
{
|
|
335
|
+
cosmeticComponent.OnRemoveEffect(gameObject);
|
|
336
|
+
}
|
|
331
337
|
}
|
|
332
338
|
|
|
333
339
|
foreach (CosmeticEffectData data in cosmeticDatas)
|
|
334
340
|
{
|
|
335
341
|
bool shouldDestroyGameObject = true;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
)
|
|
342
|
+
using PooledResource<List<CosmeticEffectComponent>> cosmeticEffectsResource =
|
|
343
|
+
Buffers<CosmeticEffectComponent>.List.Get();
|
|
344
|
+
List<CosmeticEffectComponent> cosmeticEffectsBuffer =
|
|
345
|
+
cosmeticEffectsResource.resource;
|
|
346
|
+
data.GetComponents(cosmeticEffectsBuffer);
|
|
347
|
+
foreach (CosmeticEffectComponent cosmeticEffect in cosmeticEffectsBuffer)
|
|
341
348
|
{
|
|
342
349
|
if (cosmeticEffect.CleansUpSelf)
|
|
343
350
|
{
|
package/Runtime/Utils/Buffers.cs
CHANGED
|
@@ -1,39 +1,76 @@
|
|
|
1
1
|
namespace WallstopStudios.UnityHelpers.Utils
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
|
-
using System.Collections.Concurrent;
|
|
5
4
|
using System.Collections.Generic;
|
|
6
5
|
using System.Text;
|
|
7
|
-
using System.Threading;
|
|
8
6
|
using UnityEngine;
|
|
9
|
-
|
|
7
|
+
using WallstopStudios.UnityHelpers.Core.Extension;
|
|
8
|
+
#if !SINGLE_THREADED
|
|
9
|
+
using System.Threading;
|
|
10
|
+
using System.Collections.Concurrent;
|
|
11
|
+
#endif
|
|
10
12
|
public static class Buffers
|
|
11
13
|
{
|
|
12
|
-
|
|
14
|
+
private static readonly Dictionary<float, WaitForSeconds> WaitForSeconds = new();
|
|
15
|
+
private static readonly Dictionary<float, WaitForSecondsRealtime> WaitForSecondsRealtime =
|
|
16
|
+
new();
|
|
17
|
+
|
|
18
|
+
public static readonly WaitForFixedUpdate WaitForFixedUpdate = new();
|
|
19
|
+
public static readonly WaitForEndOfFrame WaitForEndOfFrame = new();
|
|
13
20
|
|
|
14
|
-
public static readonly
|
|
15
|
-
|
|
21
|
+
public static readonly WallstopGenericPool<StringBuilder> StringBuilder = new(
|
|
22
|
+
() => new StringBuilder(),
|
|
23
|
+
onRelease: builder => builder.Clear()
|
|
24
|
+
);
|
|
16
25
|
|
|
17
26
|
/*
|
|
18
27
|
Note: Only use with CONSTANT time values, otherwise this is a memory leak.
|
|
19
28
|
DO NOT USE with random values.
|
|
20
29
|
*/
|
|
21
|
-
public static
|
|
22
|
-
|
|
23
|
-
new();
|
|
24
|
-
|
|
25
|
-
public static readonly WaitForFixedUpdate WaitForFixedUpdate = new();
|
|
26
|
-
public static readonly WaitForEndOfFrame WaitForEndOfFrame = new();
|
|
30
|
+
public static WaitForSeconds GetWaitForSeconds(float seconds)
|
|
31
|
+
{
|
|
32
|
+
return WaitForSeconds.GetOrAdd(seconds, value => new WaitForSeconds(value));
|
|
33
|
+
}
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
/*
|
|
36
|
+
Note: Only use with CONSTANT time values, otherwise this is a memory leak.
|
|
37
|
+
DO NOT USE with random values.
|
|
38
|
+
*/
|
|
39
|
+
public static WaitForSecondsRealtime GetWaitForSecondsRealTime(float seconds)
|
|
40
|
+
{
|
|
41
|
+
return WaitForSecondsRealtime.GetOrAdd(
|
|
42
|
+
seconds,
|
|
43
|
+
value => new WaitForSecondsRealtime(value)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
29
46
|
}
|
|
30
47
|
|
|
31
48
|
public static class Buffers<T>
|
|
32
49
|
{
|
|
33
|
-
public static readonly List<T
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
public static readonly WallstopGenericPool<List<T>> List = new(
|
|
51
|
+
() => new List<T>(),
|
|
52
|
+
onRelease: list => list.Clear()
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
public static readonly WallstopGenericPool<HashSet<T>> HashSet = new(
|
|
56
|
+
() => new HashSet<T>(),
|
|
57
|
+
onRelease: set => set.Clear()
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
public static readonly WallstopGenericPool<Queue<T>> Queue = new(
|
|
61
|
+
() => new Queue<T>(),
|
|
62
|
+
onRelease: queue => queue.Clear()
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
public static readonly WallstopGenericPool<Stack<T>> Stack = new(
|
|
66
|
+
() => new Stack<T>(),
|
|
67
|
+
onRelease: stack => stack.Clear()
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
public static readonly WallstopGenericPool<SortedSet<T>> SortedSet = new(
|
|
71
|
+
() => new SortedSet<T>(),
|
|
72
|
+
onRelease: set => set.Clear()
|
|
73
|
+
);
|
|
37
74
|
}
|
|
38
75
|
|
|
39
76
|
#if SINGLE_THREADED
|
|
@@ -71,33 +108,6 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
71
108
|
return new PooledResource<T>(value, _onRelease);
|
|
72
109
|
}
|
|
73
110
|
|
|
74
|
-
public static Action<T> GetClearAction()
|
|
75
|
-
{
|
|
76
|
-
try
|
|
77
|
-
{
|
|
78
|
-
Type type = typeof(T);
|
|
79
|
-
foreach (
|
|
80
|
-
MethodInfo method in type.GetMethods(
|
|
81
|
-
BindingFlags.Instance | BindingFlags.Public
|
|
82
|
-
)
|
|
83
|
-
)
|
|
84
|
-
{
|
|
85
|
-
if (
|
|
86
|
-
string.Equals(method.Name, "Clear", StringComparison.Ordinal)
|
|
87
|
-
&& method.GetParameters().Length == 0
|
|
88
|
-
)
|
|
89
|
-
{
|
|
90
|
-
return (Action<T>)Delegate.CreateDelegate(typeof(Action<T>), method);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
catch
|
|
95
|
-
{
|
|
96
|
-
// Swallow
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
111
|
public void Dispose()
|
|
102
112
|
{
|
|
103
113
|
if (_onDispose == null)
|
|
@@ -309,7 +319,6 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
309
319
|
}
|
|
310
320
|
}
|
|
311
321
|
#else
|
|
312
|
-
|
|
313
322
|
public static class WallstopFastArrayPool<T>
|
|
314
323
|
{
|
|
315
324
|
private static readonly ReaderWriterLockSlim _lock = new();
|
|
@@ -455,15 +464,22 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
455
464
|
{
|
|
456
465
|
public readonly T resource;
|
|
457
466
|
private readonly Action<T> _onDispose;
|
|
467
|
+
private readonly bool _initialized;
|
|
458
468
|
|
|
459
469
|
internal PooledResource(T resource, Action<T> onDispose)
|
|
460
470
|
{
|
|
471
|
+
_initialized = true;
|
|
461
472
|
this.resource = resource;
|
|
462
|
-
_onDispose = onDispose
|
|
473
|
+
_onDispose = onDispose;
|
|
463
474
|
}
|
|
464
475
|
|
|
465
476
|
public void Dispose()
|
|
466
477
|
{
|
|
478
|
+
if (!_initialized)
|
|
479
|
+
{
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
467
483
|
_onDispose(resource);
|
|
468
484
|
}
|
|
469
485
|
}
|
|
@@ -86,7 +86,8 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
86
86
|
|
|
87
87
|
int physicsShapes = _lastHandled.GetPhysicsShapeCount();
|
|
88
88
|
polygonCollider.pathCount = physicsShapes;
|
|
89
|
-
List<Vector2
|
|
89
|
+
using PooledResource<List<Vector2>> bufferResource = Buffers<Vector2>.List.Get();
|
|
90
|
+
List<Vector2> buffer = bufferResource.resource;
|
|
90
91
|
for (int i = 0; i < physicsShapes; ++i)
|
|
91
92
|
{
|
|
92
93
|
buffer.Clear();
|
|
@@ -238,11 +238,9 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
238
238
|
_colorStack.Add(_colorStackCache[0]);
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
List<(Component component, Color color)
|
|
242
|
-
Component component,
|
|
243
|
-
|
|
244
|
-
)>.List;
|
|
245
|
-
colorBuffer.Clear();
|
|
241
|
+
using PooledResource<List<(Component component, Color color)>> colorBufferResource =
|
|
242
|
+
Buffers<(Component component, Color color)>.List.Get();
|
|
243
|
+
List<(Component component, Color color)> colorBuffer = colorBufferResource.resource;
|
|
246
244
|
foreach ((Component component, Color color) entry in _colorStackCache)
|
|
247
245
|
{
|
|
248
246
|
colorBuffer.Add(entry);
|
|
@@ -259,11 +257,11 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
259
257
|
_materialStack.Add(_materialStackCache[0]);
|
|
260
258
|
}
|
|
261
259
|
|
|
262
|
-
|
|
263
|
-
Component component,
|
|
264
|
-
|
|
265
|
-
)
|
|
266
|
-
|
|
260
|
+
using PooledResource<
|
|
261
|
+
List<(Component component, Material material)>
|
|
262
|
+
> materialBufferResource = Buffers<(Component component, Material material)>.List.Get();
|
|
263
|
+
List<(Component component, Material material)> materialBuffer =
|
|
264
|
+
materialBufferResource.resource;
|
|
267
265
|
foreach ((Component component, Material material) entry in _materialStackCache)
|
|
268
266
|
{
|
|
269
267
|
materialBuffer.Add(entry);
|
|
@@ -277,11 +275,9 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
277
275
|
|
|
278
276
|
private void OnDisable()
|
|
279
277
|
{
|
|
280
|
-
List<(Component component, Color color)
|
|
281
|
-
Component component,
|
|
282
|
-
|
|
283
|
-
)>.List;
|
|
284
|
-
colorBuffer.Clear();
|
|
278
|
+
using PooledResource<List<(Component component, Color color)>> colorBufferResource =
|
|
279
|
+
Buffers<(Component component, Color color)>.List.Get();
|
|
280
|
+
List<(Component component, Color color)> colorBuffer = colorBufferResource.resource;
|
|
285
281
|
foreach ((Component component, Color color) entry in _colorStack)
|
|
286
282
|
{
|
|
287
283
|
colorBuffer.Add(entry);
|
|
@@ -297,11 +293,11 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
297
293
|
_colorStackCache.Add(entry);
|
|
298
294
|
}
|
|
299
295
|
|
|
300
|
-
|
|
301
|
-
Component component,
|
|
302
|
-
|
|
303
|
-
)
|
|
304
|
-
|
|
296
|
+
using PooledResource<
|
|
297
|
+
List<(Component component, Material material)>
|
|
298
|
+
> materialBufferResource = Buffers<(Component component, Material material)>.List.Get();
|
|
299
|
+
List<(Component component, Material material)> materialBuffer =
|
|
300
|
+
materialBufferResource.resource;
|
|
305
301
|
foreach ((Component component, Material material) entry in _materialStack)
|
|
306
302
|
{
|
|
307
303
|
materialBuffer.Add(entry);
|
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.9",
|
|
4
4
|
"displayName": "Unity Helpers",
|
|
5
5
|
"description": "Various Unity Helper Library",
|
|
6
6
|
"dependencies": {},
|
|
@@ -36,28 +36,3 @@
|
|
|
36
36
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|