Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback [SpriteShape] Edit callbacks like Tilemap?

Discussion in '2D' started by Baste, Nov 17, 2020.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    Posted this in the general SpriteShape thread, but I wanted to make a post for visibility.

    The Tilemap system has a really nice callback you can listen to in order to post process the tilemap:

    Code (csharp):
    1.  
    2. [InitializeOnLoadMethod]
    3. public static void HookUpToTilemapCallbacks() {
    4.     Tilemap.tilemapTileChanged += TilemapTileChanged;
    5. }
    6.  
    7. private static void TilemapTileChanged(Tilemap tilemap, Tilemap.SyncTile[] tiles) {
    8.     // process the modified tiles
    9. }
    10.  
    It would be really nice to get a callback like that available for SpriteShapes.

    Right now I solve this by having some code in a MonoBehaviour on the same GameObject as the SpriteShape, and run code in during a MouseUp in OnSceneGUI. That has two problems:
    - Detecting that an actual change has happened requires me to keep a list of all of the Spline's positions and tangents and tangent modes, and then check if each of them has been changed.
    - I have to hope really hard that the people using the SpriteShape hasn't minimized my inspector.

    What I'd love was a callback containing the changed SpriteShape, as well as what has changed, so I can react to that in a sensible manner.

    My exact need is that I'm syncing some details between Sprite Shapes and Tilemaps, so I have to calculate the part of the Tilemap that overlaps the area of the Sprite Shape that has changed, and in order to do that I need both the old and new positions/tangents.