Giter Club home page Giter Club logo

Comments (8)

ChuanXin-Unity avatar ChuanXin-Unity commented on July 27, 2024

The ITilemap functions are callbacks from the Tilemap to the Tile to retrieve information from the Tile.

Instead, you could trigger this from the Tilemap itself by calling either:

  • tilemap.RefreshTile (if you want to refresh specific Tiles at positions)
  • tilemap.RefreshAllTiles (if you want to refresh all Tiles at any position)

from 2d-extras.

blindgoat avatar blindgoat commented on July 27, 2024

Thanks.

That works fine for standard Tiles, but does not work for RuleTile as RuleTile's RefreshTile function requires an ITilemap to use.

For now I'm using tilemap.RefreshAllTiles() but that's horribly inefficient for large Tilemaps. Do you have any suggestions for how to use RuleTile.RefreshTile()?

from 2d-extras.

ChuanXin-Unity avatar ChuanXin-Unity commented on July 27, 2024

Let me try to confirm what you would like to do:

  • Update the Rules for a RuleTile (eg. changing the output Sprite of a Rule or adding new Rules)
  • Have a Tilemap (or Tilemaps) with this RuleTile refresh all Tiles that are that RuleTile so that the updated Rules take effect

The RuleTile's RefreshTile function refreshes the RuleTile at the given position for the given Tilemap, so if the above is correct, that will not do what you want.

I guess the Tilemap would need a new function to do this which would be tilemap.RefreshTiles(Tilebase tile)?

from 2d-extras.

blindgoat avatar blindgoat commented on July 27, 2024

Thank you for spending time looking into this. It is much appreciated. I could see someone using both of the scenarios you mentioned above, however my use case is different.

I have a Tilemap on which only one type of Tile is placed and it's a RuleTile. The user is "digging" and whenever they dig, as long as they haven't previously dug there, a RuleTile is placed on the Tilemap at that location. So if I dig at location 0,0, it adds a RuleTile to the Tilemap. If I then dig at location 0,1, it adds a RuleTile. Since those two tiles are touching, and since there's a rule for those scenarios (e.g. there is a tile below me and nothing above or to the sides), both tiles need to update which Sprite is shown in order to reflect that they are placed next to each other. I hope that makes sense. I can make a gif to show you an example if that would help.

from 2d-extras.

ChuanXin-Unity avatar ChuanXin-Unity commented on July 27, 2024

You can try using tilemap.SetTile( position, tile ), eg. tilemap.SetTile(new Vector3Int(0, 0, 0), ruleTile); tilemap.SetTile(new Vector3Int(0, 1, 0), ruleTile); . The tilemap will automatically update the Sprites of the Tiles you have set.

from 2d-extras.

blindgoat avatar blindgoat commented on July 27, 2024

I have been setting the tiles as you outline and they show up with the default rule but never update to match the outlined rules unless I call tilemap.RefreshAllTiles() after setting the tile. After setting a RuleTile, I would like to individually call Refresh() on each RuleTile that needs it (or have it automatically done like you implied it should be working) rather than having to refresh the entire tilemap. I haven't scaled my tilemap to the final (and very large) size, but I imagine RefreshAllTiles won't be as performant as manually updating only those which were affected.

from 2d-extras.

ChuanXin-Unity avatar ChuanXin-Unity commented on July 27, 2024

That sounds like a bug then as you should not need to make use of tilemap.RefreshAllTiles in this case.

Would it be possible to share your RuleTile setup or your project through the Unity Bug Reporter?

from 2d-extras.

blindgoat avatar blindgoat commented on July 27, 2024

I feel dumb... I setup an example project from scratch and it all worked as you described. I realized the issue in my original project is that I was creating a new RuleTile instance from the ScriptableObject every time I place a new RuleTile instead of reusing it.

Long story short: it works if you do it properly. Thanks again for all your help Chuan, and sorry for not realizing I was doing something incorrectly.

from 2d-extras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.