- Home /
Is it possible to determine wich Handles.PositionHandle is currently focused?
Hello, is it possible to determine which Handles.PositionHandle is currently focused?
Is this thread helpful? http://forum.unity3d.com/threads/currently-selected-handle-in-editor-script.87634/
Answer by codebeans · Mar 09, 2015 at 09:08 PM
If you mean by axis. Try Making each of them an individual Handle Slider.
If you mean by overall Positionhandle do this:
Add GUI.SetNextControlName("your_unique_Identifer_for_this_handle"); before calling Handle.PostionHandle(..)
Now in the function where you evaluate those Handles and try to find the right one. check for GUI.GetNameOfFocusedControl() and do a simple switch-case
Hi, I have same problems, however the following code not fully functional
// Point
GUI.SetNextControlName("Point_" + point.GetInstanceID() + "Handle1");
Vector3 newGlobal1 =
!free$$anonymous$$ode ?
Handles.PositionHandle(point.globalHandle1, Quaternion.identity) :
Handles.Free$$anonymous$$oveHandle(point.globalHandle1, point.transform.rotation, HandleUtility.GetHandleSize(point.globalHandle1) * HANDLE_SUB_SIZE, Vector3.zero, Handles.CircleCap);
you can visualize it only work on Free$$anonymous$$oveHandle by following checking.
// Another editor script to script which one is selected
void OnSceneGUI()
{
string hotControl = GUI.GetNameOfFocusedControl();
if (!hotControl.StartsWith("Point_" + selectedPoint.GetInstanceID()))
{
for (int i = 0; i < curve.pointCount; i++) // curve contain all points.
{
if (hotControl.StartsWith("Point_" + curve[i].GetInstanceID()))
{
selectedPoint = curve[i];
break;
}
}
}
GUILayout.Label(selectedPoint ? selectedPoint.name : "none");
}
thru result, I also notice when user click on PositionHandle : GUI.GetNameOfFocusedControl(); // return "" GUIUtility.hotControl // return non-zero value
but click on the Free$$anonymous$$oveHandle : GUI.GetNameOfFocusedControl(); // return "Point_#1234", correct result. GUIUtility.hotControl // return non-zero value
my purpose is create a editor panel to selected GameObject during scene update. any suggestion to make it functional on PositionHandle ?
Have you actually read the answer carefully? He suggested to not use a PositionHandle but to use 3 individual Sliders which you can give a name individually.
The PositionHandle code internally named each axis seperately:
"xAxis"
"yAxis"
"zAxis"
"Free$$anonymous$$oveAxis"
So it's not possible to give each axis for each of your points a unique name if you use a PositionHandle.
Each slider inside a PositionHandle has it's own controlID. However they are creating their IDs automatically with GUIUtility.GetControlID(Handles.s_SliderHash, FocusType.$$anonymous$$eyboard);
. The static field s_SliderHash is literally just "SliderHash".GetHashCode();
.
IDs are usually handed out in sequence, so by manually generating a control ID with the same hash before the actual PositionHandle, you should be able to predict the ID for the next control. You then just have to check GUIUtility.keyboardControl
to deter$$anonymous$$e which control is focused.
thanks, and sorry, I haven't describe my problem correctly, I dont mean to find which axis. I only need to identify the positionHandle's gameObject. but your answer make me think some more about the controlID.
how to identify the controlID's owner? I mean if I use it to move another gameObject.
currenty my project is writing an bezier curve, each Curve have unlimited point. in scene view the developer able to move all the point within that curve. thats why I need to know which point are focus.