Unity Community |

Is there a way of knowing if one of your Handles is currently selected or gets selected in CustomEditor?
I'm currently using Handles.FreeMoveHandle for every control point in my spline-tool. I try to keep track of the selected point via hacky code, where I'm making an intelligent guess during a mouseUp-event, that tries to determine which of the points is the closest of the click. This works "ok", but I'm getting reports that it's not 100%.
Last edited by keely; 05-06-2011 at 12:29 AM.
There's so much noise that I'm going to bump this once.
If I understand your issue correctly, have you tried checking GUI.changed after drawing each handle? In theory, this should tell you which one was the last one with which the user interacted. Does that help?
I don't know yet, but seems like potential winner. I'm going to test it later when I get home. Thanks!
Any more info on this issue? I am wrestling with the same problem for my Orthello OTPath spline.
The GUI.changed technique is only set when a handle has been moved.changed, not when you just select a handle ( and it gets outlined with a yellow line )
Will go and check if I can cast a ray against the handle.
Update
I have managed to find the selected handle by doing this :
- Code goes into the OnSceneGUI() of the editor class
- Check if the GUIUtility.hotControl has changed ( value of 0 = no control selected )
- If it hotControl changed, find the current handle by ray casting into the world using HandleUtility.GUIPointToWorldRay(Event.current.mou sePosition); and checking if that
ray intersects with any of the created handles.
This worlks because I know where I create my handles and within what radius the specific ray should fall to intersect with the handle.
After I have found the right control, I can cache the controlID for future and quicker lookup. I have not managed to find a way to get a handle's ControlID right after I have created it. ( anyone??)
Last edited by mas; 08-08-2011 at 06:26 AM.
Martijn Segers | WyrmTale Games |
“The intuitive mind is a sacred gift and the rational mind is a faithful servant. We have created a society that honors the servant and has forgotten the gift.” - Albert Einstein
Cheers for the info, it pointed me in the right direction.
The easiest way I found to do this is to name the Control using GUI.SetNextControlName ( ".." ).
Unfortunately as some of the Handles ( PositionHandle ) create multiple controls only
the first one will be named, but it easy enough to build your own from the components
provided.
Take the PositionHandle as an example we can add the following function to recreate
it from the other handles provided. As you can see we set the name of each of the
controls, this will let us use the function GUI.GetNameOfFocusedControl () to get the
name of the control and use that to lookup an array or dictionary to find the related
item.
Vector3 PositionHandle ( Vector3 position, Quaternion rotation, string name )
{
// right Axis
GUI.SetNextControlName ( name );
Handles.color = new Color ( 1.0f, 0.0f, 0.0f, 0.75f );
Vector3 newPos = Handles.Slider ( position, rotation*Vector3.right );
// Up Axis
GUI.SetNextControlName ( name );
Handles.color = new Color ( 0.0f, 1.0f, 0.0f, 0.75f );
newPos += Handles.Slider ( position, rotation*Vector3.up ) - position;
// Forward Axis
GUI.SetNextControlName ( name );
Handles.color = new Color ( 0.0f, 0.0f, 1.0f, 0.75f );
newPos += Handles.Slider ( position, rotation*Vector3.forward ) - position;
float sizeMultiplier = 0.0f;
if ( Camera.current.orthographic )
{
sizeMultiplier = Camera.current.orthographicSize * 2.5f;
}
else
{
Plane screen = new Plane ( Camera.current.transform.forward, Camera.current.transform.position );
screen.Raycast ( new Ray ( position, Camera.current.transform.forward ), out sizeMultiplier );
}
GUI.SetNextControlName ( name );
Handles.color = new Color ( 1.0f, 1.0f, 1.0f, 0.75f );
newPos += Handles.FreeMoveHandle ( position, rotation, 0.02f * sizeMultiplier, Vector3.zero, Handles.RectangleCap ) - position;
}
Sign up for [update notifications] as new OUYA Unity Package updates become available.
Paint scripting via video training.
Need a tree view control in Unity?
Easily add vegetation to your scene.
Toolbox directly exports to VS 2010/VS 2012.
Remotely edit the scene while it's running on a target device.