Create Rule Tiles in SECONDS in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

While this is definitely useful, I honestly prefer just using the Rule Tile Overrides. Seems more practical to me and gives me more control.

👍︎︎ 1 👤︎︎ u/VeryConfusedOne 📅︎︎ Aug 26 2021 🗫︎ replies
Captions
if you have ever worked with rule tiles in  unity before you know how much pain in this   is to set them off dragging all of the sprites  in and setting the rules can take more than 10   minutes for each individual file taking away  a lot of time from the level designing process   well you can now say goodbye to this method of  creating them because in this video i'm gonna show   you how you can create them literally in seconds  using a custom editor tool which we'll be making the tool is gonna have three main functions  first it will create a list of neighbor rules   these arrows from a list of template images then  it will use the template and list of our sprites   to generate the rule tile and finally it will  save it to our assets so we can use it in game   we'll start by creating a new script for our  editor window i'm going to call this rule   tile generator but you can call it whatever you  like the first thing we will do is to delete the   through default function class and add the using  unit editor and using unit engine the tilemaps   text to the top of the script after we've added  the using tags we can change the money behavior   to the serving now the show our editor window will  need two methods one to open the window and one to   show content in it the function which will display  content in the editor window needs to be called on   guy the function which will be reveal our editor  window can be called anything i'm going to call   it show window inside you will need to write  a get window function with the class and the   name of the window we also need a way to execute  this function from the editor so we are gonna add   the menu item attribute before the function this  will add the button to the top menu row in unity   now that we are done with the setup we can start  programming our editor window we will start with   the scroll view so scroll bar we appear when  the window will be too small to show our content   after that we can add the label so things look  nice and then comes a little complicated part   we need to display a list of sprites so we can  later use them to get the neighbors of the tiles   but the problem is that by default  there's no way to show an array   or a list in a custom editor luckily we can use  a fairly simple workaround which you can see now   you'll need to put your variable in the fight  property function as a string this will display   the variable like it would in the default  inspector just make sure your variable is public   one frustrating thing that unity does is that  your sprites need to be marked as read and   write enabled in order to get data from it so  we can add a little hail box to tell the user   now that we have our list ready we can add the  button to use that list and get the neighbors   one last thing we can do to make this editor  more clean is to only show this section   if our navy rules have not been set yet so we  can put all this code inside an if statement   time to get the neighbor rules from our template  image first we'll create a neighbor list and reset   it inside a method the rule of thumb uses a list  of integers for each tile to specify what rule to   put in what position but just using positions in  random order wouldn't work out we need to set them   in the exact same order as the tile does it could  make a diameter and get the list of positions   but the very simplest solution is just to copy  the list and paste it in our script now that   everything is set up we can make a forage loop  to get the rules for every sprite in the template   sprites list inside the for loop we will create  a temporal list for our integers for our rules   then we can use the pixel colors from the  sprite to set the rules but it's not that simple   because if the sprite is sliced which  most likely is because of the tile maps   despite the texture we return the entire image  not just that section so first we need to get   the rect of the slice get the colors then create  a new structure with the dimensions of the slice   and apply the colors to that texture we  can now use this texture to set the rules   we'll loop through each of the neighbor positions  we'll check the pixel based on the position if the   position is minus 1 the pixel coordinate will be 0  if the position is 0 the pixel coordinate will be   half of the texture size and if the position is  1 the pixel coordinate will be the texture size   we'll do this for both the x and y coordinates  then we can just use the pixel coordinate to   get the pixel color if the color is white  we'll set the rule to any if the color is   green we'll set the rule to this and if the  color is red we'll set the rule to not this   after we move through all of the position and  got the rules we can add the temporal list to   the list of neighbor rules one last thing we can  add to this function is to get a default image   for the style the default image will be that one  which doesn't have neighbors before the second for   each loop let's set the boolean with a different  value of true this boolean will be set to force   if the current rule contains at least one green  pixel if the bool is still true after the loop   we can save the index to a variable don't forget  to increment the index because we're using for   each loop not a for loop the hardest part is now  then let's go back to the own gui function after   our neighbor who's our setup we can display the  next options we can check the length of the array   to check if we already load the template or not if  the template is loaded we can display some preview   of it as this tutorial is not about editor windows  i don't want to waste time with it but there's if   anyone is interested maybe if enough people want  a more detailed explanation i can make a tutorial   about it let me know in the comment section if  you do anyway back to the tiles now we can show   another array of sprites but this time it's for  the actual tiles as we don't want any trouble   with the system we'll check if the length of  the templates writes is the same as the length   of the tiles if no let the user know why we don't  allow them to proceed if yes we can continue with   our code a tile has a bit more variable design  setting than just the rules so let's add some   input fields for the default type the collider  type the game objects and the name of the file   we'll create these variables somewhere else in the  script we can also add the default sprite which we   set up in the load template method and finally  let's add the button to generate the rule tile   we're done with our own gui method so let's create  the save tire and the generator vulture methods   let's set our value of the switch we set in the  on gui method and create the generate rule-type   function in a function the first thing we'll do  is to create an instance of a rule-type scriptable   object after that we can set up the default sprite  the default collider and the default game object   for the tiling room we'll loop through the title  sprite with a for loop first we'll create a new   tiling row then set the sprite as the tile can  be animated it uses a sprite array instead of a   single sprite this isn't going to be animated so  we can just replace the first sprite in the array   we can now set the corresponding neighbor rules  set the collider type and set the default game   object we can add the tiling rule to the list  of tiling rules in the rule tile and finally we   return our new generated tile we'll take the  style and put it in the save tile function   this function is even simpler than the previous  one first we will save the asset in our desired   location and then we'll focus on the save  the set in the project window and we are done   let's try it shall we we can open the window  with the menu item we specified in the script   you can find it at the top of the unity window  now we need to add our templates to the list if   you do that one by one we wouldn't save a lot of  time with it but luckily because this is a list we   can just shift select all of the sprites and drag  them in all at once once we are done we can click   on the button to load the template after that  we can do the same thing with the tile sprites   you can change the settings rename the sprite and  we can fly and click on the generate tile button   if you already had the time plate before this  process shouldn't take you more than just a minute   or even half a minute and if you don't have a  template don't worry i'll provide you one in   the description down below so far this tool has  shown us how much time it can save us but let's   actually compare it to a traditional method of  creating a rule tile we'll compare the tool to   creating a new tire by hand and using an existing  tile to create a different one ready set go and the templates are already set up let's rename the tile and generate it with the tool it only  took us 24 seconds to create a tile   that's that's something let's speed it up a little  bit because our other two methods are quite slow we finished replacing the tires  in 2 minutes and 44 seconds   that's not horrible but it's definitely slower  than the tool let's speed it up even more our traditional method of creating ruler is  finally done it took us almost 12 minutes to   create a new rule tile compared to the tool it  took ages as you can see with the tool creating   a new rule tile only takes seconds which  will save you a ton of time in the future   that's it for this tutorial if you found it useful   please consider liking the video and  subscribing to the channel see ya you
Info
Channel: Vinark117
Views: 576
Rating: undefined out of 5
Keywords: Unity Tutorial, How to make tiles fast, Create tiles in seconds, Create tiles fast, how to, unity, tutorial, rule tiles, unity rule tiles
Id: yI8fMXbtjew
Channel Id: undefined
Length: 11min 7sec (667 seconds)
Published: Wed Aug 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.