com.wallstop-studios.unity-helpers 2.0.0-rc17 → 2.0.0-rc19
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.
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
namespace Editor
|
|
2
|
+
{
|
|
3
|
+
#if UNITY_EDITOR
|
|
4
|
+
using System;
|
|
5
|
+
using UnityEditor;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
using UnityHelpers.Core.Helper;
|
|
8
|
+
|
|
9
|
+
[CustomPropertyDrawer(typeof(StringInList))]
|
|
10
|
+
public class StringInListDrawer : PropertyDrawer
|
|
11
|
+
{
|
|
12
|
+
// Draw the property inside the given rect
|
|
13
|
+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
14
|
+
{
|
|
15
|
+
if (attribute is not StringInList stringInList)
|
|
16
|
+
{
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
string[] list = stringInList.List;
|
|
21
|
+
|
|
22
|
+
switch (property.propertyType)
|
|
23
|
+
{
|
|
24
|
+
case SerializedPropertyType.String:
|
|
25
|
+
{
|
|
26
|
+
int index = Mathf.Max(0, Array.IndexOf(list, property.stringValue));
|
|
27
|
+
index = EditorGUI.Popup(position, property.displayName, index, list);
|
|
28
|
+
if (index < 0 || list.Length <= index)
|
|
29
|
+
{
|
|
30
|
+
base.OnGUI(position, property, label);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
property.stringValue = list[index];
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case SerializedPropertyType.Integer:
|
|
38
|
+
{
|
|
39
|
+
property.intValue = EditorGUI.Popup(
|
|
40
|
+
position,
|
|
41
|
+
property.displayName,
|
|
42
|
+
property.intValue,
|
|
43
|
+
list
|
|
44
|
+
);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
default:
|
|
48
|
+
{
|
|
49
|
+
base.OnGUI(position, property, label);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
#endif
|
|
56
|
+
}
|
|
@@ -3,19 +3,22 @@
|
|
|
3
3
|
using System;
|
|
4
4
|
using System.Collections.Generic;
|
|
5
5
|
using UnityEngine;
|
|
6
|
+
using UnityEngine.Serialization;
|
|
6
7
|
using UnityEngine.UI;
|
|
7
8
|
|
|
8
9
|
[DisallowMultipleComponent]
|
|
9
10
|
public sealed class MatchColliderToSprite : MonoBehaviour
|
|
10
11
|
{
|
|
11
|
-
|
|
12
|
-
private SpriteRenderer _spriteRenderer;
|
|
12
|
+
public Func<Sprite> spriteOverrideProducer;
|
|
13
13
|
|
|
14
|
-
[
|
|
15
|
-
|
|
14
|
+
[FormerlySerializedAs("_spriteRenderer")]
|
|
15
|
+
public SpriteRenderer spriteRenderer;
|
|
16
16
|
|
|
17
|
-
[
|
|
18
|
-
|
|
17
|
+
[FormerlySerializedAs("_image")]
|
|
18
|
+
public Image image;
|
|
19
|
+
|
|
20
|
+
[FormerlySerializedAs("_collider")]
|
|
21
|
+
public PolygonCollider2D polygonCollider;
|
|
19
22
|
|
|
20
23
|
private Sprite _lastHandled;
|
|
21
24
|
|
|
@@ -26,12 +29,17 @@
|
|
|
26
29
|
|
|
27
30
|
private void Update()
|
|
28
31
|
{
|
|
29
|
-
if (
|
|
32
|
+
if (spriteOverrideProducer != null && _lastHandled == spriteOverrideProducer())
|
|
33
|
+
{
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (spriteRenderer != null && _lastHandled == spriteRenderer.sprite)
|
|
30
38
|
{
|
|
31
39
|
return;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
|
-
if (
|
|
42
|
+
if (image != null && _lastHandled == image.sprite)
|
|
35
43
|
{
|
|
36
44
|
return;
|
|
37
45
|
}
|
|
@@ -41,42 +49,46 @@
|
|
|
41
49
|
|
|
42
50
|
public void OnValidate()
|
|
43
51
|
{
|
|
52
|
+
if (polygonCollider == null && !TryGetComponent(out polygonCollider))
|
|
53
|
+
{
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
Sprite sprite;
|
|
45
|
-
if (
|
|
58
|
+
if (spriteOverrideProducer != null)
|
|
46
59
|
{
|
|
47
|
-
sprite =
|
|
60
|
+
sprite = spriteOverrideProducer();
|
|
48
61
|
}
|
|
49
|
-
else if (
|
|
62
|
+
else if (spriteRenderer != null || TryGetComponent(out spriteRenderer))
|
|
50
63
|
{
|
|
51
|
-
sprite =
|
|
64
|
+
sprite = spriteRenderer.sprite;
|
|
52
65
|
}
|
|
53
|
-
else
|
|
66
|
+
else if (image != null || TryGetComponent(out image))
|
|
54
67
|
{
|
|
55
|
-
sprite =
|
|
68
|
+
sprite = image.sprite;
|
|
56
69
|
}
|
|
57
|
-
|
|
58
|
-
if (_collider == null || !TryGetComponent(out _collider))
|
|
70
|
+
else
|
|
59
71
|
{
|
|
60
|
-
|
|
72
|
+
sprite = null;
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
_lastHandled = sprite;
|
|
64
|
-
|
|
76
|
+
polygonCollider.points = Array.Empty<Vector2>();
|
|
65
77
|
if (_lastHandled == null)
|
|
66
78
|
{
|
|
67
|
-
|
|
79
|
+
polygonCollider.pathCount = 0;
|
|
68
80
|
return;
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
int physicsShapes = _lastHandled.GetPhysicsShapeCount();
|
|
72
|
-
|
|
84
|
+
polygonCollider.pathCount = physicsShapes;
|
|
73
85
|
List<Vector2> buffer = Buffers<Vector2>.List;
|
|
74
86
|
for (int i = 0; i < physicsShapes; ++i)
|
|
75
87
|
{
|
|
76
88
|
buffer.Clear();
|
|
77
89
|
_ = _lastHandled.GetPhysicsShape(i, buffer);
|
|
78
|
-
|
|
90
|
+
polygonCollider.SetPath(i, buffer);
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
93
|
}
|
|
82
|
-
}
|
|
94
|
+
}
|