Load Names From Data File

williamt
New Member
Registered: 2014-05-21
Posts: 3

Topic

It would be great if when you are creating tilesets you could pull in the names for the tiles from a data file. Like for instance the one that you get when using TexturePacker. I think this would be a really cool feature.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 1

I agree that this would be a nice feature. Which formats do you feel are the most important (aside from TexturePacker)?

Until such a feature is added, it should be fairly straightforward to automate the naming of tileset brushes with a custom script. Assuming that you use the "Auto Name" feature of the brush creator tab, something like the following should work (pseudocode):

void RenameTilesetBrushesFromDataFile(Tileset tileset, IList<string> newNames) {
    var tilesetRecord = BrushDatabase.Instance.FindTilesetRecord(tileset);

    int tileCount = tileset.Rows * tileset.Columns;

    if (newNames.Count < tileCount) {
        Debug.LogError("Not enough names were specified, aborted.");
        return;
    }
    else if (newNames.Count > tileCount) {
        Debug.LogWarning("More names were specified than expected, proceeding...");
    }

    for (int tileIndex = 0; tileIndex < tileCount; ++tileIndex) {
        var brushRecord = tilesetRecord.FindBrushByName("Tile " + (tileIndex + 1));
        BrushDatabase.RenameBrush(brushRecord.Brush, newNames[tileIndex]);
    }
}

Then you could read your custom data file. For instance, with a comma separated list:

string csv = File.ReadAllText(@"C:\TilesetTileNames.txt");
string[] tileNames = csv.Split(',');
RenameTilesetBrushesFromDataFile(yourTileset, tileNames);

Let me know if you have a specific data file and I would be happy to take a stab at creating a utility window for you which reads it.

I hope that this helps!

Last edited by Lea Hayes (2014-06-02 17:29:52)

williamt
New Member
Registered: 2014-05-21
Posts: 3

Response 2

I'm not really sure what other formats to support. TexturePacker can export to many data formats. One is Unity JSON (which is usable in the free version of TexturePacker). It has other formats as well. I think that and CSV would be good. Some people may want XML but I'm not sure.

In your pseudocode, how do you get a reference to Database ?

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 3

I'm not really sure what other formats to support. TexturePacker can export to many data formats. One is Unity JSON (which is usable in the free version of TexturePacker). It has other formats as well. I think that and CSV would be good. Some people may want XML but I'm not sure.

Awesome stuff. This wont make it into the 3.4.0 release but I think this would be extremely useful!

In your pseudocode, how do you get a reference to Database ?

This was a typo, I have updated the source to show BrushDatabase instead. This is part of the Rotorz Tile System editor API which is documented here:
http://rotorz.com/unity/tile-system/api … shDatabase

Please let me know if you have any further questions and I will do my best to assist :)