Search Unity

Tile Map Tilemap custom brush how to prevent default mouse behavior when painting tiles?

Discussion in '2D Experimental Preview' started by eses, Dec 8, 2019.

  1. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,608
    Hi

    Not sure if I should post this on 2D area or here. Well anyway, move this thread if needed.

    I was trying to create a scriptable brush and wanted to use modifier keys / right mouse click for extra painting features.

    I have a typical paint method like this:
    Code (CSharp):
    1.  public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int cellPos)
    2. {
    3.        // my code here
    4. }
    I can create the default painting behavior and erase things I draw.

    But I don't seem to be able find out a way to override / use the mouse event like I can do in editor scripts.

    Seems like all the modifier keys (Ctrl, Shift and Alt) are reserved and do either erasing, panning or change the brush size no matter what I tried.

    TL;DR
    So is it possible to override mouse buttons default behavior in GridBrush derived custom brushes?
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,608
    After testing this for 3 hours - I don't think all editor events work in brush.

    I can't get any of these to work in Paint method, but I can tap into some events by adding a callback method to SceneView:
    Code (CSharp):
    1. SceneView.onSceneGUIDelegate += OnSceneGUI;
    However, key events like key up don't seem to work, and not even all the modifier keys work. Then again, I have no idea if these are even supposed to work from GridBrush methods.

    Would like to hear some comments about this.
     
  3. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    826
    You will not be able to capture the modifier keys within the tool methods such as Paint, as they are being used to trigger the tool methods themselves.

    You can instead capture the events from the Editor of your GridBrush (derived from GridBrushEditor/Base) using the
    OnPaintSceneGUI
    callback and do your custom behaviour there?
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,608
    @ChuanXin

    Thank you for the info! It will most likely be helpful.

    I haven't touched GridBrushEditor class, so I'll have to read about it.

    So far I managed to do most if not everything I need from onSceneGUIDelegate attached method, using only keys that are not reserved by Tilemap brush :).
     
unityunity