Search Unity

Handles.FreeMoveHandle & HotControl!

Discussion in 'Editor & General Support' started by MvNimwegen, Apr 13, 2021.

  1. MvNimwegen

    MvNimwegen

    Joined:
    Dec 19, 2019
    Posts:
    56
    Hi!

    I have an issue with setting hotcontrol to the Handles.FreeMoveHandle.

    Basically, I want to set HotControl to a certain handle when NOT clicked on a handle in the sceneview. The handle is then supposed to move along with the cursor as it would when clicked directly. It is not supposed to jump to the cursor. The problem is that something seems to go wrong with the startposition of the handle.
    Whenever I set the hotcontrol to the handle manually, the start position for this handle is still set to the startposition of the previously used handle!

    FB8OYN3Lng.gif


    I looked at the internal code at it seems that there is a static Vector3 s_StartPosition for the FreeMove class. This is set upon a MouseDown event on the handle. Since I set the control to this handle manually through script, I suspect this step of setting the proper startposition is skipped.

    This is the code I used for this test setup

    Code (CSharp):
    1.     private void OnSceneGUI()
    2.     {
    3.         float handleSize = HandleUtility.GetHandleSize(component.transform.position);
    4.  
    5.         Handles.color = Color.blue;
    6.  
    7.         for (int i = 0; i < component.Vectors.Count; i++)
    8.         {
    9.             Vector3 newPos = Handles.FreeMoveHandle(333 + i, component.Vectors[i], Quaternion.identity, 0.2f * handleSize, Vector3.zero, Handles.DotHandleCap);
    10.             component.Vectors[i] = newPos;
    11.         }
    12.  
    13.         if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && !Event.current.control && !Event.current.alt)
    14.         {
    15.             GUIUtility.hotControl = 333;
    16.             SceneView.RepaintAll();
    17.         }
    18.     }
    I am very new to using HotControl. The value of 333 is random. I am sure there is a much cleaner way to do this, I just don't have any idea yet!

    My question is now of course, is there a way to either (re)set this startposition, of another way entirely to get the desired behaviour.

    Thank you in advance! :)
     
  2. MvNimwegen

    MvNimwegen

    Joined:
    Dec 19, 2019
    Posts:
    56
  3. MvNimwegen

    MvNimwegen

    Joined:
    Dec 19, 2019
    Posts:
    56