Cammin / LDtkToUnity

Unity importer for the LDtk level editor
https://cammin.github.io/LDtkToUnity
MIT License
388 stars 39 forks source link

Tile resolution from asset PixelPerUnit, and plugin interface. #25

Closed BKcore closed 2 months ago

BKcore commented 3 years ago

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;
  }
}
Cammin commented 3 years ago

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 🙂

sigrist commented 2 years ago

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

Cammin commented 2 months ago

The newest version 6.4.2 adds a texture field to use an alternate image with a higher resolution! The inspirations for how to choose how this is added was appreciated :)

https://github.com/user-attachments/assets/0f747c97-75ea-4812-9bb2-5ba9bb184b02