Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Super Tilemap Editor

Discussion in 'Assets and Asset Store' started by CreativeSpore, Feb 21, 2016.

  1. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    58
    Hi I have been exploring the asset some more, one difference with tiled that I wanted to fix and couldn't find out how to do it directly is treat the empty tiles as if they were repeating the tile next to it. Mainly to allow nice borders in our maps.

    This is how it currently works:

    Screen Shot 2016-09-14 at 14.27.16.png

    and I would like for it to work like this:

    Screen Shot 2016-09-14 at 14.27.25.png

    I was able to change the code of CarpetBrush, to allow painting like in the second case by adding an option of treating neighboring empty tiles as the same brushId as the current one.

    If this is something anyone is interested in I can share the patch.
     
    CreativeSpore likes this.
  2. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Probably I will add another eAutotilingMode value for autotiling with empty neighbor tiles.
     
  3. years1hundred

    years1hundred

    Joined:
    Sep 3, 2016
    Posts:
    7
    Thank you so much for replying to my question! I really appreciate!

    As it is, I apologize for my poorly-worded question. Basically, I was wondering - can you have multiple colliders on each sprite tile?

    For example, as I briefly mentioned previously, I'm working on a game similar to that of a top-down shooter.
    https://gyazo.com/665b0e2a4e36043e50f6599b502d8f3b

    So it would be amazing if each sprite tile could have both a "floor" collider (something for the player character to stand on), as well as like "wall" colliders.

    If that is indeed the case with your tilemap editor, I have a further question - when you show something like this (http://forum.unity3d.com/attachments/scenecollideredition-gif.202020), can you customize colliders like that for both the walls and the floor?

    Again, sorry if what I'm asking is confusing - I'm having a hard time explaining what I'm thinking in my head.
     
  4. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    I think I understood you this time.
    Generated colliders using 3D (that internally is using a collider mesh) are generated as quads perpendicular to the tilemap local Z axis. It means, in a top-down game, they are used to generate the wall colliders, not the floor.
    But you can add the floor collider attaching a prefab to the wall tile with the floor collider.
     
  5. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    Looking fantastic, I can't wait to give it a try!
     
  6. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I have noticed some white lines from time to time between my tiles when moving, they are only there for a frame and don't appear too often, has anyone experienced something similar?

    Anisotropic filtering and antialias is turned off.
     
  7. nodoxi

    nodoxi

    Joined:
    Feb 27, 2013
    Posts:
    9
    CreativeSpore, it would be great to have possibility to edit color map like in 2D Toolkit Tilemap.

    What is your texture filter mode? Set it to point(no filter).
     
  8. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    All of my textures are already set to point
     
  9. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    It could be a texture UV precision error where a neighbor pixel in the atlas is taken.
    I have plans to add padding pixels between tiles in the atlas but right now the best options to avoid that is:
    • Setting an Inner padding in the Tilemap Render settings above 0 and below 0.5 would be fine. It depends on the zoom level
    • Activating Pixel Snap
    • Using a pixel perfect camera with a zoom and position snapped to the pixel size according to the view resolution.
     
  10. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    58
    Hi, I am using the CarpetBrush brush to draw our terrains but in our case we want random tiles for most positions in the brush, not just randomizing the center.

    From what I could see you need to first import the brush into the tileset before being able to add it as a random brush in the terrain brush. This means that we would end up with a ton of brushes that are never meant to be used directly in the brush palette.

    I can think of two ways to solve this:
    * add a property to brushes that lets you mark them as not visible in the brush palette
    * add a category to brushes and have the brush palette group brushes by category.

    maybe being able to add names to the brushes in the tile palette or tilemap paint inspector would also help a bit.

    Thanks for your help
     
  11. Spyder638

    Spyder638

    Joined:
    Sep 4, 2014
    Posts:
    6
    Hey, CreativeSpore. You helped me out the other day in the YouTube comments section about finding colliders in tilemaps. I went back and tried again using your advice and with much joy it worked!

    What I've been using this for is to send the colliders into a pathfinding asset called Poly|Nav, which currently only supports PolygonCollider2D. This means I've had to use PolygonCollider2D for walls...

    The combination of assets at first glimpse seemed to work brilliantly, once I got past a couple of niggles with Poly|Nav. However, upon further experimenting with both tools in combination, I run into a really weird (to me!) issue where my agents would be able to walk through vertical-running walls, but not horizontally-running walls:

    This shows the type of wall the agent would walk through.
    This shows the type of wall the agent wouldn't walk through, and properly avoid.

    I've asked about this in the Poly|Nav thread but I'm starting to suspect the cause of the issue is with how this asset generates the colliders. Would you have any insight into why something like this would happen, and if so, how I can if possible avoid it?
     
  12. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    I have added a new property in the brushes ShowInPalette to display them or not in the brush palette.
     
  13. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Could you try showing the tile chunks activating the option Show Tile Chunks found in the section Map of the tilemap?
    This will allow you to debug the polygon colliders and see why it is not working.
    For a wall like that it should create a polygon collider with 4 vertices, one per each corner.
     
  14. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    58
    Hi CreativeSpore, thanks a lot for the fix, is there any place where you leave latest versions so we can try these fixes before them reaching the asset store?

    Thanks for everything.
     
  15. Spyder638

    Spyder638

    Joined:
    Sep 4, 2014
    Posts:
    6
    If I recall right that wasn't happening. There would be 1 vertice per tile corner.
     
  16. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    The last version of Super Tilemap Editor v1.4.0 is available now!

    Change log:
    • Added support to edit tile colliders directly in the scene view when Colliders tab is selected
    • Added PhysicMaterial and PhysicMaterial2D property to tilemaps
    • Added support to edit multiple brushes
    • Changed the way a tilemap is highlighted when it's a child of a tilemap group
    • Added tilemap event OnMeshUpdated
    • The current selected tilemap colliders are now updated when the tile colliders are modified in the Tile Property Window
    • Fixed tilemap IsTrigger setter
    • Fixed some collider 2D generation issues
     
  17. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    What version of STE do you have? Try updating to the last version. There should be only a vertex between two extremes of a collider line when using 2D colliders.
     
  18. Spyder638

    Spyder638

    Joined:
    Sep 4, 2014
    Posts:
    6
    Will do! I was unaware there was a newer version than the one I have currently. Thank you!
     
  19. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Yes, I have the vertex color edition in the road map.
     
  20. Robosaur

    Robosaur

    Joined:
    Jan 21, 2014
    Posts:
    6
    Yo, how would I make each tile have a "default" list of parameters? I don't want to have to re-add my parameters manually to every tile...
     
  21. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    The update is amazing, thank you so much!
     
    CreativeSpore likes this.
  22. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    I want to improve this in a future release.
    Right now you could create a script to add the same parameters to all tiles.
    For example, if you go to TilesetEditor.cs and look for OnInspectorGUI you could add this button to achieve that:
    Code (CSharp):
    1. public override void OnInspectorGUI()
    2. {
    3.     Tileset tileset = (Tileset)target;
    4.     serializedObject.Update();
    5.  
    6.     //Custom code to add default parameters
    7.     if (GUILayout.Button("Apply default parameters"))
    8.     {
    9.         foreach (Tile tile in tileset.Tiles)
    10.         {
    11.             tile.paramContainer.AddParam("MyFloatParam", 1f);
    12.             tile.paramContainer.AddParam("MyIntParam", 5);
    13.             tile.paramContainer.AddParam("MyBoolParam", false);
    14.             tile.paramContainer.AddParam("MyObjectParam", null);
    15.         }
    16.         serializedObject.Update();
    17.     }
    18.  
    19.     // Rest of code
    20.  
    21. }
     
  23. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    None of these seem to help.

    Pixel snap seems to introduce gaps between my sprites where the red line of the Tilemap grid appears

    Setting a padding between 0 and 1 doesn't seem to make a difference, and i have also tried a pixel perfect camera.

    Here is what the artifact looks like, they can appear horizontally as well.
     
    Last edited: Mar 26, 2018
  24. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    606
    I have this problem (maybe bug) where I am instantiating a gameobject (that contains multiple tilemaps) and it does not render.

    Code (csharp):
    1.  
    2. GameObject newLevel = Instantiate(CurrentLevel.GetLevel()) as GameObject;
    3. newLevel.transform.SetParent(levelHolderTransform, false);
    4.  
    This works the first time it's instantiated, but if I delete the game object, and recreate (i.e. reset level) nothing will render. If I manually disable and enable the object in the inspector it will show up.
     
  25. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Hi,
    I see for your gifs you are using parallax tilemaps. Even using a pixel perfect camera, you still need to snap the positions of the elements in the scene.

    I guess the artifact is because a line of pixels is not being rendered. This happens when pixel snap is enabled.
    I think if the pixels are too close to 0.5f, sometimes, for float imprecision, a pixel falls in the next int, and the next falls to the floor.
    So, to avoid pixel artifacts in this I would disable pixel snap and set the inner padding to 0.5, for example, and reduce the value until you don't see any artifacts.

    For the next version of STE I will add a tool to add padding between tiles extruding the color, so pixel snap won't be needed neither inner padding.

    Let me know if you still have issues with this after trying my suggestions.
     
  26. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I'm not using parallax tilemaps, the parallax backgrounds elements are just sprites, i only use one tilemap for the terrain i can walk on.

    I'm already not using pixel snap because it introduces an even worse artifact (the first gif)

    In the second gif there is no pixel snap and i have tried an inner padding between 0.1 and 0.5 with no improvement.

    I also would prefer not to use a pixel perfect camera because it makes parallax backgrounds scroll less smoothly.

    I'll wait for the updated version to see if your solution works, let me know if you have other suggestions or if you need me to do some tests for you.
     
  27. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    What are you instantiating? a prefab with a tilemap group or something else? I fixed a bug similar to this one in previous version. Are you updated to the last version?
     
  28. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    It would be helpful to know if in the second gif the artifact is because of a transparent pixel or because it's rendering a pixel of the neighbor tile.
     
  29. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    606
    Yea, Basically something like this:

    Level1 - Tilemap group
    Ground Tilemap
    Foreground Tilemap
    Other game objects (non-tilemap)
    The other game objects (sprites) will show up, but the tilemaps don't until I enable/disable the root level element in inspector. I've tried to enable/disable via code but only doing it manually in the inspector works. I believe I have the latest version, just downloaded it 4 days ago.
     
  30. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I'm trying to isolate the issue but it happens randomly and rarely so it's a bit difficult to pinpoint

    I've made an empty test scene with a panning camera and a tilemap, the lines appear with or without transparency, using a simple Sprite/Default material.

    With transparency:



    Without transparency:






    I'm not sure what else to try
     
  31. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    Have you tried to add "same pixel borders" around each of your tiles (i.e add 1px border outside the tile that are of the same color as the current outer pixels)?
     
  32. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I have replaced the spritesheet with a completely black image with no transparency, it still happens.

     
  33. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    Tried slightly changing the size of the tile cells?

    I don't know if it is from the videos, but the pixels look to change size a lot. Maybe change to sprite pixel size or camera settings that are "closer" to pixel perfect settings? Ultimate that is probably at the bottom of the problem. Your sprite pixel size related to screen pixel size to me seems way off.
     
  34. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I have tried a pixel perfect setup before and it didn't help, it also makes everything look jittery when in motion which i didn't like.
     
  35. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    Movement should not be related to pixel perfect. Something else may be causing movement problems.
    Anyway, try cell sizes.
     
  36. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I have tried different cell sizes values and it still happens, it doesn't seem any different from changing the inner padding value but i could be wrong.

    About the pixel perfect thing, i'm probably just doing something wrong, it seems a bit complicated to get right.
     
  37. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    I have created an example to try to replicate this bug but I couldn't, even adding other dummy game object to the tilemap group.
    This is the code I used to test:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TestBugWithTilemap : MonoBehaviour {
    5.  
    6.     public GameObject TilemapPrefab;
    7.  
    8.     void Update () {
    9.  
    10.         if (Input.GetKeyDown(KeyCode.A))
    11.         {
    12.             GameObject level = Instantiate(TilemapPrefab) as GameObject;
    13.             level.transform.SetParent(gameObject.transform, false);
    14.         }
    15.  
    16.         if (Input.GetKeyDown(KeyCode.D))
    17.         {
    18.             Application.LoadLevel(Application.loadedLevel);
    19.         }
    20.    
    21.     }
    22. }
    23.  
    Are you updated to the last version? What version of Unity are you using?
    Anyway, if you call UpdateMesh for all the tilemaps in the tilemap group, they should be refreshed, but it's strange it's not working.
     
  38. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Could you send me a text project, it can be with the black texture, so I can check it myself and try to find the cause and solution?

    Can I see the importing settings of the texture? And what quality mode are you using in the editor and Unity version?
     
  39. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    I'm sending you a test project, just know that it doesn't happen often, press play and look at the panning screen, you should see white lines from time to time.
     
  40. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    606
    Problem goes away if I call UpdateMesh on the tile.

    I think problem may be that the tilemaps are 'reloading' before the old ones are removed.

    Here's some code to better describe the issue:

    Code (csharp):
    1.  
    2. //unload current map
    3.   foreach (Transform child in levelHolderTransform)
    4.   {
    5.   Destroy(child.gameObject);
    6.   }
    7.  
    8. GameObject newLevel = Instantiate(LevelPrefab) as GameObject;
    9.   newLevel.transform.SetParent(levelHolderTransform, false);
    10.  
    11.  
    So maybe it's an issue where Destroy doesn't get called until the next Update loop, and the new tilegroups are being created before the old ones are destroyed. However don't see why it would cause the new ones the stop rendering.
     
  41. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Thanks for posting the code, I could replicate it now. It happens only the first time when you reload the prefab, in my case, and it works fine the next times.
    The cause is because the mesh of a tilemap is not saved with the asset, so, to create the preview of a tilemap, the mesh needs to be created.
    When you press play in the editor, the OnValidate event force the prefab object to create a mesh for the tilemap.
    Then you instantiate the prefab and the instantiated tilemap takes the same reference to the mesh the prefab has.
    For other side, the tilemap only refresh the mesh (creating a new one is needed) is the mesh is null when OnEnable is called, but when you create the new tilemap, the mesh is not destroyed yet, so the mesh is not updated. Then, later, the first tilemap is destroyed and the mesh is manually destroyed (I do this is the OnDestroy method to avoid the Unity warning about leaked objects).
    So this is the reason because the second time you instantiated the tilemap, the mesh is not updated and removed.
    The next time you instantiate a tilemap, the prefab has a null mesh so it refreshes the mesh.

    So, you should destroy the tilemaps using DestroyImmediate to avoid this or force a refresh, calling Tilemap.Refresh method.
     
    Last edited: Oct 13, 2016
  42. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
    This looks interesting, could I implement a game like https://www.factorio.com with it? Am I right that the properties are only per tile-type, not individual for each placed tile on the map? How would I implement e.g. that a coal-tile can have x tons of coal, and it gets reduced when you mine it, but of course, only the one tile which you mine? And how would I program a factory, which has a list of different resources and products which are in the factory at a given time? Would be nice if I could attach a C# object to individual tiles on the map, if this is not possible already.
     
  43. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
    Ok, I bought it, looks good so far. Minor bug in the PDF documentation on page 11: it is not "Window/SuperTilemapEditor/Tile Properties Windows", but "SuperTilemapEditor/Window/The Properties Window".
     
  44. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Yes, you can only add a property to a tile, not to a tilemap cell position. In my opinion, to add a tile with coal I would use a prefab attached to that tile. You could need more logic than just manage the amount of coal. To make it easy, you can use the component TileObjectBehaviour. This component, attached to a prefab will replicate the tile used to instantiate it.
    For the factory is the same, use a prefab with a component to manage the factory and the resources contained in it.
    If you need more help don't hesitate to send me an email.
    Thanks for telling me about the documentation error, I will fix it ;)
     
  45. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
    Thanks, the TileObjectBehaviour was helping me. I created an empty GameObject and put it in a new prefab. Then I attached the script below to the GameObject and set the prefab to a tile, and enabled "show tile with prefab". The script creates a BoxCollider, so that OnMouseDown is called when pressing the tile.

    I needed some time to figure out that some parts of my script are running in edit mode, because I'm new to Unity (and C#, and game programming, have done mostly Java business applications so far), but with the "SerializeField" attribute I managed to serialize the tile position and the tilemap (I guess it serializes only a reference to the one tilemap) so that it was available at runtime, too. Now I can click on the tile and it disappears if there are no more coals left.

    Is the UpdateMesh function fast for large maps, or should I use your method to create a sprite and then delete this sprite? Problem is I might have lots of such tiles, so then it might be slower to display them all as sprites instead as optimized tiles.

    Some more confusion was when the prefabs gets updated. If I hit the "Refresh Tilemap" button, the prefabs are created, but if they are already created, they are mixed somehow. For example, first I created a BoxCollider2D with the script, then changed it to BoxCollider and refreshed the tilemap, but the BoxCollider2D was still there. Don't know if it is a good idea to delete all prefabs when hitting the refresh button, because it is a really nice feature that you can change the individual prefabs in the scene. Maybe another button "refresh with prefab re-creation" or "re-create prefabs" or something like this? Then I don't have to do it manually in the scene when I update a script attached to a prefab.

    Maybe you should make another video about this prefab feature and how to do something interesting when clicking on a tile. This is a really useful feature many people need, and beginners like me don't see how to do it at first by reading the documentation or watching your videos, but maybe I missed it somewhere. Feel free to use my code, or improve it :)

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using CreativeSpore.SuperTilemapEditor;
    5.  
    6. public class CoalTest : MonoBehaviour
    7. {
    8.     float displayTime;
    9.     string info;
    10.  
    11.     int coals = 3;
    12.  
    13.     [SerializeField]
    14.     int GridX;
    15.  
    16.     [SerializeField]
    17.     int GridY;
    18.  
    19.     [SerializeField]
    20.     Tilemap ParentTilemap;
    21.  
    22.     void OnMouseDown()
    23.     {
    24.         if (coals > 0)
    25.         {
    26.             coals--;
    27.             info = "coals left: " + coals;
    28.             if (coals == 0)
    29.             {
    30.                 ParentTilemap.Erase(GridX, GridY);
    31.                 ParentTilemap.UpdateMesh();
    32.             }
    33.             displayTime = 2;
    34.         }
    35.     }
    36.  
    37.     void OnTilePrefabCreation(TilemapChunk.OnTilePrefabCreationData data)
    38.     {
    39.         GridX = data.GridX;
    40.         GridY = data.GridY;
    41.         ParentTilemap = data.ParentTilemap;
    42.         BoxCollider bc = gameObject.AddComponent<BoxCollider>();
    43.         bc.size = new Vector2(data.ParentTilemap.CellSize.x, data.ParentTilemap.CellSize.y);
    44.     }
    45.  
    46.     void OnGUI()
    47.     {
    48.         if (displayTime > 0)
    49.         {
    50.             displayTime -= Time.deltaTime;
    51.             int cx = Screen.width / 2;
    52.             int cy = Screen.height / 2;
    53.             GUI.Box(new Rect(cx - 200, cy - 40, 400, 80), info);
    54.         }
    55.     }
    56. }
    57.  
     
    Last edited: Oct 13, 2016
  46. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
    PS: creating the BoxCollider in the Start() method avoids creating multiple BoxColliders whenever you hit the refresh button.
     
  47. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    Good work to be new to Unity and C# game programming!
    Answering your questions:
    UpdateMesh is fast enough even in big maps because it only updates the modified chunks (the tilemap is subdivided in chunks of 60x60 tiles). Also, it is done only once during the next update, unless you call UpdateMeshImmediate.
    But if you are going to have a lot of tiles with resources like this, it could be a problem to instantiate so many sprites, so you could create a resource manager instead and place it out of the tilemap in a single gameObject called RecourceManager, for example.
    And use a code like this:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using CreativeSpore.SuperTilemapEditor;
    5.  
    6. public class TileResourceManager : MonoBehaviour
    7. {
    8.     public class TileResourceData
    9.     {
    10.         public int GridX;
    11.         public int GridY;
    12.         public int coals;
    13.         public string info;
    14.         public float displayTime;
    15.     }
    16.  
    17.     List<TileResourceData> tilesWithResources = new List<TileResourceData>();
    18.     List<TileResourceData> tilesToBeUpdated = new List<TileResourceData>();
    19.  
    20.  
    21.     [SerializeField]
    22.     Tilemap ParentTilemap;
    23.  
    24.     void Start()
    25.     {
    26.         int tileIdOfCoal = 5;
    27.         for(int gy = ParentTilemap.MinGridY; gy <= ParentTilemap.MaxGridY; ++gy )
    28.         {
    29.             for(int gx = ParentTilemap.MinGridX; gx <= ParentTilemap.MaxGridX; ++gx )
    30.             {
    31.                 if( Tileset.GetTileIdFromTileData(ParentTilemap.GetTileData(gx, gy)) == tileIdOfCoal )
    32.                 {
    33.                     tilesWithResources.Add(new TileResourceData() { GridX = gx, GridY = gy, coals = 3 });
    34.                 }
    35.             }
    36.         }
    37.     }
    38.  
    39.     void OnMouseDown()
    40.     {
    41.         int gx = TilemapUtils.GetMouseGridX(ParentTilemap, Camera.main);
    42.         int gy = TilemapUtils.GetMouseGridY(ParentTilemap, Camera.main);
    43.         TileResourceData data = tilesWithResources.Find(x => x.GridX == gx && x.GridY == gy);
    44.         if (data.coals > 0)
    45.         {
    46.             data.coals--;
    47.             data.info = "coals left: " + data.coals;
    48.             if (data.coals == 0)
    49.             {
    50.                 ParentTilemap.Erase(gx, gy);
    51.                 ParentTilemap.UpdateMesh();
    52.                 tilesWithResources.Remove(data);
    53.             }
    54.             else
    55.             {
    56.                 tilesToBeUpdated.Add(data);
    57.                 data.displayTime = 2;
    58.             }
    59.         }
    60.     }
    61.  
    62.     void OnGUI()
    63.     {
    64.         List<TileResourceData> updatedList = new List<TileResourceData>();
    65.         foreach (TileResourceData data in tilesToBeUpdated)
    66.         {
    67.             if (data.displayTime > 0)
    68.             {
    69.                 data.displayTime -= Time.deltaTime;
    70.                 if(data.displayTime > 0f)
    71.                 {
    72.                     updatedList.Add(data);
    73.                     int cx = Screen.width / 2;
    74.                     int cy = Screen.height / 2;
    75.                     GUI.Box(new Rect(cx - 200, cy - 40, 400, 80), data.info);
    76.                 }
    77.             }
    78.         }
    79.         tilesToBeUpdated = updatedList;
    80.     }
    81. }
    By the way, the reason the colliders are mixed is because you are adding the component in the OnTilePrefabCreation event. You should add the collider directly to the prefab object, and set the size to be like a tile.
    You can also create a prefab dragging a scene gameObject to any Project View folder.
     
  48. CreativeSpore

    CreativeSpore

    Joined:
    Nov 6, 2014
    Posts:
    1,190
    I have found the line artifact cause and fixed it.
    These are the lines that need to be modified (only the last two lines) to avoid float errors and line artifacts when camera is not pixel perfect. Pixel snap has to be disabled as well.
    "\CreativeSpore\SuperTilemapEditor\Scripts\Tilemap\TilemapChunk_Renderer.cs"
    Code (CSharp):
    1. private void _AddTileToMesh(Rect tileUV, int tx, int ty, uint tileData, Vector2 subtileOffset, Vector2 subtileCellSize, int subTileIdx = -1)
    2. {
    3.     float px0 = tx * CellSize.x + subtileOffset.x;
    4.     float py0 = ty * CellSize.y + subtileOffset.y;
    5.     float px1 = tx * CellSize.x + subtileOffset.x + subtileCellSize.x;
    6.     float py1 = ty * CellSize.y + subtileOffset.y + subtileCellSize.y;        
    7.  
    I will include this fix in the next update.
     
  49. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    Thank you so much, it seems to be working perfectly, haven't seen another white line, really appreciate the hard work.
     
  50. FrankBuss

    FrankBuss

    Joined:
    Dec 22, 2014
    Posts:
    55
    Thanks, the resource manager idea sounds good, because with a GameObject for each tile, Unity would do a lot of things for each tile with it, e.g. calling Start, Update etc. Nice C# features with the member variable initialization and the find method, reminds me a bit of Scala or Haskell.

    BTW, the Unity interface gets reeeeeeaaaaaally slow when you create a new tileset, then enter 0 for tile size and 1 for padding (x and y the same) on a big image like 2048x2048, then click Slice Atlas. Safe your project before you do this :)