Skip to content

Commit d3a39ba

Browse files
committed
Merge tag '6.11.0'
2 parents 043a5c5 + 6fe0539 commit d3a39ba

49 files changed

Lines changed: 586 additions & 839 deletions

Some content is hidden

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

Assets/LDtkUnity/CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
# [6.11.0](https://github.com/Cammin/LDtkToUnity/compare/6.10.0...6.11.0) (2025-05-16)
2+
3+
4+
### Bug Fixes
5+
6+
* Fixed ordering of fields in the project settings ([0ea0528](https://github.com/Cammin/LDtkToUnity/commit/0ea0528a815ef6aaad91ddb99daa989866bb5a49))
7+
8+
9+
### Features
10+
11+
* Added MiddleCenterOffset to LDtkComponentEntity. It's used for helping draw handles in the scene, but could be useful for other means. ([42d5cb1](https://github.com/Cammin/LDtkToUnity/commit/42d5cb19d7bb840ddd6dd37a762381949ea6d821))
12+
* Added PixelsPerUnit value to LDtkComponentLevel. Added new public method to recalculate the level border values in case the level is moved ([6c83962](https://github.com/Cammin/LDtkToUnity/commit/6c839629e1cf0a87f7e693d4a444e4d38fcbdc5b))
13+
14+
15+
### Performance Improvements
16+
17+
* Refactor that removes the LDtkEntityDrawerComponent, and simplifies the data delivery for all of the drawn scene window handles. ([d415590](https://github.com/Cammin/LDtkToUnity/commit/d415590fe02341d8bff6e3a28bc3293aed58a8d9))
18+
19+
# [6.10.0](https://github.com/Cammin/LDtkToUnity/compare/6.9.2...6.10.0) (2025-05-07)
20+
21+
22+
### Features
23+
24+
* Added a new toggle in the project settings to force a prefab revert on all LDtk prefab instances in loaded scenes ([50892a5](https://github.com/Cammin/LDtkToUnity/commit/50892a576248762d641faeb5d96c3b76c43b33e7))
25+
126
## [6.9.2](https://github.com/Cammin/LDtkToUnity/compare/6.9.1...6.9.2) (2025-05-02)
227

328

Assets/LDtkUnity/Editor/Builders/LDtkBuilderEntity.cs

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using UnityEditor;
2-
using UnityEngine;
1+
using UnityEngine;
32

43
namespace LDtkUnity.Editor
54
{
@@ -67,8 +66,7 @@ private void BuildEntityInstance()
6766

6867
private void PopulateEntityComponent()
6968
{
70-
Vector2 size = ((Vector2)_entity.UnityPxSize / Project.PixelsPerUnit);
71-
69+
Vector2 size = (Vector2)_entity.UnityPxSize / Project.PixelsPerUnit;
7270
_entityComponent.OnImport(Importer.DefinitionObjects, _entity, LayerComponent, _fieldsComponent, _iidComponent, size);
7371
}
7472

@@ -96,10 +94,6 @@ private void AddFieldData()
9694
_fieldsComponent = fieldsFactory.FieldsComponent;
9795
LDtkProfiler.EndSample();
9896

99-
LDtkProfiler.BeginSample("AddHandleDrawers");
100-
AddHandleDrawers(_entityObj, _entity, Layer.GridSize);
101-
LDtkProfiler.EndSample();
102-
10397
LDtkProfiler.BeginSample("InterfaceEvents");
10498
InterfaceEvents();
10599
LDtkProfiler.EndSample();
@@ -144,115 +138,6 @@ private void PositionEntity()
144138

145139
_entityObj.transform.localPosition = localPos;
146140
}
147-
148-
/// <summary>
149-
/// Only doing this for importer performance. an early return to not build the rest
150-
/// </summary>
151-
private static bool DrawerEligibility(FieldInstance field)
152-
{
153-
EditorDisplayMode? mode = field.Definition.EditorDisplayMode;
154-
155-
switch (mode)
156-
{
157-
case EditorDisplayMode.Hidden: //do not show
158-
return false;
159-
160-
case EditorDisplayMode.ValueOnly: //all but point/point array
161-
return !field.IsPoint;
162-
163-
case EditorDisplayMode.NameAndValue: //all
164-
return true;
165-
166-
case EditorDisplayMode.EntityTile: //enum/enum array, tile/tile array
167-
return field.IsEnum || field.IsTile;
168-
169-
case EditorDisplayMode.RadiusGrid: //int, float
170-
case EditorDisplayMode.RadiusPx: //int, float
171-
return field.IsInt || field.IsFloat;
172-
173-
case EditorDisplayMode.PointStar: //point, point array
174-
case EditorDisplayMode.Points: //point, point array
175-
return field.IsPoint;
176-
177-
case EditorDisplayMode.PointPath: //point array only
178-
case EditorDisplayMode.PointPathLoop: //point array only
179-
return field.IsPoint && field.Definition.IsArray;
180-
181-
case EditorDisplayMode.ArrayCountNoLabel: //any arrays
182-
case EditorDisplayMode.ArrayCountWithLabel: //any arrays
183-
return field.Definition.IsArray;
184-
185-
case EditorDisplayMode.RefLinkBetweenCenters: //entity ref, entity ref array
186-
case EditorDisplayMode.RefLinkBetweenPivots: //entity ref, entity ref array
187-
return field.IsEntityRef;
188-
189-
default:
190-
LDtkDebug.LogError("No Drawer eligibility found!");
191-
return false;
192-
}
193-
}
194-
195-
private void AddHandleDrawers(GameObject gameObject, EntityInstance entityInstance, int gridSize)
196-
{
197-
LDtkEntityDrawerComponent drawerComponent = gameObject.gameObject.AddComponent<LDtkEntityDrawerComponent>();
198-
EntityDefinition entityDef = entityInstance.Definition;
199-
200-
string entityPath = GetEntityImageAndRect(entityInstance, Project.assetPath, out Rect entityIconRect);
201-
Vector2 size = (Vector2)entityInstance.UnityPxSize / Project.PixelsPerUnit;
202-
203-
Color smartColor = entityInstance.UnitySmartColor;
204-
205-
//entity handle data
206-
LDtkEntityDrawerData entityDrawerData = new LDtkEntityDrawerData(drawerComponent.transform, entityDef, entityPath, entityIconRect, size, smartColor);
207-
drawerComponent.AddEntityDrawer(entityDrawerData);
208-
209-
foreach (FieldInstance fieldInstance in entityInstance.FieldInstances)
210-
{
211-
if (!DrawerEligibility(fieldInstance))
212-
{
213-
continue;
214-
}
215-
216-
EditorDisplayMode displayMode = fieldInstance.Definition.EditorDisplayMode;
217-
Vector2 pivotOffset = LDtkCoordConverter.EntityPivotOffset(entityDef.UnityPivot, size);
218-
Vector3 middleCenter = gameObject.transform.position + (Vector3)pivotOffset;
219-
220-
LDtkFieldDrawerData data = new LDtkFieldDrawerData(_fieldsComponent, smartColor, displayMode, fieldInstance.Identifier, gridSize, Project.PixelsPerUnit, middleCenter);
221-
drawerComponent.AddReference(data);
222-
}
223-
}
224-
225-
//this would be used instead in the entity drawer for getting the texture that way
226-
private string GetEntityImageAndRect(EntityInstance entityInstance, string assetPath, out Rect rect)
227-
{
228-
rect = new Rect();
229-
230-
TilesetRectangle tile = entityInstance.Tile;
231-
if (tile == null)
232-
{
233-
return null;
234-
}
235-
236-
//todo while awaiting this fix, safely null check it https://github.com/deepnight/ldtk/issues/1107
237-
TilesetDefinition tileset = tile.Tileset;
238-
if (tileset == null)
239-
{
240-
return null;
241-
}
242-
243-
LDtkRelativeGetterTilesetTexture textureGetter = new LDtkRelativeGetterTilesetTexture();
244-
Texture2D tex = textureGetter.GetRelativeAsset(tileset, assetPath);
245-
if (tex == null)
246-
{
247-
return null;
248-
}
249-
250-
Rect src = tile.UnityRect;
251-
rect = LDtkCoordConverter.ImageSlice(src, tex.height);
252-
253-
string texPath = AssetDatabase.GetAssetPath(tex);
254-
return texPath;
255-
}
256141

257142
public PointParseData GetParsedPointData()
258143
{

Assets/LDtkUnity/Editor/Builders/LDtkBuilderLevel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ private void CreateLevelComponent()
225225

226226
private void PopulateLevelComponent()
227227
{
228-
Vector2 size = ((Vector2)_level.UnityPxSize / _project.PixelsPerUnit);
229-
230-
_levelComponent.OnImport(_level, _lvlFile, _layerComponents, _fieldsComponent, _worldComponent, size, _iidComponent);
228+
_levelComponent.OnImport(_level, _lvlFile, _layerComponents, _fieldsComponent, _worldComponent, _iidComponent, _project.PixelsPerUnit);
231229
}
232230

233231
private bool TryAddFields()

Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Linq;
32
using UnityEngine;
43
using UnityEngine.Tilemaps;
54

Assets/LDtkUnity/Editor/CustomEditor/Importer/LDtkEditorCommandUpdater.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Diagnostics;
22
using System.IO;
3-
using System.Linq;
4-
using System.Text.RegularExpressions;
53
using UnityEditor;
64
using UnityEngine;
75

Assets/LDtkUnity/Editor/CustomEditor/LDtkEntityDrawerComponentEditor.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

Assets/LDtkUnity/Editor/CustomEditor/LDtkEntityDrawerComponentEditor.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/LDtkUnity/Editor/CustomEditor/SceneDrawer/ComponentDrawers/LDtkSceneDrawerEntity.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,69 @@
11
using System;
2-
using UnityEditor;
2+
using System.Linq;
33
using UnityEngine;
44

55
namespace LDtkUnity.Editor
66
{
7+
/// <summary>
8+
/// Draws entity stuff, no field stuff
9+
/// </summary>
710
internal static class LDtkSceneDrawerEntity
811
{
9-
public static ILDtkHandleDrawer DrawEntity(LDtkEntityDrawerData entity)
12+
public static void DrawEntityDrawer(LDtkComponentEntity entityComponent)
1013
{
1114
Vector2 offset = Vector2.zero;
1215

13-
if (entity.Transform == null)
16+
if (!entityComponent.Def)
1417
{
15-
return null;
18+
return;
1619
}
1720

18-
switch (entity.EntityMode)
21+
switch (entityComponent.Def.RenderMode)
1922
{
2023
case RenderMode.Cross:
2124
case RenderMode.Ellipse:
2225
case RenderMode.Rectangle:
2326
case RenderMode.Tile:
24-
LDtkEntityDrawerShapes.Data shapeData = new LDtkEntityDrawerShapes.Data()
25-
{
26-
EntityMode = entity.EntityMode,
27-
FillOpacity = entity.FillOpacity,
28-
LineOpacity = entity.LineOpacity,
29-
Hollow = entity.Hollow,
30-
Pivot = entity.Pivot,
31-
Size = entity.Size
32-
};
33-
LDtkEntityDrawerShapes entityDrawer = new LDtkEntityDrawerShapes(entity.Transform, shapeData);
27+
LDtkEntityDrawerShapes entityDrawer = new LDtkEntityDrawerShapes(entityComponent);
3428
entityDrawer.OnDrawHandles();
3529
break;
3630
default:
3731
throw new ArgumentOutOfRangeException();
3832
}
3933

40-
offset = TryDrawTile(entity, offset);
41-
TryDrawName(entity, offset);
34+
offset = TryDrawTile(entityComponent, offset);
35+
TryDrawName(entityComponent, offset);
4236

43-
return null;
37+
return;
4438
}
4539

46-
private static void TryDrawName(LDtkEntityDrawerData entity, Vector2 offset)
40+
private static void TryDrawName(LDtkComponentEntity entity, Vector2 offset)
4741
{
48-
if (entity.ShowName && LDtkPrefs.ShowEntityIdentifier)
42+
if (entity.Def.ShowName && LDtkPrefs.ShowEntityIdentifier)
4943
{
50-
HandleUtil.DrawText(entity.Identifier, entity.Transform.position, entity.SmartColor, offset);
44+
HandleUtil.DrawText(entity.Identifier, entity.transform.position, entity.SmartColor, offset);
5145
}
5246
}
5347

54-
private static Vector2 TryDrawTile(LDtkEntityDrawerData entity, Vector2 offset)
48+
private static Vector2 TryDrawTile(LDtkComponentEntity entityComponent, Vector2 offset)
5549
{
56-
if (!entity.DrawTile)
50+
bool entityDrawsTile = entityComponent.Def.RenderMode == RenderMode.Tile;
51+
bool fieldDrawsTile = entityComponent.Def.FieldDefs.Any(field => field.EditorDisplayMode == EditorDisplayMode.EntityTile);
52+
53+
bool drawsTile = entityDrawsTile || fieldDrawsTile;
54+
55+
if (!drawsTile)
5756
{
5857
return offset;
5958
}
6059

61-
Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>(entity.TexPath);
62-
if (tex == null)
60+
Sprite tile = entityComponent.Tile;
61+
if (!tile)
6362
{
6463
return offset;
6564
}
6665

67-
LDtkEntityDrawerIcon iconDrawer = new LDtkEntityDrawerIcon(entity.Transform, tex, entity.TexRect);
66+
LDtkEntityDrawerIcon iconDrawer = new LDtkEntityDrawerIcon(entityComponent.transform, tile.texture, tile.rect);
6867

6968
iconDrawer.PrecalculateValues();
7069
offset += iconDrawer.OffsetToNextUI;

Assets/LDtkUnity/Editor/CustomEditor/SceneDrawer/ComponentDrawers/LDtkSceneDrawerField.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

Assets/LDtkUnity/Editor/CustomEditor/SceneDrawer/ComponentDrawers/LDtkSceneDrawerField.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)