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
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 32e167906e4845f4b2aebb7ca3494aea
3
+ timeCreated: 1738520991
@@ -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
- [SerializeField]
12
- private SpriteRenderer _spriteRenderer;
12
+ public Func<Sprite> spriteOverrideProducer;
13
13
 
14
- [SerializeField]
15
- private Image _image;
14
+ [FormerlySerializedAs("_spriteRenderer")]
15
+ public SpriteRenderer spriteRenderer;
16
16
 
17
- [SerializeField]
18
- private PolygonCollider2D _collider;
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 (_spriteRenderer != null && _lastHandled == _spriteRenderer.sprite)
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 (_image != null && _lastHandled == _image.sprite)
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 (_spriteRenderer != null || TryGetComponent(out _spriteRenderer))
58
+ if (spriteOverrideProducer != null)
46
59
  {
47
- sprite = _spriteRenderer.sprite;
60
+ sprite = spriteOverrideProducer();
48
61
  }
49
- else if (_image != null || TryGetComponent(out _image))
62
+ else if (spriteRenderer != null || TryGetComponent(out spriteRenderer))
50
63
  {
51
- sprite = _image.sprite;
64
+ sprite = spriteRenderer.sprite;
52
65
  }
53
- else
66
+ else if (image != null || TryGetComponent(out image))
54
67
  {
55
- sprite = null;
68
+ sprite = image.sprite;
56
69
  }
57
-
58
- if (_collider == null || !TryGetComponent(out _collider))
70
+ else
59
71
  {
60
- return;
72
+ sprite = null;
61
73
  }
62
74
 
63
75
  _lastHandled = sprite;
64
- _collider.points = Array.Empty<Vector2>();
76
+ polygonCollider.points = Array.Empty<Vector2>();
65
77
  if (_lastHandled == null)
66
78
  {
67
- _collider.pathCount = 0;
79
+ polygonCollider.pathCount = 0;
68
80
  return;
69
81
  }
70
82
 
71
83
  int physicsShapes = _lastHandled.GetPhysicsShapeCount();
72
- _collider.pathCount = physicsShapes;
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
- _collider.SetPath(i, buffer);
90
+ polygonCollider.SetPath(i, buffer);
79
91
  }
80
92
  }
81
93
  }
82
- }
94
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc17",
3
+ "version": "2.0.0-rc19",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},