Search Unity

Question Custom Rule Tiles - Prevent changing during runtime & / or bool being set

Discussion in '2D' started by Monhulio, Jun 23, 2021.

  1. Monhulio

    Monhulio

    Joined:
    May 9, 2019
    Posts:
    3
    Does anyone have some experience using the ruletile and custom ruletile script setup? I want to prevent tiles from changing, either at runtime or when a certain bool I set is true during runtime, but work as usual when I am using the editor. I can't seem to find an override in the "customruletile" that will allow me to do this.

    I basically want to allow the player to destroy tiles by "setting" them without running the ruleset, but when a player is building (or when I am in the editor) I want to USE the ruleset.

    Psuedo world destruction if you will.
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    You may need to override the RuleTile to get this behaviour. You could change the RuleTile.RefreshTile behaviour to not adjust the neighbours when you change it in the Player.

    Code (CSharp):
    1. public override void RefreshTile(Vector3Int position, ITilemap tilemap)
    2. {
    3.     if (Application.IsPlaying())
    4.         TileBase.RefreshTile(position, tilemap);
    5.     else
    6.         RuleTile.RefreshTile(position, tilemap);
    7. }
     
    Monhulio likes this.
  3. Monhulio

    Monhulio

    Joined:
    May 9, 2019
    Posts:
    3
    @ChuanXin Thankyou so much! This might be what I am looking for, as doing
    Code (CSharp):
    1. if (!Application.isPlaying)
    2.             base.RefreshTile(position, tilemap);
    Seems to produce the results I want at present, which means its targeting the correct info. Will post in here again if there is any more to it, otherwise I should be able to check.
    Code (CSharp):
    1. if (InBuildMode || !Application.isPlaying)
    2.             base.RefreshTile(position, tilemap);
    So that the tiles only refresh visuals when my player is trying to build tiles, not destroy!