Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Extending functionality of RuleTile?

Discussion in 'Scripting' started by Rocky_Unity, Feb 11, 2020.

  1. Rocky_Unity

    Rocky_Unity

    Joined:
    Oct 13, 2017
    Posts:
    96
    Hello!
    I was wondering if there is a way to extend the functionality of a rule tile?
    In particular, I want to add a new "Output" field. This field will be called "Seasons". So it'll be the same tile basically, but with some changes to add snow on it, etc.. Currently, the fields are Fixed, Animation, and Random.
    This is what the random field looks like


    And this is what the code for the rule tile looks like:
    So I want to add to the public enum OutputSprite, Seasonal = 3.

    Then in that field I could set 4 sprites (for 4 seasons) that the ruletile will choose, based on a ScriptableObject that holds the current season. That function could look something like this..

    That's where I get stuck though. I'm not sure how to extend the functionality of the RuleTile. Is this something that is possible?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    I just copied the rule tile class source code, called it CustomRuleTile, and changed whatever I wanted to change. That worked for me. Unity isn't really designed to be extensible throught iheritance. A lot of important members can't be overridden and / or even accessed.
     
  3. Rocky_Unity

    Rocky_Unity

    Joined:
    Oct 13, 2017
    Posts:
    96
    Palex,
    That's what I ended up doing last night. I didn't realize I could because I installed it via the package manager and didn't (or as far as I am aware) didn't have access to the scripts. I removed the pacakage and added the 2d+extras scripts that I wanted into my Assets instead, and then modified accordingly and made my modifications. (just as you suggested)

    My rule-tiles now work wonderfully and pick a different themed sprite based on an event :) (like seasons)
    Stoked!! Unity has provided some fantastic tools for tiling, I love it!
     
  4. AidinD

    AidinD

    Joined:
    May 3, 2017
    Posts:
    4
    Do you perhaps have this extended rule-tile of yours publicly available? I am doing a Stardew Valley:ish game and need a RuleTile able to change seasons.
     
  5. treecki

    treecki

    Joined:
    Feb 6, 2017
    Posts:
    28
    Sorry to necro a year old thread, but this has become something I've been aiming to do and have run into a few issues.

    I'm currently using the 2D Tilemap Extras 1.8.0-preview because of the new feature that allows to extend the grid within rule tile, which is extremely useful for creating wall tiles with a 3/4th perspective. I'm trying to make these wall tiles even more complex and figured out how you could extend the rule tile class to create your own "rules" beyond "This" and "NotThis" (vid for those curious). I'd like to make rules that check whether the neighbor is a ceiling or a wall, which would require adding an enum variable as an "Output field" as @Rocky_Unity mentioned doing earlier.

    I guess my question is if anyone has found the updated ruletile scripts that include the extend neighbor feature? Cause then I'd just do the same thing previously. Or, has anyone found a way to add an rule tile "Output field"?

    I know this is kind of a shot in the dark, but I figured I'd post and ask!
     
    Last edited: Aug 7, 2021
    Hugo-ElectricMonkeys likes this.