com.wallstop-studios.unity-helpers 2.0.0-rc81.2 → 2.0.0-rc81.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.
|
@@ -22,16 +22,19 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
22
22
|
|
|
23
23
|
public static class ChildComponentExtensions
|
|
24
24
|
{
|
|
25
|
-
private static readonly List<Component> ChildCache = new();
|
|
26
25
|
private static readonly Dictionary<
|
|
27
26
|
Type,
|
|
28
|
-
(FieldInfo field, Action<object, object> setter)[]
|
|
27
|
+
(FieldInfo field, ChildComponentAttribute attribute, Action<object, object> setter)[]
|
|
29
28
|
> FieldsByType = new();
|
|
30
29
|
|
|
31
30
|
public static void AssignChildComponents(this Component component)
|
|
32
31
|
{
|
|
33
32
|
Type componentType = component.GetType();
|
|
34
|
-
(
|
|
33
|
+
(
|
|
34
|
+
FieldInfo field,
|
|
35
|
+
ChildComponentAttribute attribute,
|
|
36
|
+
Action<object, object> setter
|
|
37
|
+
)[] fields = FieldsByType.GetOrAdd(
|
|
35
38
|
componentType,
|
|
36
39
|
type =>
|
|
37
40
|
{
|
|
@@ -39,51 +42,58 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
39
42
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
40
43
|
);
|
|
41
44
|
return fields
|
|
42
|
-
.
|
|
43
|
-
|
|
45
|
+
.Select(field =>
|
|
46
|
+
field.IsAttributeDefined(out ChildComponentAttribute attribute)
|
|
47
|
+
? (field, attribute, ReflectionHelpers.GetFieldSetter(field))
|
|
48
|
+
: (null, null, null)
|
|
49
|
+
)
|
|
50
|
+
.Where(tuple => tuple.attribute != null)
|
|
44
51
|
.ToArray();
|
|
45
52
|
}
|
|
46
53
|
);
|
|
47
54
|
|
|
48
|
-
foreach (
|
|
55
|
+
foreach (
|
|
56
|
+
(
|
|
57
|
+
FieldInfo field,
|
|
58
|
+
ChildComponentAttribute attribute,
|
|
59
|
+
Action<object, object> setter
|
|
60
|
+
) in fields
|
|
61
|
+
)
|
|
49
62
|
{
|
|
50
|
-
if (!field.IsAttributeDefined(out ChildComponentAttribute customAttribute))
|
|
51
|
-
{
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
63
|
Type fieldType = field.FieldType;
|
|
56
64
|
bool isArray = fieldType.IsArray;
|
|
57
65
|
Type childComponentType = isArray ? fieldType.GetElementType() : fieldType;
|
|
58
66
|
bool foundChild;
|
|
59
|
-
if (
|
|
67
|
+
if (attribute.onlyDescendents)
|
|
60
68
|
{
|
|
69
|
+
using PooledResource<List<Transform>> childBufferResource =
|
|
70
|
+
Buffers<Transform>.List.Get();
|
|
71
|
+
List<Transform> childBuffer = childBufferResource.resource;
|
|
61
72
|
if (isArray)
|
|
62
73
|
{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
List<Transform> childBuffer = childBufferResource.resource;
|
|
74
|
+
using PooledResource<List<Component>> componentResource =
|
|
75
|
+
Buffers<Component>.List.Get();
|
|
76
|
+
List<Component> cache = componentResource.resource;
|
|
67
77
|
foreach (Transform child in component.IterateOverAllChildren(childBuffer))
|
|
68
78
|
{
|
|
69
79
|
foreach (
|
|
70
80
|
Component childComponent in child.GetComponentsInChildren(
|
|
71
81
|
childComponentType,
|
|
72
|
-
|
|
82
|
+
attribute.includeInactive
|
|
73
83
|
)
|
|
74
84
|
)
|
|
75
85
|
{
|
|
76
|
-
|
|
86
|
+
cache.Add(childComponent);
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
foundChild = 0 <
|
|
90
|
+
foundChild = 0 < cache.Count;
|
|
81
91
|
|
|
82
92
|
Array correctTypedArray = ReflectionHelpers.CreateArray(
|
|
83
93
|
childComponentType,
|
|
84
|
-
|
|
94
|
+
cache.Count
|
|
85
95
|
);
|
|
86
|
-
Array.Copy(
|
|
96
|
+
Array.Copy(cache.ToArray(), correctTypedArray, cache.Count);
|
|
87
97
|
setter(component, correctTypedArray);
|
|
88
98
|
}
|
|
89
99
|
else if (
|
|
@@ -95,15 +105,12 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
95
105
|
|
|
96
106
|
IList instance = ReflectionHelpers.CreateList(childComponentType);
|
|
97
107
|
foundChild = false;
|
|
98
|
-
using PooledResource<List<Transform>> childBufferResource =
|
|
99
|
-
Buffers<Transform>.List.Get();
|
|
100
|
-
List<Transform> childBuffer = childBufferResource.resource;
|
|
101
108
|
foreach (Transform child in component.IterateOverAllChildren(childBuffer))
|
|
102
109
|
{
|
|
103
110
|
foreach (
|
|
104
111
|
Component childComponent in child.GetComponentsInChildren(
|
|
105
112
|
childComponentType,
|
|
106
|
-
|
|
113
|
+
attribute.includeInactive
|
|
107
114
|
)
|
|
108
115
|
)
|
|
109
116
|
{
|
|
@@ -118,9 +125,6 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
118
125
|
{
|
|
119
126
|
foundChild = false;
|
|
120
127
|
Component childComponent = null;
|
|
121
|
-
using PooledResource<List<Transform>> childBufferResource =
|
|
122
|
-
Buffers<Transform>.List.Get();
|
|
123
|
-
List<Transform> childBuffer = childBufferResource.resource;
|
|
124
128
|
foreach (
|
|
125
129
|
Transform child in component.IterateOverAllChildrenRecursivelyBreadthFirst(
|
|
126
130
|
childBuffer
|
|
@@ -131,7 +135,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
131
135
|
if (
|
|
132
136
|
childComponent == null
|
|
133
137
|
|| (
|
|
134
|
-
!
|
|
138
|
+
!attribute.includeInactive
|
|
135
139
|
&& (
|
|
136
140
|
!childComponent.gameObject.activeInHierarchy
|
|
137
141
|
|| childComponent is Behaviour { enabled: false }
|
|
@@ -157,7 +161,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
157
161
|
{
|
|
158
162
|
Component[] childComponents = component.GetComponentsInChildren(
|
|
159
163
|
childComponentType,
|
|
160
|
-
|
|
164
|
+
attribute.includeInactive
|
|
161
165
|
);
|
|
162
166
|
foundChild = 0 < childComponents.Length;
|
|
163
167
|
|
|
@@ -188,7 +192,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
188
192
|
foreach (
|
|
189
193
|
Component childComponent in component.GetComponentsInChildren(
|
|
190
194
|
childComponentType,
|
|
191
|
-
|
|
195
|
+
attribute.includeInactive
|
|
192
196
|
)
|
|
193
197
|
)
|
|
194
198
|
{
|
|
@@ -202,7 +206,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
202
206
|
{
|
|
203
207
|
Component childComponent = component.GetComponentInChildren(
|
|
204
208
|
childComponentType,
|
|
205
|
-
|
|
209
|
+
attribute.includeInactive
|
|
206
210
|
);
|
|
207
211
|
foundChild = childComponent != null;
|
|
208
212
|
if (foundChild)
|
|
@@ -212,7 +216,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
212
216
|
}
|
|
213
217
|
}
|
|
214
218
|
|
|
215
|
-
if (!foundChild && !
|
|
219
|
+
if (!foundChild && !attribute.optional)
|
|
216
220
|
{
|
|
217
221
|
component.LogError($"Unable to find child component of type {fieldType}");
|
|
218
222
|
}
|
|
@@ -23,13 +23,17 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
23
23
|
{
|
|
24
24
|
private static readonly Dictionary<
|
|
25
25
|
Type,
|
|
26
|
-
(FieldInfo field, Action<object, object> setter)[]
|
|
26
|
+
(FieldInfo field, ParentComponentAttribute attribute, Action<object, object> setter)[]
|
|
27
27
|
> FieldsByType = new();
|
|
28
28
|
|
|
29
29
|
public static void AssignParentComponents(this Component component)
|
|
30
30
|
{
|
|
31
31
|
Type componentType = component.GetType();
|
|
32
|
-
(
|
|
32
|
+
(
|
|
33
|
+
FieldInfo field,
|
|
34
|
+
ParentComponentAttribute attribute,
|
|
35
|
+
Action<object, object> setter
|
|
36
|
+
)[] fields = FieldsByType.GetOrAdd(
|
|
33
37
|
componentType,
|
|
34
38
|
type =>
|
|
35
39
|
{
|
|
@@ -37,24 +41,29 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
37
41
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
38
42
|
);
|
|
39
43
|
return fields
|
|
40
|
-
.
|
|
41
|
-
|
|
44
|
+
.Select(field =>
|
|
45
|
+
field.IsAttributeDefined(out ParentComponentAttribute attribute)
|
|
46
|
+
? (field, attribute, ReflectionHelpers.GetFieldSetter(field))
|
|
47
|
+
: (null, null, null)
|
|
48
|
+
)
|
|
49
|
+
.Where(tuple => tuple.attribute != null)
|
|
42
50
|
.ToArray();
|
|
43
51
|
}
|
|
44
52
|
);
|
|
45
53
|
|
|
46
|
-
foreach (
|
|
54
|
+
foreach (
|
|
55
|
+
(
|
|
56
|
+
FieldInfo field,
|
|
57
|
+
ParentComponentAttribute attribute,
|
|
58
|
+
Action<object, object> setter
|
|
59
|
+
) in fields
|
|
60
|
+
)
|
|
47
61
|
{
|
|
48
|
-
if (!field.IsAttributeDefined(out ParentComponentAttribute customAttribute))
|
|
49
|
-
{
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
62
|
Type fieldType = field.FieldType;
|
|
54
63
|
bool isArray = fieldType.IsArray;
|
|
55
64
|
Type parentComponentType = isArray ? fieldType.GetElementType() : fieldType;
|
|
56
65
|
bool foundParent;
|
|
57
|
-
if (
|
|
66
|
+
if (attribute.onlyAncestors)
|
|
58
67
|
{
|
|
59
68
|
Transform parent = component.transform.parent;
|
|
60
69
|
if (parent == null)
|
|
@@ -65,7 +74,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
65
74
|
{
|
|
66
75
|
Component[] parentComponents = parent.GetComponentsInParent(
|
|
67
76
|
parentComponentType,
|
|
68
|
-
|
|
77
|
+
attribute.includeInactive
|
|
69
78
|
);
|
|
70
79
|
foundParent = 0 < parentComponents.Length;
|
|
71
80
|
|
|
@@ -85,7 +94,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
85
94
|
|
|
86
95
|
Component[] parents = parent.GetComponentsInParent(
|
|
87
96
|
parentComponentType,
|
|
88
|
-
|
|
97
|
+
attribute.includeInactive
|
|
89
98
|
);
|
|
90
99
|
|
|
91
100
|
IList instance = ReflectionHelpers.CreateList(
|
|
@@ -106,7 +115,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
106
115
|
{
|
|
107
116
|
Component childComponent = parent.GetComponentInParent(
|
|
108
117
|
parentComponentType,
|
|
109
|
-
|
|
118
|
+
attribute.includeInactive
|
|
110
119
|
);
|
|
111
120
|
foundParent = childComponent != null;
|
|
112
121
|
if (foundParent)
|
|
@@ -121,7 +130,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
121
130
|
{
|
|
122
131
|
Component[] parentComponents = component.GetComponentsInParent(
|
|
123
132
|
parentComponentType,
|
|
124
|
-
|
|
133
|
+
attribute.includeInactive
|
|
125
134
|
);
|
|
126
135
|
foundParent = 0 < parentComponents.Length;
|
|
127
136
|
|
|
@@ -140,7 +149,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
140
149
|
parentComponentType = fieldType.GenericTypeArguments[0];
|
|
141
150
|
Component[] parents = component.GetComponentsInParent(
|
|
142
151
|
parentComponentType,
|
|
143
|
-
|
|
152
|
+
attribute.includeInactive
|
|
144
153
|
);
|
|
145
154
|
|
|
146
155
|
IList instance = ReflectionHelpers.CreateList(
|
|
@@ -160,7 +169,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
160
169
|
{
|
|
161
170
|
Component childComponent = component.GetComponentInParent(
|
|
162
171
|
parentComponentType,
|
|
163
|
-
|
|
172
|
+
attribute.includeInactive
|
|
164
173
|
);
|
|
165
174
|
foundParent = childComponent != null;
|
|
166
175
|
if (foundParent)
|
|
@@ -170,7 +179,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
170
179
|
}
|
|
171
180
|
}
|
|
172
181
|
|
|
173
|
-
if (!foundParent && !
|
|
182
|
+
if (!foundParent && !attribute.optional)
|
|
174
183
|
{
|
|
175
184
|
component.LogError($"Unable to find parent component of type {fieldType}");
|
|
176
185
|
}
|
|
@@ -22,13 +22,17 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
22
22
|
{
|
|
23
23
|
private static readonly Dictionary<
|
|
24
24
|
Type,
|
|
25
|
-
(FieldInfo field, Action<object, object> setter)[]
|
|
25
|
+
(FieldInfo field, SiblingComponentAttribute attribute, Action<object, object> setter)[]
|
|
26
26
|
> FieldsByType = new();
|
|
27
27
|
|
|
28
28
|
public static void AssignSiblingComponents(this Component component)
|
|
29
29
|
{
|
|
30
30
|
Type componentType = component.GetType();
|
|
31
|
-
(
|
|
31
|
+
(
|
|
32
|
+
FieldInfo field,
|
|
33
|
+
SiblingComponentAttribute attribute,
|
|
34
|
+
Action<object, object> setter
|
|
35
|
+
)[] fields = FieldsByType.GetOrAdd(
|
|
32
36
|
componentType,
|
|
33
37
|
type =>
|
|
34
38
|
{
|
|
@@ -36,13 +40,23 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
36
40
|
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
37
41
|
);
|
|
38
42
|
return fields
|
|
39
|
-
.
|
|
40
|
-
|
|
43
|
+
.Select(field =>
|
|
44
|
+
field.IsAttributeDefined(out SiblingComponentAttribute attribute)
|
|
45
|
+
? (field, attribute, ReflectionHelpers.GetFieldSetter(field))
|
|
46
|
+
: (null, null, null)
|
|
47
|
+
)
|
|
48
|
+
.Where(tuple => tuple.attribute != null)
|
|
41
49
|
.ToArray();
|
|
42
50
|
}
|
|
43
51
|
);
|
|
44
52
|
|
|
45
|
-
foreach (
|
|
53
|
+
foreach (
|
|
54
|
+
(
|
|
55
|
+
FieldInfo field,
|
|
56
|
+
SiblingComponentAttribute attribute,
|
|
57
|
+
Action<object, object> setter
|
|
58
|
+
) in fields
|
|
59
|
+
)
|
|
46
60
|
{
|
|
47
61
|
Type fieldType = field.FieldType;
|
|
48
62
|
bool isArray = fieldType.IsArray;
|
|
@@ -113,11 +127,7 @@ namespace WallstopStudios.UnityHelpers.Core.Attributes
|
|
|
113
127
|
}
|
|
114
128
|
}
|
|
115
129
|
|
|
116
|
-
if (
|
|
117
|
-
!foundSibling
|
|
118
|
-
&& field.IsAttributeDefined(out SiblingComponentAttribute customAttribute)
|
|
119
|
-
&& !customAttribute.optional
|
|
120
|
-
)
|
|
130
|
+
if (!foundSibling && !attribute.optional)
|
|
121
131
|
{
|
|
122
132
|
component.LogError($"Unable to find sibling component of type {fieldType}");
|
|
123
133
|
}
|
package/Runtime/Utils/Buffers.cs
CHANGED
|
@@ -8,16 +8,25 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
8
8
|
using System.Collections.Generic;
|
|
9
9
|
using System.Text;
|
|
10
10
|
using UnityEngine;
|
|
11
|
-
using WallstopStudios.UnityHelpers.Core.Extension;
|
|
12
11
|
#if !SINGLE_THREADED
|
|
13
12
|
using System.Threading;
|
|
14
13
|
using System.Collections.Concurrent;
|
|
14
|
+
#else
|
|
15
|
+
using WallstopStudios.UnityHelpers.Core.Extension;
|
|
15
16
|
#endif
|
|
16
17
|
public static class Buffers
|
|
17
18
|
{
|
|
19
|
+
#if SINGLE_THREADED
|
|
18
20
|
private static readonly Dictionary<float, WaitForSeconds> WaitForSeconds = new();
|
|
19
21
|
private static readonly Dictionary<float, WaitForSecondsRealtime> WaitForSecondsRealtime =
|
|
20
22
|
new();
|
|
23
|
+
#else
|
|
24
|
+
private static readonly ConcurrentDictionary<float, WaitForSeconds> WaitForSeconds = new();
|
|
25
|
+
private static readonly ConcurrentDictionary<
|
|
26
|
+
float,
|
|
27
|
+
WaitForSecondsRealtime
|
|
28
|
+
> WaitForSecondsRealtime = new();
|
|
29
|
+
#endif
|
|
21
30
|
|
|
22
31
|
public static readonly WaitForFixedUpdate WaitForFixedUpdate = new();
|
|
23
32
|
public static readonly WaitForEndOfFrame WaitForEndOfFrame = new();
|
|
@@ -110,7 +119,12 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
110
119
|
|
|
111
120
|
public PooledResource<T> Get()
|
|
112
121
|
{
|
|
113
|
-
|
|
122
|
+
return Get(out _);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public PooledResource<T> Get(out T value)
|
|
126
|
+
{
|
|
127
|
+
if (!_pool.TryPop(out value))
|
|
114
128
|
{
|
|
115
129
|
value = _producer();
|
|
116
130
|
}
|
|
@@ -168,7 +182,12 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
168
182
|
|
|
169
183
|
public PooledResource<T> Get()
|
|
170
184
|
{
|
|
171
|
-
|
|
185
|
+
return Get(out _);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public PooledResource<T> Get(out T value)
|
|
189
|
+
{
|
|
190
|
+
if (!_pool.TryPop(out value))
|
|
172
191
|
{
|
|
173
192
|
value = _producer();
|
|
174
193
|
}
|
|
@@ -200,6 +219,11 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
200
219
|
private static readonly Action<T[]> _onDispose = Release;
|
|
201
220
|
|
|
202
221
|
public static PooledResource<T[]> Get(int size)
|
|
222
|
+
{
|
|
223
|
+
return Get(size, out _);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public static PooledResource<T[]> Get(int size, out T[] value)
|
|
203
227
|
{
|
|
204
228
|
switch (size)
|
|
205
229
|
{
|
|
@@ -213,7 +237,8 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
213
237
|
}
|
|
214
238
|
case 0:
|
|
215
239
|
{
|
|
216
|
-
|
|
240
|
+
value = Array.Empty<T>();
|
|
241
|
+
return new PooledResource<T[]>(value, _ => { });
|
|
217
242
|
}
|
|
218
243
|
}
|
|
219
244
|
|
|
@@ -225,13 +250,14 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
225
250
|
|
|
226
251
|
if (pool.Count == 0)
|
|
227
252
|
{
|
|
228
|
-
|
|
253
|
+
value = new T[size];
|
|
254
|
+
return new PooledResource<T[]>(value, _onDispose);
|
|
229
255
|
}
|
|
230
256
|
|
|
231
257
|
int lastIndex = pool.Count - 1;
|
|
232
|
-
|
|
258
|
+
value = pool[lastIndex];
|
|
233
259
|
pool.RemoveAt(lastIndex);
|
|
234
|
-
return new PooledResource<T[]>(
|
|
260
|
+
return new PooledResource<T[]>(value, _onDispose);
|
|
235
261
|
}
|
|
236
262
|
|
|
237
263
|
private static void Release(T[] resource)
|
|
@@ -253,6 +279,11 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
253
279
|
private static readonly Action<T[]> _onRelease = Release;
|
|
254
280
|
|
|
255
281
|
public static PooledResource<T[]> Get(int size)
|
|
282
|
+
{
|
|
283
|
+
return Get(size, out _);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
public static PooledResource<T[]> Get(int size, out T[] value)
|
|
256
287
|
{
|
|
257
288
|
switch (size)
|
|
258
289
|
{
|
|
@@ -266,17 +297,18 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
266
297
|
}
|
|
267
298
|
case 0:
|
|
268
299
|
{
|
|
269
|
-
|
|
300
|
+
value = Array.Empty<T>();
|
|
301
|
+
return new PooledResource<T[]>(value, _ => { });
|
|
270
302
|
}
|
|
271
303
|
}
|
|
272
304
|
|
|
273
305
|
ConcurrentStack<T[]> result = _pool.GetOrAdd(size, _ => new ConcurrentStack<T[]>());
|
|
274
|
-
if (!result.TryPop(out
|
|
306
|
+
if (!result.TryPop(out value))
|
|
275
307
|
{
|
|
276
|
-
|
|
308
|
+
value = new T[size];
|
|
277
309
|
}
|
|
278
310
|
|
|
279
|
-
return new PooledResource<T[]>(
|
|
311
|
+
return new PooledResource<T[]>(value, _onRelease);
|
|
280
312
|
}
|
|
281
313
|
|
|
282
314
|
private static void Release(T[] resource)
|
|
@@ -296,6 +328,11 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
296
328
|
private static readonly Action<T[]> _onRelease = Release;
|
|
297
329
|
|
|
298
330
|
public static PooledResource<T[]> Get(int size)
|
|
331
|
+
{
|
|
332
|
+
return Get(size, out _);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public static PooledResource<T[]> Get(int size, out T[] value)
|
|
299
336
|
{
|
|
300
337
|
switch (size)
|
|
301
338
|
{
|
|
@@ -309,7 +346,8 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
309
346
|
}
|
|
310
347
|
case 0:
|
|
311
348
|
{
|
|
312
|
-
|
|
349
|
+
value = Array.Empty<T>();
|
|
350
|
+
return new PooledResource<T[]>(value, _ => { });
|
|
313
351
|
}
|
|
314
352
|
}
|
|
315
353
|
|
|
@@ -325,12 +363,12 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
325
363
|
_pool[size] = pool;
|
|
326
364
|
}
|
|
327
365
|
|
|
328
|
-
if (!pool.TryPop(out
|
|
366
|
+
if (!pool.TryPop(out value))
|
|
329
367
|
{
|
|
330
|
-
|
|
368
|
+
value = new T[size];
|
|
331
369
|
}
|
|
332
370
|
|
|
333
|
-
return new PooledResource<T[]>(
|
|
371
|
+
return new PooledResource<T[]>(value, _onRelease);
|
|
334
372
|
}
|
|
335
373
|
|
|
336
374
|
private static void Release(T[] resource)
|
|
@@ -346,6 +384,11 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
346
384
|
private static readonly Action<T[]> _onRelease = Release;
|
|
347
385
|
|
|
348
386
|
public static PooledResource<T[]> Get(int size)
|
|
387
|
+
{
|
|
388
|
+
return Get(size, out _);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
public static PooledResource<T[]> Get(int size, out T[] value)
|
|
349
392
|
{
|
|
350
393
|
switch (size)
|
|
351
394
|
{
|
|
@@ -359,7 +402,8 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
359
402
|
}
|
|
360
403
|
case 0:
|
|
361
404
|
{
|
|
362
|
-
|
|
405
|
+
value = Array.Empty<T>();
|
|
406
|
+
return new PooledResource<T[]>(value, _ => { });
|
|
363
407
|
}
|
|
364
408
|
}
|
|
365
409
|
|
|
@@ -465,12 +509,12 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
465
509
|
}
|
|
466
510
|
}
|
|
467
511
|
|
|
468
|
-
if (!pool.TryPop(out
|
|
512
|
+
if (!pool.TryPop(out value))
|
|
469
513
|
{
|
|
470
|
-
|
|
514
|
+
value = new T[size];
|
|
471
515
|
}
|
|
472
516
|
|
|
473
|
-
return new PooledResource<T[]>(
|
|
517
|
+
return new PooledResource<T[]>(value, _onRelease);
|
|
474
518
|
}
|
|
475
519
|
|
|
476
520
|
private static void Release(T[] resource)
|