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

Hand tool stuck in sceneview after showing context menu

Discussion in 'Scripting' started by LoK4t, Nov 16, 2015.

  1. LoK4t

    LoK4t

    Joined:
    May 27, 2015
    Posts:
    9
    Hi! I recently started working on an editor extention, where when the user right-clicks in the scene view, a context menu appears.

    However the problem is that after I listen to the event and show the context menu, and the user closes that menu, the hand (pan) tool gets stuck, and I am unable to choose any other tool. It can be fixed by pressing play and stopping again, but it's a real pain to have to do that each time.

    I'm thinking it might be because of the event not being propogated properly, or something like that, however it I am not experienced enough to figure it out. Any help?

    Here is the code to replicate the problem (put in an EditorWindow class:

    Code (CSharp):
    1.  
    2. private static void OnScene(SceneView sceneView)
    3.     {
    4.         int ctrlID = GUIUtility.GetControlID(FocusType.Passive);
    5.         if(doRightClickMenu)
    6.         {
    7.             if (Event.current.type == EventType.MouseUp && Event.current.button == 1)
    8.             {
    9.                 menu.ShowAsContext();
    10.                 Tools.current = Tool.View;
    11.                 HandleUtility.AddDefaultControl(ctrlID);
    12.             }
    13.         }
    14.     }

    EDIT ----------------

    I could not find a way to solve this, but using the mousedown event instead of the mouseup event seemed to not get the hand tool stuck, although I would have liked to have responded to the mouseup event.
     
    Last edited: Nov 19, 2015
    lil_sichen likes this.
  2. LoK4t

    LoK4t

    Joined:
    May 27, 2015
    Posts:
    9
    Read edit ^^
     
  3. gouki04

    gouki04

    Joined:
    May 17, 2017
    Posts:
    1
    I find a solution, you should call
    Event.current.use()
    after
    menu.ShowAsContext()
    , this will prevent the event pass to the hand tool.