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

Question Custom render tilemap selection gizmo

Discussion in '2D' started by Jake_sunshine, Mar 14, 2023.

  1. Jake_sunshine

    Jake_sunshine

    Joined:
    Jan 5, 2023
    Posts:
    3
    When using a custom brush, I'm looking to also handle the preview border of the brush myself. I can't seem to find an override or even an event that correlates to the mouseOver event on a grid in the editor.

    Specifically, when I use the "Paint with active brush (B)" option from the Tile Palette window, I can't figure out how to modify the render border of the gizmo in the scene view. This is what I see:

    upload_2023-3-13_19-16-44.png

    I'm looking to handle the borders of the grid element I'm hovering over myself, so that I can indicate the brush width of a custom brush I've created. I see a selection area when using "Select an area of the grid (S)" option from the Tile Palette window:

    upload_2023-3-13_19-19-18.png

    This multi-tile selection is close to what I'm looking for, but I'd like to handle it on the Brush setting, instead. I'd also like to handle it myself to outline multiple hexes around the hex I'm hovering over. I already successfully have the brush painting implemented, but it's difficult to use because I can't change the border preview to give a hint of what will change when Paint is called.

    I believe this border preview is a gizmo, but it's difficult to find documentation on this element. Any help would be appreciated.

    Thanks in advance,
    Jake
     

    Attached Files:

  2. vonchor

    vonchor

    Joined:
    Jun 30, 2009
    Posts:
    238
    I think what you're talking about is the Grid Marquee - if it's what's usually a square box at the cursor position when painting on a vanilla rectangular grid.

    If that's what you mean then no it isn't a gizmo. It's drawn during a scene view. The code for drawing these various marquees are in 'internal' methods in GridEditorUtility and you need to set up a SceneView callback to draw it (ie gets a little complicated, I've done this myself). You can access it via reflection but I'm pretty sure that you can't change the line width.

    You could copy the code in the GridEditorUtility and mod it to change the width (I assume that's OK w/ Unity folks) but you then couldn't distribute it.
     
    Jake_sunshine likes this.
  3. Jake_sunshine

    Jake_sunshine

    Joined:
    Jan 5, 2023
    Posts:
    3
    I'd suspected this. The good news is that I don't mind the original marquee still being there, what I really need is the extended brush size. This is a good lead, by backup option was to draw based on the world projection of the mouse, which I don't want to have to do for obvious performance reasons. Knowing the name of this alone is a huge help, thank you.
     
  4. vonchor

    vonchor

    Joined:
    Jun 30, 2009
    Posts:
    238
    If you want some example code that does this, DM me.