Skip to content

Commit 9582c59

Browse files
committed
feat: Point fields will now draw their Vector2 value in addition to the transform
1 parent 7786197 commit 9582c59

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Assets/LDtkUnity/Editor/PropertyDrawer/LDtkFieldElementDrawer.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal sealed class LDtkFieldElementDrawer : PropertyDrawer
1313

1414
private SerializedProperty _canBeNullProp;
1515
private SerializedProperty _isNotNullProp;
16+
private SerializedProperty _elementProp;
1617
private SerializedProperty _valueProp;
1718
private SerializedProperty _min;
1819
private SerializedProperty _max;
@@ -54,6 +55,13 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
5455
}
5556

5657
}
58+
59+
if (type == LDtkFieldType.Point)
60+
{
61+
propertyHeight *= 2;
62+
propertyHeight++;
63+
}
64+
5765
return propertyHeight;
5866
}
5967

@@ -70,6 +78,8 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
7078
private void Draw(Rect position, SerializedProperty property, GUIContent label)
7179
{
7280
LDtkProfiler.BeginSample("LDtkFieldElementDrawer.Draw");
81+
82+
_elementProp = property;
7383

7484
TryInitTex();
7585

@@ -156,6 +166,9 @@ private bool TryDrawNullable(GUIContent label, LDtkFieldType type)
156166
return true;
157167
}
158168

169+
/// <summary>
170+
/// If return true, block drawing the standard field
171+
/// </summary>
159172
private bool TryDrawAlternateType(LDtkFieldType type, GUIContent label)
160173
{
161174
switch (type)
@@ -181,6 +194,12 @@ private bool TryDrawAlternateType(LDtkFieldType type, GUIContent label)
181194
return false;
182195
}
183196

197+
case LDtkFieldType.Point:
198+
{
199+
DrawPointField(label);
200+
return true;
201+
}
202+
184203
default:
185204
return false;
186205
}
@@ -251,6 +270,21 @@ private void DrawTileField(GUIContent label)
251270
GUI.DrawTexture(imgRect, tex);
252271
}
253272

273+
private void DrawPointField(GUIContent label)
274+
{
275+
Rect labelRect = new Rect(_labelRect);
276+
labelRect.height = EditorGUIUtility.singleLineHeight;
277+
EditorGUI.LabelField(labelRect, label);
278+
279+
Rect objectRect = new Rect(_fieldRect);
280+
objectRect.height = EditorGUIUtility.singleLineHeight;
281+
EditorGUI.PropertyField(objectRect, _valueProp, GUIContent.none);
282+
283+
SerializedProperty vector2Prop = _elementProp.FindPropertyRelative(LDtkFieldElement.PROPERTY_VECTOR2);
284+
objectRect.y += EditorGUIUtility.singleLineHeight+1;
285+
EditorGUI.PropertyField(objectRect, vector2Prop, GUIContent.none);
286+
}
287+
254288
private static Texture2D GetTileTexture(Sprite spr)
255289
{
256290
return AssetPreview.GetAssetPreview(spr);

0 commit comments

Comments
 (0)