com.wallstop-studios.unity-helpers 2.0.0-rc78 → 2.0.0-rc78.2
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.
|
@@ -182,8 +182,8 @@
|
|
|
182
182
|
{
|
|
183
183
|
return target switch
|
|
184
184
|
{
|
|
185
|
-
GameObject go => go.GetComponent<T>(),
|
|
186
|
-
Component c => c.GetComponent<T>(),
|
|
185
|
+
GameObject go => go != null ? go.GetComponent<T>() : default,
|
|
186
|
+
Component c => c != null ? c.GetComponent<T>() : default,
|
|
187
187
|
_ => default,
|
|
188
188
|
};
|
|
189
189
|
}
|
|
@@ -192,8 +192,8 @@
|
|
|
192
192
|
{
|
|
193
193
|
return target switch
|
|
194
194
|
{
|
|
195
|
-
GameObject go => go.GetComponents<T>(),
|
|
196
|
-
Component c => c.GetComponents<T>(),
|
|
195
|
+
GameObject go => go != null ? go.GetComponents<T>() : Array.Empty<T>(),
|
|
196
|
+
Component c => c != null ? c.GetComponents<T>() : Array.Empty<T>(),
|
|
197
197
|
_ => default,
|
|
198
198
|
};
|
|
199
199
|
}
|
|
@@ -203,7 +203,7 @@
|
|
|
203
203
|
return target switch
|
|
204
204
|
{
|
|
205
205
|
GameObject go => go,
|
|
206
|
-
Component c => c.gameObject,
|
|
206
|
+
Component c => c != null ? c.gameObject : null,
|
|
207
207
|
_ => null,
|
|
208
208
|
};
|
|
209
209
|
}
|
|
@@ -213,8 +213,8 @@
|
|
|
213
213
|
component = default;
|
|
214
214
|
return target switch
|
|
215
215
|
{
|
|
216
|
-
GameObject go => go.TryGetComponent(out component),
|
|
217
|
-
Component c => c.TryGetComponent(out component),
|
|
216
|
+
GameObject go => go != null && go.TryGetComponent(out component),
|
|
217
|
+
Component c => c != null && c.TryGetComponent(out component),
|
|
218
218
|
_ => false,
|
|
219
219
|
};
|
|
220
220
|
}
|
|
@@ -53,11 +53,13 @@ namespace WallstopStudios.UnityHelpers.Visuals.UGUI
|
|
|
53
53
|
UpdateMaterialInstance();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
#if UNITY_EDITOR
|
|
56
57
|
protected override void OnValidate()
|
|
57
58
|
{
|
|
58
59
|
base.OnValidate();
|
|
59
60
|
UpdateMaterialInstance();
|
|
60
61
|
}
|
|
62
|
+
#endif
|
|
61
63
|
|
|
62
64
|
private void UpdateMaterialInstance()
|
|
63
65
|
{
|
|
@@ -398,5 +398,35 @@
|
|
|
398
398
|
|
|
399
399
|
yield break;
|
|
400
400
|
}
|
|
401
|
+
|
|
402
|
+
[Test]
|
|
403
|
+
public void GetGameObject()
|
|
404
|
+
{
|
|
405
|
+
GameObject go = new("Test", typeof(SpriteRenderer));
|
|
406
|
+
SpriteRenderer spriteRenderer = go.GetComponent<SpriteRenderer>();
|
|
407
|
+
|
|
408
|
+
GameObject result = go.GetGameObject();
|
|
409
|
+
Assert.AreEqual(result, go);
|
|
410
|
+
result = spriteRenderer.GetGameObject();
|
|
411
|
+
Assert.AreEqual(result, go);
|
|
412
|
+
|
|
413
|
+
Object.DestroyImmediate(spriteRenderer);
|
|
414
|
+
result = spriteRenderer.GetGameObject();
|
|
415
|
+
Assert.IsTrue(result == null);
|
|
416
|
+
result = go.GetGameObject();
|
|
417
|
+
Assert.AreEqual(result, go);
|
|
418
|
+
|
|
419
|
+
Object.DestroyImmediate(go);
|
|
420
|
+
result = spriteRenderer.GetGameObject();
|
|
421
|
+
Assert.IsTrue(result == null);
|
|
422
|
+
result = go.GetGameObject();
|
|
423
|
+
Assert.IsTrue(result == null);
|
|
424
|
+
|
|
425
|
+
result = ((GameObject)null).GetGameObject();
|
|
426
|
+
Assert.IsTrue(result == null);
|
|
427
|
+
|
|
428
|
+
result = ((SpriteRenderer)null).GetGameObject();
|
|
429
|
+
Assert.IsTrue(result == null);
|
|
430
|
+
}
|
|
401
431
|
}
|
|
402
432
|
}
|
package/package.json
CHANGED