com.wallstop-studios.unity-helpers 1.0.1-rc07 → 1.0.1-rc09
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.
|
@@ -2,32 +2,36 @@
|
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
4
|
using System.Collections.Generic;
|
|
5
|
-
using Core.Attributes;
|
|
6
|
-
using Core.Extension;
|
|
7
5
|
using UnityEngine;
|
|
6
|
+
using UnityEngine.UI;
|
|
8
7
|
|
|
9
8
|
[DisallowMultipleComponent]
|
|
10
9
|
public sealed class MatchColliderToSprite : MonoBehaviour
|
|
11
10
|
{
|
|
12
11
|
[SerializeField]
|
|
13
|
-
[SiblingComponent]
|
|
14
12
|
private SpriteRenderer _spriteRenderer;
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
[SerializeField]
|
|
15
|
+
private Image _image;
|
|
16
|
+
|
|
16
17
|
[SerializeField]
|
|
17
|
-
[SiblingComponent]
|
|
18
18
|
private PolygonCollider2D _collider;
|
|
19
19
|
|
|
20
20
|
private Sprite _lastHandled;
|
|
21
21
|
|
|
22
22
|
private void Awake()
|
|
23
23
|
{
|
|
24
|
-
this.AssignSiblingComponents();
|
|
25
24
|
OnValidate();
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
private void Update()
|
|
29
28
|
{
|
|
30
|
-
if (_lastHandled == _spriteRenderer.sprite)
|
|
29
|
+
if (_spriteRenderer != null && _lastHandled == _spriteRenderer.sprite)
|
|
30
|
+
{
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (_image != null && _lastHandled == _image.sprite)
|
|
31
35
|
{
|
|
32
36
|
return;
|
|
33
37
|
}
|
|
@@ -35,30 +39,28 @@
|
|
|
35
39
|
OnValidate();
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
// Visible for testing
|
|
39
42
|
public void OnValidate()
|
|
40
43
|
{
|
|
41
|
-
|
|
44
|
+
Sprite sprite;
|
|
45
|
+
if (_spriteRenderer != null || TryGetComponent(out _spriteRenderer))
|
|
46
|
+
{
|
|
47
|
+
sprite = _spriteRenderer.sprite;
|
|
48
|
+
}
|
|
49
|
+
else if (_image != null || TryGetComponent(out _image))
|
|
42
50
|
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
51
|
+
sprite = _image.sprite;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
sprite = null;
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
if (_collider == null)
|
|
58
|
+
if (_collider == null || !TryGetComponent(out _collider))
|
|
52
59
|
{
|
|
53
|
-
|
|
54
|
-
if (_collider == null)
|
|
55
|
-
{
|
|
56
|
-
this.LogError("No PolygonCollider2D detected - cannot match collider shape.");
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
60
|
+
return;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
_lastHandled =
|
|
63
|
+
_lastHandled = sprite;
|
|
62
64
|
_collider.points = Array.Empty<Vector2>();
|
|
63
65
|
if (_lastHandled == null)
|
|
64
66
|
{
|