x


Using Handles class

How can I use the Handles class in an editor window to show a Vector3 point in the scene view?

I simply want to be able to enter co-ordinates and have a handle appear there.

I've got this so far:

class SimpleHandle extends EditorWindow{

private var posValue : Vector3;

@MenuItem ("Window/Simple Handle")
static function Init () {
    var window : SimpleHandle = EditorWindow.GetWindow(SimpleHandle);
}

function OnGUI(){
    posValue = EditorGUILayout.Vector3Field("Position", posValue);
}

function OnSceneGUI () {
    Handles.PositionHandle(posValue, Quaternion.identity);
}

}

But it doesn't work, and looking through the forums and documentation hasn't helped - examples in the docs are pretty sparse with the Handles class...

Thanks!

more ▼

asked Jun 11 '10 at 07:12 PM

chief1234 gravatar image

chief1234
368 13 14 26

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Old question, so you've probably figured it out already, but anyway ...

EditorWindow doesn't have an OnSceneGUI method, so your code above will never get called. You can do what you want in a custom Editor, but not an EditorWindow. For an Editor, the OnSceneGUI method lets you draw into the scene view, which is where the Handles class becomes useful.

Typically the OnSceneGUI method would be used to draw things in the scene relative to the target object of the Editor (the component being edited), but there's nothing to stop your Editor from having its own member variables and drawing whatever it feels like.

Note that Editor.OnSceneGUI will only be called when the editor is active in the Inspector, which may not be what you're looking for.

MonoBehaviour.OnDrawGizmos may be a simpler solution to what you're trying to do. You could have a component with an array of Vecto3's, and have its OnDrawGizmos method draw a handle for each of the vectors.

more ▼

answered Jan 05 '11 at 04:05 PM

yoyo gravatar image

yoyo
6.4k 25 39 84

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x169
x38
x15

asked: Jun 11 '10 at 07:12 PM

Seen: 2349 times

Last Updated: Jun 11 '10 at 07:12 PM