![]() In the loop I iterate from 0 up to the x textureSize: for(float x = 0.0 x <= pal_size x += pixel_size). ![]() I am not sure about the number that comes out of textureSize(base_palette, 0).I am happy with the end result (It works!), but I am not totally comfortable with using a loop to look for the base color for EVERY pixel of the sprite.Then I read the color from the new_palette that is in the same pixel position. To be able to find the replacement color, for every pixel, I search the original color with a custom function called find_color_in_base_palette, which loops the base_palette looking for the color (the function returns the x position of the color). New palette + sprite with colors replaced (shader running) - don't mind the saturated colors, I chose them to be easier to see the shader at work: With this shader I don't need to create any sprite masks, I can use the original sprites. SetSkin("#INSERT DEFAULT TILE PALETTE NAME HERE#") įor(int x = (int) x ("Spritesheets/" + name) ĥ) And there you go! Now, any time you need to change the skin/season/tilesheet, just use a reference to the Grid's Reskinner script, and call the SetSkin method, like so: Reskinner reskinner = gridObject.I wrote a simple canvas_item shader that gets an input base palette (the original palette of the sprite) and a new palette (the replacement palette) and correctly replaces the original colors with the new colors. Public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)Ĥ) Attach this Reskinner script to your Grid object: using System Public class ReskinnableTileBase : TileBase Now, create a script called ReskinnableTileBase: using System.Collections You can use as many TilePalettes as needed, as long as they are children of the Grid object. Draw all of your scenery, collision, etc. I also tried adding a Grab Pass after the first pass (palette swap) and using that texture to show the lighting on top of it in the next pass. I tried digging into the 'CombinedShapeLightShared.HLSL' and create a custom one to work with lighting but that also didn't seem to help. ![]() The next step is to create a Grid object with a child TilePalette. Atleast, the palette swap works but it doesn't respond to lighting. Finally, run the scene and each spritesheet's sprites will be renamed to make each corresponding sprite have the same name.ģ) We now have each of our seasons' tilesheets modified so each tile is identically named. Set the newName field to whatever you want, it will be the prefix for the name of each sprite in each spritesheet. Drag and drop your spritesheets into the Texture2D array. TextureImporter.spritesheet = sliceMetaData ĮditorUtility.SetDirty (textureImporter) ĪssetDatabase.ImportAsset (path, ImportAssetOptions.ForceUpdate) Īttach it to an empty GameObject in an empty Scene (just for simplicity). Public class SpriteRenamer : MonoBehaviourįoreach(Texture2D texture2D in texture2Ds)", index) ![]() Inside of resources, create a folder "Spritesheets", and place your spricesheets in it.Ģ) Run this renaming script: using UnityEngine When you are finished, create a folder "Resources" in your "Assets" folder. Each tileset should be organized the same exact way (bushes/trees/objects should be in the same spot on every season's tilesheet). Import your tilesets as multi-sprite spritesheets, and split them using the Unity sprite editor. Here's what I came up with, and it's not too complicated.ġ) Create your tilesets. However I found myself digging through years-old forum posts to come up with my solution. This problem seems significant enough that Unity docs would cover it. How would said user switch between their tile palettes programmatically, instead of using a wasteful solution like prefab tiles? Scenario: User has different tile palettes for each season (Summer, Fall, etc.) and switching between the two using popular Unity techniques would be tedious if the number of tiles in the tileset is greater than 5 or 10.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |