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.

Begin(), Drag() & End() event for native Handle in unity...

Discussion in 'Editor & General Support' started by usernameHed, Nov 11, 2020.

  1. usernameHed

    usernameHed

    Joined:
    Apr 5, 2016
    Posts:
    90
    Hello, a simple task is driving me crazy.
    My goal is: I want to tell in unity when the user start or finish draging an handle. The HandleMove, and HandleRotate (the native tools of unity)

    Here is the base of the script:

    Code (CSharp):
    1.  
    2.     [InitializeOnLoad]
    3.     public static class CallBackIsMovingHandle
    4.     {
    5.         static CallBackIsMovingHandle()
    6.         {
    7.             SceneView.duringSceneGui += DuringSceneGUI;
    8.         }
    9.  
    10.         private static void DuringSceneGUI(SceneView sceneView)
    11.         {
    12.                //do my tests here
    13.         }
    14.    }
    15. }
    Then for my actual test, here is a try:

    Code (CSharp):
    1.  
    2.  
    3.        if (Selection.activeGameObject == null)
    4.        {
    5.              return;
    6.        }
    7.      
    8.        if (Tools.current != Tool.Move && Tools.current != Tool.Rotate)
    9.        {
    10.              return;
    11.         }
    12.  
    13.        int controlID = HandleUtility.nearestControl;
    14.  
    15.        if (GUIUtility.hotControl == controlID)
    16.             {
    17.                 switch (Event.current.GetTypeForControl(controlID))
    18.                 {
    19.                      case EventType.MouseDown:
    20.                         Debug.Log("Start");
    21.                         break;
    22.                     case EventType.MouseDrag:
    23.                         Debug.Log("Drag");
    24.                         break;
    25.                     case EventType.MouseUp:
    26.                         Debug.Log("up");
    27.                         break;
    28.                 }
    29.             }
    This code kind of work if my mouse stay hover the handle (first part of the video), but when i'm movong my mouse on the side, the Drag / mouseUp event doesn't work


    I would like to find a way to detect mouse down/drag/up only for the handle tool.
    When I'm using:
    Code (CSharp):
    1. int controlId = GUIUtility.GetControlID(FocusType.Passive);
    2. switch (Event.current.GetTypeForControl(controlID))
    3. {
    4. // event..
    5. }
    If I use that code it detect also click/drag/up when i'm not even draging a handle (like when i'm moving in the sceneView or orbiting around some gameObject...)

    AND: i would like the mouseUp to work even when my moue leave the sceneView of course...

    Thanks!
     
    Last edited: Nov 11, 2020