Skip to content

Commit f4b3089

Browse files
committed
feat: Added a Size field for LDtkComponentEntity for getting an easy size in unity units. Relegated it's previous Size field into PxSize
1 parent 23ea132 commit f4b3089

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

Assets/LDtkUnity/Editor/Builders/LDtkBuilderEntity.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ private void BuildEntityInstance()
6666

6767
private void PopulateEntityComponent()
6868
{
69-
_entityComponent.OnImport(Importer.DefinitionObjects, _entity, LayerComponent, _fieldsComponent, _iidComponent);
69+
Vector2 size = ((Vector2)_entity.UnityPxSize / Project.PixelsPerUnit);
70+
71+
_entityComponent.OnImport(Importer.DefinitionObjects, _entity, LayerComponent, _fieldsComponent, _iidComponent, size);
7072
}
7173

7274
private void CreateEntityInstance()
@@ -193,7 +195,7 @@ private void AddHandleDrawers(GameObject gameObject, EntityInstance entityInstan
193195
EntityDefinition entityDef = entityInstance.Definition;
194196

195197
string entityPath = GetEntityImageAndRect(entityInstance, Project.assetPath, out Rect entityIconRect);
196-
Vector2 size = (Vector2)entityInstance.UnitySize / Project.PixelsPerUnit;
198+
Vector2 size = (Vector2)entityInstance.UnityPxSize / Project.PixelsPerUnit;
197199

198200
Color smartColor = entityInstance.UnitySmartColor;
199201

Assets/LDtkUnity/Runtime/Components/LDtkComponentEntity.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public sealed class LDtkComponentEntity : MonoBehaviour
1313
[field: Tooltip("This entity's layer")]
1414
[field: SerializeField] public LDtkComponentLayer Parent { get; private set; }
1515

16+
[field: Tooltip("This entity's size in unity units")]
17+
[field: SerializeField] public Vector2 Size { get; private set; }
18+
1619
[field: Header("Redundant Fields")]
1720
[field: Tooltip("Grid-based coordinates")]
1821
[field: SerializeField] public Vector2Int Grid { get; private set; }
@@ -43,15 +46,15 @@ public sealed class LDtkComponentEntity : MonoBehaviour
4346
[field: SerializeField] public LDtkFields FieldInstances { get; private set; }
4447

4548
[field: Tooltip("Entity size in pixels. For non-resizable entities, it will be the same as Entity definition.")]
46-
[field: SerializeField] public Vector2Int Size { get; private set; }
49+
[field: SerializeField] public Vector2Int PxSize { get; private set; }
4750

4851
[field: Tooltip("Unique instance identifier")]
4952
[field: SerializeField] public LDtkIid Iid { get; private set; }
5053

5154
[field: Tooltip("Pixel coordinates in current level coordinate space. Don't forget optional layer offsets, if they exist!")]
5255
[field: SerializeField] public Vector2Int Px { get; private set; }
5356

54-
internal void OnImport(LDtkDefinitionObjectsCache cache, EntityInstance entity, LDtkComponentLayer layer, LDtkFields fields, LDtkIid iid)
57+
internal void OnImport(LDtkDefinitionObjectsCache cache, EntityInstance entity, LDtkComponentLayer layer, LDtkFields fields, LDtkIid iid, Vector2 size)
5558
{
5659
Grid = entity.UnityGrid;
5760
Identifier = entity.Identifier;
@@ -62,12 +65,13 @@ internal void OnImport(LDtkDefinitionObjectsCache cache, EntityInstance entity,
6265
WorldCoord = entity.UnityWorld;
6366
Def = cache.GetObject<LDtkDefinitionObjectEntity>(entity.DefUid);
6467
FieldInstances = fields;
65-
Size = entity.UnitySize;
68+
PxSize = entity.UnityPxSize;
6669
Iid = iid;
6770
Px = entity.UnityPx;
6871

6972
//custom
7073
Parent = layer;
74+
Size = size;
7175
}
7276
}
7377
}

Assets/LDtkUnity/Runtime/Data/Extensions/Instance/EntityInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public partial class EntityInstance : ILDtkIdentifier, ILDtkIid
4343
/// <value>
4444
/// Entity size in pixels, adjusted for this instance's resizing.
4545
/// </value>
46-
[IgnoreDataMember] public Vector2Int UnitySize => new Vector2Int(Width, Height);
46+
[IgnoreDataMember] public Vector2Int UnityPxSize => new Vector2Int(Width, Height);
4747

4848
/// <value>
4949
/// Entity scale multiplier, suitable for a transform's scale.

0 commit comments

Comments
 (0)