Search Unity

[FIXED] Temporarily change to HandTool from CustomTool

Discussion in 'Editor & General Support' started by KezwikHD, Jul 6, 2021.

  1. KezwikHD

    KezwikHD

    Joined:
    Jul 6, 2021
    Posts:
    2
    I wrote a little EditorTool that functions as a brush. The tool works just fine, but i want to be able to move and navigate through the scene by using the middle mouse button and right mouse button. This is implemented for all of the built-in tools already. Also when i right-click the mouse it automatically switches to the Orbit-Tool in the Toolbar and the Cursor gets the Eye-Icon, but it does nothing.

    I don't know if that is a bug and said navigation functionality should be inherited from the EditorTool class, or if i need to implement it on my own.

    However i didn't find anything even remotely related to "how to temporarily switch to the hand/orbit-tool"

    What i'm trying to do in more detail:
    my tool only needs left-click, so right-click could be used to rotate the view and middle-click could be used for panning. This functionality is already implemented within all of the built-in Tools. If you press the middle mouse button you temporarily switch to the panning tool and on release of the middle mouse button you switch back. Same goes for right click. Since i didn't find anything helpful i tried switching as follows:

    Code (CSharp):
    1. Event evnt = Event.current;
    2. if(evnt.button == 1)
    3. {
    4.       Tools.current = Tool.View;
    5. }
    But of course that switches the Tool permanently, which is not what i want.
    Is there a way to switch temporarily or to inherit the Hand-Tool functionality?
     
  2. KezwikHD

    KezwikHD

    Joined:
    Jul 6, 2021
    Posts:
    2
    Ok nevermind i fixed it!

    The above described behaviour is already implemented by default and by inheriting from EditorTool you already get that

    The thing i did, which caused problems was following:
    Code (CSharp):
    1. public override void OnToolGUI(EditorWindow window) {
    2.         [..]
    3.         Event evnt = Event.current;
    4.         if(evnt.isMouse) {
    5.                   [..]
    6.         }
    7.         evnt.Use() //<- This line uses the event and therefore makes
    8.                           //every mouse event unusable for the HandTool
    9. }