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.
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:
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: