Problems detecting Handles by mouseover or nearestControl
Asked Answered
B

2

0

I’m trying to “select” on mouseOver a Handle.Button, but I cant find a solution that works.

I thought I can get the ID of the control, and then check if its the same ID than HandleUtility.nearestControl , but this works with a few Handles, and others doesn’t.

Can anyone tell me what’s wrong? Or maybe another approach?

idNext = GUIUtility.GetControlID(FocusType.Passive) + 1;
if (Handles.Button(point, handleRotation, handleSize,pickSize, Handles.CircleHandleCap))
{
    selectedIndex = index;
}

if (selectedIndex == index)
{
    point = Handles.DoPositionHandle(point, handleRotation);
    //some irrelevant code
}
else if (HandleUtility.nearestControl == idNext)
{
    selectedIndex = index;
}
Burnaby answered 27/1, 2024 at 11:43 Comment(0)
B
0

Since I couldn’t solve it using CONTROLS, I am wasting a lot of CPU resources.

I hope someone else have a better approach than me :confused:

switch(Event.current.type)
{
    case EventType.mouseMove:
    {
        for (int i = 0; i < points; i++)
        {
            float dist = Vector2.Distance(Event.current.mousePosition, HandleUtility.WorldToGUIPoint(obj.transform.position + point));
            if (dist < 20)
            {
                if (i != selectedIndex)
                {
                    selectedIndex = i;
                    Repaint();
                }
                break;
            }
        }
    }
    break;
}
Burnaby answered 27/1, 2024 at 11:45 Comment(0)
T
0

I asume that youre trying to get the buttons control id using the “idNext”. From my understanding that wont work since the Button method uses an internal hash to randomize their controll id.

I dont think unity intends for you to add behavior to the builtin handles, so if you want the control id of the handle you will have to write your own implementation.

I also dont understand what the point of the button is if you automaticly select it by hovering over it.

Tibetan answered 27/1, 2024 at 11:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.