Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Assets/LDtkUnity/Editor/Builders/LDtkBuilderEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal sealed class LDtkBuilderEntity : LDtkBuilderLayer
private LDtkComponentEntity _entityComponent;
private LDtkFields _fieldsComponent;
private LDtkIid _iidComponent;
private LDtkFieldsFactory _fieldsFactory;

public LDtkBuilderEntity(LDtkProjectImporter project, Level level, LDtkComponentLayer layerComponent, LDtkSortingOrder sortingOrder, LDtkLinearLevelVector linearVector, WorldLayout layout, LDtkAssetProcessorActionCache assetProcess, LDtkJsonImporter importer)
: base(project, level, layerComponent, sortingOrder, importer)
Expand Down Expand Up @@ -89,9 +90,9 @@ private void AddEntityComponent()
private void AddFieldData()
{
LDtkProfiler.BeginSample("SetEntityFieldsComponent");
LDtkFieldsFactory fieldsFactory = new LDtkFieldsFactory(_entityObj, _entity.FieldInstances, Project, Importer);
fieldsFactory.SetEntityFieldsComponent();
_fieldsComponent = fieldsFactory.FieldsComponent;
_fieldsFactory = new LDtkFieldsFactory(_entityObj, _entity.FieldInstances, Project, Importer);
_fieldsFactory.SetEntityFieldsComponent();
_fieldsComponent = _fieldsFactory.FieldsComponent;
LDtkProfiler.EndSample();

LDtkProfiler.BeginSample("InterfaceEvents");
Expand Down Expand Up @@ -128,6 +129,11 @@ private void ScaleEntity()
newScale.x *= _entityComponent.ScaleFactor.x;
newScale.y *= _entityComponent.ScaleFactor.y;
_entityObj.transform.localScale = newScale;

if (_fieldsFactory != null)
{
_fieldsFactory.ApplyPointScale(_entityComponent.ScaleFactor);
}
}

private void PositionEntity()
Expand Down Expand Up @@ -168,4 +174,4 @@ public PointParseData GetParsedPointData()
};
}
}
}
}
19 changes: 17 additions & 2 deletions Assets/LDtkUnity/Editor/ParsedField/LDtkFieldsFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;

namespace LDtkUnity.Editor
{
Expand All @@ -11,6 +12,7 @@ internal sealed class LDtkFieldsFactory
private readonly FieldInstance[] _fieldInstances;
private readonly LDtkProjectImporter _project;
private readonly LDtkJsonImporter _importer;
private readonly List<Transform> _pointTransforms = new List<Transform>();

public LDtkFields FieldsComponent { get; private set; }

Expand Down Expand Up @@ -61,6 +63,8 @@ private LDtkField[] GetFields()
{
LDtkFieldElement element = field._data[ii];
Transform newPoint = new GameObject($"{_fieldInstances[i].Identifier}_{ii}").transform;
_pointTransforms.Add(newPoint);

element.SetPointLocalTransform(newPoint);
newPoint.SetParent(_instance.transform, true);
}
Expand All @@ -69,5 +73,16 @@ private LDtkField[] GetFields()
}
return fields;
}

public void ApplyPointScale(Vector2 scale)
{
foreach (Transform point in _pointTransforms)
{
Vector3 local = point.localPosition;
local.x /= scale.x;
local.y /= scale.y;
point.localPosition = local;
}
}
}
}
}
Loading