- Home /
Detect mouseDown & mouseUp events on handles in editor
In my onSceneGUI delegate I can get the mouseDown and mouseUp events for the right mouse button. I can get the mouseDown event for the left mouse button and with a lot of work using GetControlID and GUIUtility.hotControl it is possible to get the mouseUp event for the left mouse button (???). But, NOTHING happens when I click on the handles/gizmos of an object in the scene view.
It is possible to use GUIUtility.hotControl to view the id of the handle controls when they are clicked on but these change depending on how many objects there are, the order of creation or some other reason.
Do I need another delegate to intercept mouse clicks on the handles?
Any help would be very welcome.
Answer by Zergling103 · Jan 19, 2015 at 10:34 PM
Use GUI.changed.
bool temp = GUI.changed;
GUI.changed = false;
Vector3 modifiedPosition = Handles.PositionHandle(GetPosition(), Quaternion.identity);
if (GUI.changed)
{
Debug.Log("Position was modified!")
SetPosition(modifiedPosition);
}
GUI.changed |= temp;
Answer by MediaGiant · Mar 02, 2014 at 12:47 PM
It was tricky, but there is an answer, a simple answer, and it does not use reflection.
string tempString = GUI.GetNameOfFocusedControl();
if ((tempString == "xAxis" || tempString == "yAxis" || tempString == "zAxis") && GUIUtility.hotControl != 0)
{
hotControlFlag = true; // declared elsewhere
Debug.Log ("dragging");
}
if ((tempString == "xAxis" || tempString == "yAxis" || tempString == "zAxis") && hotControlFlag && GUIUtility.hotControl == 0)
{
hotControlFlag = false;
Debug.Log ("released");
}
This solution is much better than the "Best Answer".
Your answer
Follow this Question
Related Questions
What is the best way to use the Handles class to create custom gizmos. 1 Answer
How to create a control that allows to select position within a line? 3 Answers
Draggable gizmos like polygon collider 2d corners 1 Answer
Draw Gizmos and Handles in the scene from an EditorWindow 1 Answer
Editor Windows : Help required 1 Answer