com.wallstop-studios.unity-helpers 2.0.0-rc20 → 2.0.0-rc22
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.
|
@@ -248,8 +248,8 @@
|
|
|
248
248
|
return;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
int textureX = offsetX + x + spriteX;
|
|
252
|
-
int textureY = offsetY + y + spriteY;
|
|
251
|
+
int textureX = (-1 * minX) + offsetX + x + spriteX;
|
|
252
|
+
int textureY = (-1 * minY) + offsetY + y + spriteY;
|
|
253
253
|
int index = textureY * width + textureX;
|
|
254
254
|
|
|
255
255
|
if (index < 0 || pixels.Length <= index)
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
{
|
|
3
3
|
using System.Collections.Generic;
|
|
4
4
|
using System.Linq;
|
|
5
|
-
using UnityEngine;
|
|
6
5
|
using Core.Attributes;
|
|
6
|
+
using UnityEngine;
|
|
7
7
|
|
|
8
8
|
/// <summary>
|
|
9
9
|
/// Keeps stack-like track of Colors and Materials of SpriteRenderers
|
|
@@ -80,13 +80,26 @@
|
|
|
80
80
|
_spriteRenderer.color = CurrentColor;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
public bool TryGetColor(Component component, out Color color)
|
|
84
|
+
{
|
|
85
|
+
int index = _colorStack.FindIndex(value => value.component == component);
|
|
86
|
+
if (index < 0)
|
|
87
|
+
{
|
|
88
|
+
color = default;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
color = _colorStack[index].color;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
83
96
|
/// <summary>
|
|
84
97
|
/// Inserts a material as "first in the queue".
|
|
85
98
|
/// </summary>
|
|
86
99
|
/// <param name="component">Component that owns the material.</param>
|
|
87
100
|
/// <param name="material">Material to use.</param>
|
|
88
101
|
/// <param name="force">If true, overrides the enable check.</param>
|
|
89
|
-
/// <returns>The instanced material, if possible.</returns>
|
|
102
|
+
/// <returns>The instanced material, if possible.</returns>
|
|
90
103
|
public Material PushMaterial(Component component, Material material, bool force = false)
|
|
91
104
|
{
|
|
92
105
|
if (component == this)
|
|
@@ -171,6 +184,18 @@
|
|
|
171
184
|
_materialStack[^1] = (currentComponent, instanced);
|
|
172
185
|
}
|
|
173
186
|
|
|
187
|
+
public bool TryGetMaterial(Component component, out Material material)
|
|
188
|
+
{
|
|
189
|
+
int index = _materialStack.FindIndex(value => value.component == component);
|
|
190
|
+
if (index < 0)
|
|
191
|
+
{
|
|
192
|
+
material = default;
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
material = _materialStack[index].material;
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
|
|
174
199
|
private void Awake()
|
|
175
200
|
{
|
|
176
201
|
if (_spriteRenderer == null)
|
|
@@ -195,7 +220,10 @@
|
|
|
195
220
|
|
|
196
221
|
_colorStack.Clear();
|
|
197
222
|
_colorStack.Add(_colorStackCache[0]);
|
|
198
|
-
List<(Component component, Color color)> colorBuffer = Buffers<(
|
|
223
|
+
List<(Component component, Color color)> colorBuffer = Buffers<(
|
|
224
|
+
Component component,
|
|
225
|
+
Color color
|
|
226
|
+
)>.List;
|
|
199
227
|
colorBuffer.Clear();
|
|
200
228
|
colorBuffer.AddRange(_colorStackCache);
|
|
201
229
|
for (int i = 1; i < colorBuffer.Count; ++i)
|
|
@@ -206,8 +234,10 @@
|
|
|
206
234
|
|
|
207
235
|
_materialStack.Clear();
|
|
208
236
|
_materialStack.Add(_materialStackCache[0]);
|
|
209
|
-
List<(Component component, Material material)> materialBuffer =
|
|
210
|
-
|
|
237
|
+
List<(Component component, Material material)> materialBuffer = Buffers<(
|
|
238
|
+
Component component,
|
|
239
|
+
Material material
|
|
240
|
+
)>.List;
|
|
211
241
|
materialBuffer.Clear();
|
|
212
242
|
materialBuffer.AddRange(_materialStackCache);
|
|
213
243
|
for (int i = 1; i < materialBuffer.Count; ++i)
|
|
@@ -219,7 +249,10 @@
|
|
|
219
249
|
|
|
220
250
|
private void OnDisable()
|
|
221
251
|
{
|
|
222
|
-
List<(Component component, Color color)> colorBuffer = Buffers<(
|
|
252
|
+
List<(Component component, Color color)> colorBuffer = Buffers<(
|
|
253
|
+
Component component,
|
|
254
|
+
Color color
|
|
255
|
+
)>.List;
|
|
223
256
|
colorBuffer.Clear();
|
|
224
257
|
colorBuffer.AddRange(_colorStack);
|
|
225
258
|
for (int i = colorBuffer.Count - 1; 1 <= i; --i)
|
|
@@ -230,8 +263,10 @@
|
|
|
230
263
|
_colorStackCache.Clear();
|
|
231
264
|
_colorStackCache.AddRange(colorBuffer);
|
|
232
265
|
|
|
233
|
-
List<(Component component, Material material)> materialBuffer =
|
|
234
|
-
|
|
266
|
+
List<(Component component, Material material)> materialBuffer = Buffers<(
|
|
267
|
+
Component component,
|
|
268
|
+
Material material
|
|
269
|
+
)>.List;
|
|
235
270
|
materialBuffer.Clear();
|
|
236
271
|
materialBuffer.AddRange(_materialStack);
|
|
237
272
|
|
|
@@ -251,10 +286,12 @@
|
|
|
251
286
|
return;
|
|
252
287
|
}
|
|
253
288
|
|
|
254
|
-
_ = _colorStack.RemoveAll(
|
|
255
|
-
existingComponent
|
|
256
|
-
|
|
257
|
-
|
|
289
|
+
_ = _colorStack.RemoveAll(existingComponent =>
|
|
290
|
+
existingComponent.component == component || existingComponent.component == null
|
|
291
|
+
);
|
|
292
|
+
_ = _colorStackCache.RemoveAll(existingComponent =>
|
|
293
|
+
existingComponent.component == component || existingComponent.component == null
|
|
294
|
+
);
|
|
258
295
|
}
|
|
259
296
|
|
|
260
297
|
private void RemoveMaterial(Component component)
|
|
@@ -264,10 +301,12 @@
|
|
|
264
301
|
return;
|
|
265
302
|
}
|
|
266
303
|
|
|
267
|
-
_ = _materialStack.RemoveAll(
|
|
268
|
-
existingComponent
|
|
269
|
-
|
|
270
|
-
|
|
304
|
+
_ = _materialStack.RemoveAll(existingComponent =>
|
|
305
|
+
existingComponent.component == component || existingComponent.component == null
|
|
306
|
+
);
|
|
307
|
+
_ = _materialStackCache.RemoveAll(existingComponent =>
|
|
308
|
+
existingComponent.component == component || existingComponent.component == null
|
|
309
|
+
);
|
|
271
310
|
}
|
|
272
311
|
}
|
|
273
|
-
}
|
|
312
|
+
}
|