From the course: Unity 5: 2D Building a Tile Map Editor

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Calculating tile size

Calculating tile size

- So now that we're displaying the tile size, we need to actually get the value. In order to do that, we're going to use the AssetDatabase to load up the texture2D into memory, and then read all the attached sprites attached to it. To get started, we're going to need to go back into our TileMap class. Here we're going to create an array that'll store all the references attached to a texture2D. The way that we read this from the AssetDatabase it'll return an object array. So let's create a public field called spriteReferences typed to an object array. Next in the TileMapEditor, we're going to use the OnEnable method in order to read all of the sprites attached to the texture2D whenever we select a TileMap. Let's test that the texture2D actually exists on the TileMap before we try to read its contents. Once we know that this exists, we need to get a path to the actual texture2D asset. Here, we're going to use a static method on the AssetDatabase class called GetAssetPath and we'll pass…

Contents