How do I get reference to all tiles in a scene

(vitaly) #1


We need to place tiles on a tile map programmatically. We have found TileEdMapGroup.AddTile(TileEdMapTile tile) method but we cannot find a reference to all tiles TileEdMapTile[] in the scene. The idea is when we put some tile on the scene we use the onPlacedTile callback and add some more tiles using TileEd API. Is there ability to access and iterate over all available tiles and add it to the map? Thanks.

(Leslie Young) #2

The TileEdMapAsset contains a list of TileEdMapGroup, each containing a list of TileEdMapTile (the tiles).

Extract Assets\plyoung\TileEd\packages\ if you did not yet do so to see what the TileEd map assets look like.

(vitaly) #3

Hi, thanks for the response but that’s not exactly what we are looking for. We need to get reference to all available tiles and props for placing on the scene. The tiles are contained within different tile groups and it seems TileEdTileSetsAsset is what we are looking for but there is no instance of that class available. Thanks.

(Leslie Young) #4

Oh, you looking for the Tile/ Prop sets you created?
Those are saved under /Assets/projectData/TileEd/Data/
The scripts are TileEdTileSetsAsset and TileEdPropSetsAsset and classes related to those; all can be viewed in the zip I mentioned before.

(vitaly) #5

Thanks for the tip. I was able to find the code and find the needed class. However to fix this I needed to recompile the runtime TileEd library where I have added static properties for instance of each TileEdTileSetsAsset and TileEdPropSetsAsset classes. So it seems that currently your library misses that functionality. I think that it will be helpful if you add 2 new properties to the TileEd global class such as tilesAsset and propsAsset which will contain reference to the corresponding TileEdTileSetsAsset and TileEdPropSetsAsset classes. This also would not require to recompile the runtime dll.
Currently I have also found a workaround to the described issue. At first I’ve tried ScriptableObject.Find… functions but they did not return the mentioned classes instances. Then I’ve wrote my own function which works correctly:

public static T SearchWithinAll() where T : ScriptableObject
    T returnType = default(T);
    var types = Resources.FindObjectsOfTypeAll();
    if (types != null)
        foreach (var t in types)
            if (t is T)
                returnType = t as T;

    return returnType;

and use it like this:

TileEd_Ed_Props.onPlacedProp += TileEd_Ed_Props_onPlacedProp;
private static void TileEd_Ed_Tiles_onPlacedTile(TileEd_Ed_Tiles.PlacedTileInfo obj)
    TileEdTileSetsAsset tileAsset = SearchWithinAll();
    if (tileAsset != null)
       // execute some action.