Skip to content

Commit 42d5cb1

Browse files
committed
feat: Added MiddleCenterOffset to LDtkComponentEntity. It's used for helping draw handles in the scene, but could be useful for other means.
1 parent 6c83962 commit 42d5cb1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Assets/LDtkUnity/Runtime/Components/LDtkComponentEntity.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public sealed class LDtkComponentEntity : MonoBehaviour
1919
[field: Tooltip("The scale determined by how much the entity is resized relative to it's default size. Use for determining the length of an entity prefab, like scaling or length/size.")]
2020
[field: SerializeField] public Vector2 ScaleFactor { get; private set; }
2121

22+
[field: Tooltip("Local offset from this transform to the center of this entity based on size. Used for drawing handles in the scene from the entity's center")]
23+
[field: SerializeField] public Vector2 MiddleCenterOffset { get; private set; }
24+
2225
[field: Header("Redundant Fields")]
2326
[field: Tooltip("Grid-based coordinates")]
2427
[field: SerializeField] public Vector2Int Grid { get; private set; }
@@ -76,6 +79,12 @@ internal void OnImport(LDtkDefinitionObjectsCache cache, EntityInstance entity,
7679
Parent = layer;
7780
Size = size;
7881
ScaleFactor = entity.UnityScale;
82+
MiddleCenterOffset = LDtkCoordConverter.EntityPivotOffset(Def.Pivot, size);
7983
}
84+
85+
/// <summary>
86+
/// The middle center of what this entity would be, factoring entity size
87+
/// </summary>
88+
public Vector3 MiddleCenter => transform.TransformPoint(MiddleCenterOffset);
8089
}
8190
}

0 commit comments

Comments
 (0)