Created
March 8, 2020 17:17
-
-
Save matheusmessora/425cbdfab455e574a93b822b37a46868 to your computer and use it in GitHub Desktop.
Unity Editor script to export Tilemaps (x,y) position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEditor; | |
using UnityEngine; | |
using UnityEngine.Tilemaps; | |
[CustomEditor(typeof(Tilemap))] | |
public class CollisionsScript : Editor | |
{ | |
private Tilemap tilemap { get { return (target as Tilemap); } } | |
public BoundsInt area; | |
public override void OnInspectorGUI() | |
{ | |
DrawDefaultInspector(); | |
if(GUILayout.Button("EXPORT")) | |
{ | |
Debug.Log("APERTOU"); | |
BoundsInt bounds = tilemap.cellBounds; | |
TileBase[] allTiles = tilemap.GetTilesBlock(bounds); | |
for (int x = 0; x < bounds.size.x; x++) | |
{ | |
for (int y = 0; y < bounds.size.y; y++) | |
{ | |
TileBase tile = allTiles[x + y * bounds.size.x]; | |
if (tile != null) | |
{ | |
Debug.Log("x:" + x + " y:" + y + " tile:" + tile.name); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on:
https://gamedev.stackexchange.com/questions/150917/how-to-get-all-tiles-from-a-tilemap