LDtkToUnity icon indicating copy to clipboard operation
LDtkToUnity copied to clipboard

Tile resolution from asset PixelPerUnit, and plugin interface.

Open BKcore opened this issue 4 years ago • 2 comments

Hey,

Following up from a conversation on the LDtk discord.

Turns out you've made a bunch of changes to the project since I grabbed the source, so making a PR wouldn't be trivial. Here's a patch of the changes instead if you want to take a look.

ldtk-asset-proc-changes.patch.txt

This includes 2 changes:

  1. Pulling the tile resolution from the Unity Texture Asset
  2. A simple extension pattern to allow defining a path mapper outside of the LDtk source

These changes allow remapping of the tileset art to a different file, with a different tile resolution, allowing the use of HD tilesets (keeping low-res tilesets in LDtk which doesn't support high-res tiles).

Here's what the path mapper looks like on my side:

[InitializeOnLoad]
public static class AssetProcessingExtensionsInitializer {
  static AssetProcessingExtensionsInitializer() {
    Debug.Log("AssetProcessingExtensionsInitializer");
    AssetProcessingExtensions.RegisterAssetPathMapper(new AssetPathMapper());
  }
}

public class AssetPathMapper : IAssetPathMapper {
  public string MapAssetPath(string path) {
    var outPath = path;
    if (outPath.EndsWith("SD.png")) {
      var hd = outPath.Replace("SD.png", "HD.png");
      if (File.Exists(hd)) {
        outPath = hd;
      }
    }
    if (path != outPath) {
      Debug.Log($"Remapped {path} to {outPath}");
    }
    return outPath;
  }
}

BKcore avatar Jul 06 '21 04:07 BKcore

Yeah, this looks very cool. I may implement this sometime, in case this can be helpful for anyone else in the same situation.

Thanks for providing your solution to rerouting paths 🙂

Cammin avatar Jul 06 '21 17:07 Cammin

This issue is a little old, but it would be a great feature. Working with small resolution in LDTK and then the possibility to replace with high resolution assets when importing in Unity would be awesome

+1 to implement this feature

sigrist avatar Jul 14 '22 12:07 sigrist