diff --git a/Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs b/Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs index cfc663ec..aa6ed3c1 100644 --- a/Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs +++ b/Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs @@ -1,4 +1,5 @@ -using Unity.Collections; +using System; +using Unity.Collections; using Unity.Jobs; using UnityEngine; @@ -67,6 +68,16 @@ public void Execute(int i) offset.x = pxOffsetX / (float)LayerGridSize; offset.y = -pxOffsetY / (float)LayerGridSize; + //Rules can have multiple tiles built (like a 2x2 of art), but they all occupy the same coordId despite being located full cell(s) away! + //this results in offsets that can exceed 1 or -1, which at that point, should occupy the next cell over. + //not only is it easier to track down the tile in the editor, but it renders in a better z order with other tiles in that other cell. + int cellShiftX = offset.x > 0 ? (int)Math.Floor(offset.x) : (int)Math.Ceiling(offset.x); + int cellShiftY = offset.y > 0 ? (int)Math.Floor(offset.y) : (int)Math.Ceiling(offset.y); + cX += cellShiftX; + cY -= cellShiftY; + offset.x -= cellShiftX; + offset.y -= cellShiftY; + bool flipX = (input.Flip & 1) == 1; bool flipY = (input.Flip & 2) == 2; diff --git a/Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs b/Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs index 23b69ac8..126f036c 100644 --- a/Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs +++ b/Assets/LDtkUnity/Editor/Builders/TilemapTilesBuilder.cs @@ -48,6 +48,7 @@ public TilemapTilesBuilder(Tilemap map, int capacity) _depth = new Dictionary(10); } + /// Z is always 0 public int GetNextCellZ(Vector3Int cell) { if (!_depth.ContainsKey(cell))