Lynda.com: Become a Unity 2D Developer (Day 4)
UNITY 5: 2D BUILDING A TILE MAP EDITOR
According to the tutorial instructor, Jesse Freeman, this course will focus on understanding how to use the Tile Map Editor extension for Unity. Obtaining a strong foundation with the Tile Map Editor will enable me to create a tile map class, custom tile picker, a tile brush, along with creating custom menus.
This particular exercise was more or less a preview of what is to come. Nevertheless, I was able to add a custom menu option, specifically GameObject -> Tile Map. Luckily for me, it worked as expected. Not only did the menu option populate, it executed the code to add a Tile Map layer. Also, for the sake of showing work, I will include an alternate menu option that is very much "troll thing to do". **Did I just admit to hack'n my own application menu? It just renders an option titled as "Cereal Time!"**
Building a Custom Inspector
Creating a custom inspector item was fairly simple. The C# script was able to utilize the #UnityEditor and TileMapEditor class, which allows the option of creating a custom inspector GUI value.
Reading Sprites from a Texture
This lesson has been broken into 5 parts: Creating a Texture Picker, Showing a Warning Message, Calculating Tile Size, Calculating the Map Size, and Dynamic Pixels to Units. With that out of the way, onward with the lesson.
Creating a Texture Picker
It is safe to assume from herein, I will be utilizing C# scripts to modify all components of Unity. This lesson sorta flew over my head. This C# script modifies the Tile Map Inspector window to include a Texture Picker option. (located on lower right-hand side of Inspector palette image.)
Showing a Warning Message
You know how there are some titles that give it all away. Well, that is the case here. Showing a Warning Message is literally an exercise to display a warning message when something is wrong. In this case, it is a message when a texture is missing or simply unavailable.
Calculating the Tile Size
Pulling on the thread from the exercise above, the next step is to write a script that is able to determine the size tile that is being loaded. Notice on the example above, there is a field for Tile Size but with a value of "0x0". The displayed value does not reflect the attributes of the loaded texture image.
Using the C# scripts below, whenever a texture is loaded, it will display the dimensions of the loaded texture.
Calculating the Map Size
Setting up the script for determining the size of the grid was a matter of developing a formula and applying it within the code. Granted, I'm no math wiz so I'm glad this is just me following a tutorial. In any case, below is a screenshot of the C# script along with the successful outcome. Admittedly, this took a while to get working. There were a few typos that rendered the code useless. Quite disastrous when my code came to a screeching halt due to a misplaced comma.
Dynamic Pixels to Units
This tutorial was a bit of eyebrow raiser. With that said, I was a bit lost in regards to it's application, until the very end. Ultimately, this enables the developer/designer to ensure that the images loaded are correctly listed in regards to units of measurement.
According to the tutorial instructor, Jesse Freeman, this course will focus on understanding how to use the Tile Map Editor extension for Unity. Obtaining a strong foundation with the Tile Map Editor will enable me to create a tile map class, custom tile picker, a tile brush, along with creating custom menus.
This particular exercise was more or less a preview of what is to come. Nevertheless, I was able to add a custom menu option, specifically GameObject -> Tile Map. Luckily for me, it worked as expected. Not only did the menu option populate, it executed the code to add a Tile Map layer. Also, for the sake of showing work, I will include an alternate menu option that is very much "troll thing to do". **Did I just admit to hack'n my own application menu? It just renders an option titled as "Cereal Time!"**
Building a Custom Inspector
Creating a custom inspector item was fairly simple. The C# script was able to utilize the #UnityEditor and TileMapEditor class, which allows the option of creating a custom inspector GUI value.
Reading Sprites from a Texture
This lesson has been broken into 5 parts: Creating a Texture Picker, Showing a Warning Message, Calculating Tile Size, Calculating the Map Size, and Dynamic Pixels to Units. With that out of the way, onward with the lesson.
Creating a Texture Picker
It is safe to assume from herein, I will be utilizing C# scripts to modify all components of Unity. This lesson sorta flew over my head. This C# script modifies the Tile Map Inspector window to include a Texture Picker option. (located on lower right-hand side of Inspector palette image.)
Showing a Warning Message
You know how there are some titles that give it all away. Well, that is the case here. Showing a Warning Message is literally an exercise to display a warning message when something is wrong. In this case, it is a message when a texture is missing or simply unavailable.
Calculating the Tile Size
Pulling on the thread from the exercise above, the next step is to write a script that is able to determine the size tile that is being loaded. Notice on the example above, there is a field for Tile Size but with a value of "0x0". The displayed value does not reflect the attributes of the loaded texture image.
Using the C# scripts below, whenever a texture is loaded, it will display the dimensions of the loaded texture.
Calculating the Map Size
Setting up the script for determining the size of the grid was a matter of developing a formula and applying it within the code. Granted, I'm no math wiz so I'm glad this is just me following a tutorial. In any case, below is a screenshot of the C# script along with the successful outcome. Admittedly, this took a while to get working. There were a few typos that rendered the code useless. Quite disastrous when my code came to a screeching halt due to a misplaced comma.
Dynamic Pixels to Units
This tutorial was a bit of eyebrow raiser. With that said, I was a bit lost in regards to it's application, until the very end. Ultimately, this enables the developer/designer to ensure that the images loaded are correctly listed in regards to units of measurement.












Comments
Post a Comment