- Home /
Drawing Handles
I have been trying to draw handles for the past 2 days with very little success, not sure which portion of what I am doing is wrong.
I don't want to use gizmos (as they require a monobehaviour that doesn't really fit what I'm doing)
here is a snippet of code
public class AdaptivePathEditor : EditorWindow {
public void Update () {
Handles.DrawCamera(new Rect(0,0,500,500),Camera.current);
Handles.PositionHandle(Vector3.zero,Quaternion.identity);
}
}
I would also like a object that can be created and dragged into a an editor window but that probably requires inheriting from scriptable object which is another thing entirely.
Answer by numberkruncher · Feb 17, 2013 at 08:02 PM
Use OnSceneGUI of custom editor for handles
I believe that you need to use the OnSceneGUI
message handler of a custom Editor
for this:
[CustomEditor(typeof(YourMonoBehaviour))]
public class AdaptivePathEditor : Editor {
void OnSceneGUI() {
Handles.DrawCamera(new Rect(0,0,500,500), Camera.current);
Handles.PositionHandle(Vector3.zero, Quaternion.identity);
}
}
For more information please see: http://docs.unity3d.com/Documentation/ScriptReference/Editor.html
Otherwise you may need to consider using the Graphics
and/or GL
class instead. Though I am not sure how you would "inject" that into a scene view without a custom editor or gizmos.
Define a static gizmo function
Another alternative would be to draw gizmos from your editor window:
public class YourEditorWindow : EditorWindow {
static YourEditorWindow window;
[DrawGizmo(GizmoType.NotSelected)]
static void RenderCustomGizmo(Transform objectTransform, GizmoType gizmoType) {
if (window == null)
return;
// Draw gizmos...
}
// Maintain static reference to window
void OnEnable() {
window = this;
}
void OnDisable() {
window = null;
}
void OnGUI() {
}
}
For further information please see:
not sure that would work, its funny i just need a "ball" or "node" to pop up without a zsort so i can see it through things aswell as line drawer.
Update(); happens 100 times a second from everywindow, so enless editor.handles refuses to run there. then i think it should work
I believe that handles need to be presented using OnSceneGUI
because they respond to GUI events which do not occur when processing Update
messages. It is normal to associate custom control IDs to handles which can then be used to handle things like mouse interaction (drag & drop for example). Handles are generally interactive GUI elements.
There is an undocumented OnPreSceneGUI
message handler, so perhaps there is an undocumented OnPostSceneGUI
message handler. I am not saying that there is, but might be worth experimenting to find out. This would presumably draw your handles on top of everything else.
that would work wonders, only if i could get handles actually drawing from EditorWindow, which i don't fully understand why its so difficult
EditorWindow
's are not designed to present things within other scene view windows. They are independent viewports, however they can actually draw gizmos.