Skip to content

Commit 043a5c5

Browse files
committed
Merge remote-tracking branch 'Cammin/master'
2 parents 01eb4fa + 4cc21d6 commit 043a5c5

151 files changed

Lines changed: 2732 additions & 1126 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
lfs: true
3232

3333
#Test Cache
34-
- uses: actions/cache@v4.0.2
34+
- uses: actions/cache@v4.2.3
3535
with:
3636
path: Library
3737
key: Library-${{ matrix.unityVersion }}

.github/workflows/test-runner_dispatch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
lfs: true
3939

4040
#Test Cache
41-
- uses: actions/cache@v4.0.2
41+
- uses: actions/cache@v4.2.3
4242
with:
4343
path: Library
4444
key: Library-${{ matrix.unityVersion }}

.github/workflows/unity-builder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
lfs: true
4040

4141
#Build Cache
42-
- uses: actions/cache@v4.0.2
42+
- uses: actions/cache@v4.2.3
4343
with:
4444
path: Library
4545
key: Library-${{ matrix.unityVersion }}

Assets/LDtkUnity/CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1+
## [6.9.2](https://github.com/Cammin/LDtkToUnity/compare/6.9.1...6.9.2) (2025-05-02)
2+
3+
4+
### Performance Improvements
5+
6+
* Setting tilemap tiles now leverages TileChangeData introduced in unity 2021.2 to reduce excessive tilemap API calls ([0f77e30](https://github.com/Cammin/LDtkToUnity/commit/0f77e3037299053e5416ec7019d313bead921e0d))
7+
8+
## [6.9.1](https://github.com/Cammin/LDtkToUnity/compare/6.9.0...6.9.1) (2025-04-17)
9+
10+
11+
### Bug Fixes
12+
13+
* Fixed a null ref when trying to draw entity ref array or points array when the array was empty ([a023dda](https://github.com/Cammin/LDtkToUnity/commit/a023dda3ed0bb7884a31e484a4f9ad2b9eed2341))
14+
15+
# [6.9.0](https://github.com/Cammin/LDtkToUnity/compare/6.8.0...6.9.0) (2025-04-17)
16+
17+
18+
### Features
19+
20+
* Added a new ScaleFactor field to LDtkComponentEntity which can be used to scale your entity in ways other than scaling the transform ([3d5f2d4](https://github.com/Cammin/LDtkToUnity/commit/3d5f2d4333928467947f453d51ade1684a78e43c))
21+
* Added a toggle option in the project importer inspector to disable scaling entity prefab instances if they were resized in LDtk ([8558ebb](https://github.com/Cammin/LDtkToUnity/commit/8558ebb99b7675bc47d2745bd31cae39b4a59870))
22+
23+
# [6.8.0](https://github.com/Cammin/LDtkToUnity/compare/6.7.1...6.8.0) (2025-04-16)
24+
25+
26+
### Features
27+
28+
* Added new type checks for FieldDefinition among other small json data changes ([73040e5](https://github.com/Cammin/LDtkToUnity/commit/73040e579a1ac4c18d12229d2e8b83515052618d))
29+
* Added support to LDtkTableOfContents ScriptableObject to get fields, and also can access entity definition data from a toc entry ([1149747](https://github.com/Cammin/LDtkToUnity/commit/1149747d6d286a099078bcdad185e84ccec4d88e))
30+
* Point fields will now draw their Vector2 value in addition to the transform ([9582c59](https://github.com/Cammin/LDtkToUnity/commit/9582c59df613834ecd090f45da545ae2e0c22afa))
31+
* Refactored the fields system to have a secondary way to get field data from LDtkFields with GetField(). This is a requisite to support fields in LDtkTableOfContents ([e2fb42a](https://github.com/Cammin/LDtkToUnity/commit/e2fb42ab91b8332d3beb538940b6f95c67900711))
32+
33+
## [6.7.1](https://github.com/Cammin/LDtkToUnity/compare/6.7.0...6.7.1) (2025-03-29)
34+
35+
36+
### Bug Fixes
37+
38+
* Changed some fields so they are no longer static for more stable parallel import process ([ffeb4ef](https://github.com/Cammin/LDtkToUnity/commit/ffeb4ef981d2c361d113b78c9fa38dd48c068144))
39+
* Prevent potential infinite import loop (and polluted source control) due to the .ldtkc being written even if the contents don't change ([29fda78](https://github.com/Cammin/LDtkToUnity/commit/29fda78a2686faa9ed53fed166c924e77bb99aaa))
40+
41+
# [6.7.0](https://github.com/Cammin/LDtkToUnity/compare/6.6.2...6.7.0) (2025-03-26)
42+
43+
44+
### Features
45+
46+
* Added a Size field for LDtkComponentEntity for getting an easy size in unity units. Relegated it's previous Size field into PxSize ([f4b3089](https://github.com/Cammin/LDtkToUnity/commit/f4b30890a5d0b9ecee1a235ba5b15c2869d53237))
47+
148
## [6.6.2](https://github.com/Cammin/LDtkToUnity/compare/6.6.1...6.6.2) (2024-12-15)
249

350

Assets/LDtkUnity/Editor/Builders/LDtkBuilderEntity.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,21 @@ private void BuildEntityInstance()
5555
AddIidComponent();
5656

5757
PositionEntity();
58-
ScaleEntity();
5958

6059
LDtkProfiler.BeginSample("AddFieldData");
6160
AddFieldData();
6261
LDtkProfiler.EndSample();
6362

6463
PopulateEntityComponent();
64+
65+
ScaleEntity();
6566
}
6667

6768
private void PopulateEntityComponent()
6869
{
69-
_entityComponent.OnImport(Importer.DefinitionObjects, _entity, LayerComponent, _fieldsComponent, _iidComponent);
70+
Vector2 size = ((Vector2)_entity.UnityPxSize / Project.PixelsPerUnit);
71+
72+
_entityComponent.OnImport(Importer.DefinitionObjects, _entity, LayerComponent, _fieldsComponent, _iidComponent, size);
7073
}
7174

7275
private void CreateEntityInstance()
@@ -124,9 +127,11 @@ private void InterfaceEvents()
124127

125128
private void ScaleEntity()
126129
{
130+
if (!Project.ScaleEntities) return;
131+
127132
//modify by the resized entity scaling from LDtk
128133
Vector3 newScale = _entityObj.transform.localScale;
129-
newScale.Scale(_entity.UnityScale);
134+
newScale.Scale(_entityComponent.ScaleFactor);
130135
_entityObj.transform.localScale = newScale;
131136
}
132137

@@ -193,7 +198,7 @@ private void AddHandleDrawers(GameObject gameObject, EntityInstance entityInstan
193198
EntityDefinition entityDef = entityInstance.Definition;
194199

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

198203
Color smartColor = entityInstance.UnitySmartColor;
199204

Assets/LDtkUnity/Editor/Builders/LDtkBuilderIntGridValue.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,35 +81,36 @@ public void BuildIntGridValues()
8181
$"Level:{Layer.LevelReference.Identifier}, Layer:{Layer.Identifier}, IntGridValue:{intGridValue}");
8282
continue;
8383
}
84-
84+
8585
IntGridValueDefinition intGridValueDef = intGridValueDefs[index];
86-
TileBase tile = defToTile[intGridValueDef];
8786

8887
LDtkProfiler.BeginSample("GetTilemapToBuildOn");
8988
TilemapTilesBuilder tilemapToBuildOn = GetTilemapToBuildOn(defToKey[intGridValueDef]);
9089
LDtkProfiler.EndSample();
9190

9291
//Set all the tilemap call configurations, but set the actual tile later via an optimized SetTiles
9392
LDtkProfiler.BeginSample("ConvertCellCoord");
94-
Vector3Int cellToPut = ConvertCellCoord(cell);
93+
Vector3Int cellPosition = ConvertCellCoord(cell);
9594
LDtkProfiler.EndSample();
95+
96+
TileBase tile = defToTile[intGridValueDef];
9697

97-
LDtkProfiler.BeginSample("SetPendingTile");
98-
tilemapToBuildOn.SetPendingTile(cellToPut, tile);
98+
LDtkProfiler.BeginSample("intGridValueDef.UnityColor");
99+
Color color = intGridValueDef.UnityColor;
100+
LDtkProfiler.EndSample();
101+
102+
LDtkProfiler.BeginSample("GetIntGridValueScale");
103+
Matrix4x4 matrix = GetIntGridValueScale(tile);
99104
LDtkProfiler.EndSample();
100105

101-
//color & transform
102-
LDtkProfiler.BeginSample("SetColorAndMatrix");
103-
tilemapToBuildOn.SetColor(cellToPut, intGridValueDef.UnityColor);
104-
Matrix4x4? matrix = GetIntGridValueScale(tile);
105-
if (matrix != null)
106-
{
107-
tilemapToBuildOn.SetTransformMatrix(cellToPut, matrix.Value);
108-
}
109-
106+
LDtkProfiler.BeginSample("construct TileChangeData");
107+
TileChangeData data = new TileChangeData(cellPosition, tile, color, matrix);
108+
LDtkProfiler.EndSample();
109+
110+
LDtkProfiler.BeginSample("AddTileChangeData");
111+
tilemapToBuildOn.AddTileChangeData(ref data);
110112
LDtkProfiler.EndSample();
111113
}
112-
113114
LDtkProfiler.EndSample();
114115

115116
LDtkProfiler.BeginSample("IterateAllTilemaps");
@@ -120,7 +121,7 @@ public void BuildIntGridValues()
120121
Tilemap tilemap = builder.Map;
121122

122123
LDtkProfiler.BeginSample("IntGrid.ApplyPendingTiles");
123-
builder.ApplyPendingTiles(true);
124+
builder.ApplyIntGridTiles();
124125
LDtkProfiler.EndSample();
125126

126127
tilemap.SetOpacity(Layer);
@@ -203,8 +204,9 @@ private Tilemap CreateNewTilemap(TilemapKey key)
203204
/// <summary>
204205
/// There's also scaling code from <see cref="LDtkBuilderLevel.BuildLayerInstance"/> and also in the tileset builder for scale there
205206
/// </summary>
206-
private Matrix4x4? GetIntGridValueScale(TileBase tile)
207+
private Matrix4x4 GetIntGridValueScale(TileBase tile)
207208
{
209+
//todo consider job-ifying this to run this math in parallel
208210
Vector2 scale = Vector2.one;
209211

210212
//make the scale correct across every pixels per unit configuration from the importer
@@ -214,7 +216,7 @@ private Tilemap CreateNewTilemap(TilemapKey key)
214216

215217
if (!GetTileDataForTile(tile, out var data))
216218
{
217-
return null;
219+
return Matrix4x4.identity;
218220
}
219221

220222
if (data.colliderType != Tile.ColliderType.Sprite)

Assets/LDtkUnity/Editor/Builders/LDtkBuilderTileset.cs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Unity.Jobs;
1+
using System.Collections.Generic;
2+
using Unity.Jobs;
23
using UnityEngine;
34
using UnityEngine.Tilemaps;
45

@@ -7,7 +8,9 @@ namespace LDtkUnity.Editor
78
internal sealed class LDtkBuilderTileset : LDtkBuilderLayer
89
{
910
private TileInstance[] _tiles;
10-
private TilemapTilesBuilder _tilesetProvider;
11+
12+
//in most realistic situations, tiles will not overlap, but we can overestimate anyways to avoid resizing
13+
private Dictionary<Vector3Int, int> _depth;
1114

1215
public Tilemap Map;
1316

@@ -87,7 +90,7 @@ public void BuildTileset(TileInstance[] tiles)
8790
LDtkProfiler.EndSample();
8891

8992
LDtkProfiler.BeginSample("new ConstructNewTilemap");
90-
_tilesetProvider = new TilemapTilesBuilder(Map, tiles.Length);
93+
_depth = new Dictionary<Vector3Int, int>(10);
9194
LDtkProfiler.EndSample();
9295

9396
//if we are also an intgrid layer, then we already reduced our position in the intGridBuilder
@@ -102,15 +105,17 @@ public void BuildTileset(TileInstance[] tiles)
102105
Map.SetOpacity(Layer);
103106
LDtkProfiler.EndSample();
104107

105-
LDtkProfiler.BeginSample("CacheNeededTilesArtifacts");
106-
TileBase[] tileAssets = new TileBase[tilesLength];
108+
LDtkProfiler.BeginSample("CacheNeededTilesArtifactsAndSetupColor");
109+
TileChangeData[] tileAssets = new TileChangeData[tilesLength];
110+
//Determine tile asset and setup color while the job is running
107111
LDtkTilesetTile[] artifactTiles = artifacts._tiles;
108112
int artifactCount = artifactTiles.Length;
109113
for (int i = 0; i < tilesLength; i++)
110114
{
111-
int? t = _tiles[i].T;
115+
tileAssets[i].color = new Color(1, 1, 1, _tiles[i].A);
112116

113-
//it's possible that a t value is null in the json, unfortunately
117+
int? t = _tiles[i].T;
118+
//it's possible that a t value is null in the json, unfortunately for performance's sake
114119
if (t == null)
115120
{
116121
continue;
@@ -122,11 +127,12 @@ public void BuildTileset(TileInstance[] tiles)
122127
int tValue = t.Value;
123128
if (tValue < artifactCount)
124129
{
125-
tileAssets[i] = artifactTiles[tValue];
130+
tileAssets[i].tile = artifactTiles[tValue];
126131
}
127132
}
128133
LDtkProfiler.EndSample();
129134

135+
//Job is done, we can use the output now!
130136
LDtkProfiler.BeginSample("handle.Complete");
131137
handle.Complete();
132138
LDtkProfiler.EndSample();
@@ -135,35 +141,24 @@ public void BuildTileset(TileInstance[] tiles)
135141
job.Input.Dispose();
136142
LDtkProfiler.EndSample();
137143

138-
LDtkProfiler.BeginSample("RecalculateCellPositions");
139-
Vector3Int[] cells = new Vector3Int[tilesLength];
144+
LDtkProfiler.BeginSample("RecalculateCellPositionsAndSetupMatrix");
140145
for (int i = 0; i < tilesLength; i++)
141146
{
142-
cells[i] = job.Output[i].Cell;
143-
cells[i].z = _tilesetProvider.GetNextCellZ(cells[i]);
147+
//todo find a way to improve performance of this somehow where we dont need to make a vector3int copy
148+
Vector3Int cell = job.Output[i].Cell;
149+
cell.z = GetNextCellZ(cell);
150+
tileAssets[i].position = cell;
151+
tileAssets[i].transform = job.Output[i].Matrix;
144152
}
145153
LDtkProfiler.EndSample();
146154

147155
LDtkProfiler.BeginSample("Tilemap.SetTiles");
148-
Map.SetTiles(cells, tileAssets);
149-
LDtkProfiler.EndSample();
150-
151-
LDtkProfiler.BeginSample("SetColorAndMatrix");
152-
for (int i = 0; i < tilesLength; i++)
153-
{
154-
Color color = new Color(1, 1, 1, _tiles[i].A);
155-
Matrix4x4 matrix = job.Output[i].Matrix;
156-
_tilesetProvider.SetColorAndMatrix(cells[i], ref color, ref matrix);
157-
}
156+
TilemapTilesBuilder.SetTiles(Map, tileAssets);
158157
LDtkProfiler.EndSample();
159158

160159
LDtkProfiler.BeginSample("Output.Dispose");
161160
job.Output.Dispose();
162161
LDtkProfiler.EndSample();
163-
164-
LDtkProfiler.BeginSample("ApplyExtraData");
165-
_tilesetProvider.ApplyExtraData();
166-
LDtkProfiler.EndSample();
167162

168163
LDtkProfiler.BeginSample("CompressBounds");
169164
Map.CompressBounds();
@@ -174,5 +169,18 @@ private TilesetDefinition EvaluateTilesetDefinition()
174169
{
175170
return Layer.OverrideTilesetUid != null ? Layer.OverrideTilesetDefinition : Layer.TilesetDefinition;
176171
}
172+
173+
/// <param name="cell">Z is always 0</param>
174+
private int GetNextCellZ(Vector3Int cell)
175+
{
176+
if (!_depth.ContainsKey(cell))
177+
{
178+
_depth.Add(cell, 0);
179+
return 0;
180+
}
181+
182+
_depth[cell] += 1;
183+
return _depth[cell];
184+
}
177185
}
178186
}

Assets/LDtkUnity/Editor/Builders/LDtkBuilderWorld.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public LDtkComponentWorld BuildWorld()
3131

3232
LDtkComponentLevel[] levels = null;
3333

34-
//don't make levels if we are using separate levels
34+
//don't make levels if we are using separate levels because the levels in the project only contain root-level information
3535
if (!_json.ExternalLevels)
3636
{
3737
levels = BuildLevels();

Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace LDtkUnity.Editor
77
{
8+
/// <summary>
9+
/// This job is for calculating the tile matrix and cell position for each tile in a layer.
10+
/// </summary>
811
internal struct TileBuildingJob : IJobFor
912
{
1013
public struct InputData
@@ -24,10 +27,10 @@ public struct OutputData
2427
[ReadOnly] public NativeArray<InputData> Input;
2528
[WriteOnly] public NativeArray<OutputData> Output;
2629

27-
[ReadOnly] public int LayerGridSize;
28-
[ReadOnly] public int LayerCWid;
29-
[ReadOnly] public int LayerCHei;
30-
[ReadOnly] public float ScaleFactor;
30+
[ReadOnly] private int LayerGridSize;
31+
[ReadOnly] private int LayerCWid;
32+
[ReadOnly] private int LayerCHei;
33+
[ReadOnly] private float ScaleFactor;
3134

3235
public TileBuildingJob(TileInstance[] tiles, LayerInstance layer, float layerScale)
3336
{

0 commit comments

Comments
 (0)