From 43465411888de66894edac5eca72d56e25e4f975 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 21 Jul 2024 22:51:36 -0700 Subject: [PATCH] fix: The tile building process will now shift cells if a given tile's offset reached or exceeds 1 in any direction brought on by a rule building multiple tiles. This fixed some render order problems --- Assets/LDtkUnity/Editor/Builders/TileBuildingJob.cs | 13 ++++++++++++- .../Editor/Builders/TilemapTilesBuilder.cs | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) 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))