The problem here is (afaik) that during OnGUI you don’t have an “active camera”, as EditorWindow’s aren’t at all connected with the SceneView.
You might be able to call
Vector3 mousePos = Event.current.mousePosition;
The mouse position must be flipped into ScreenSpace because we only have access to the ScreenPointToRay-function, which is similar to the GUIPointToWorldRay, except it takes use of screenspace:
mousePos.y = SceneView.lastActiveSceneView.camera.pixelHeight - mousePos.y;
Then we can create the ray:
Ray ray = SceneView.lastActiveSceneView.camera.ScreenPointToRay(mousePos);
if you however want to incorporate more GUI/Handles into the sceneview itself for the EditorWindow, I reccoment to do this:
public class SceneInteractingWindow : EditorWindow
{
private void OnEnable()
{
//register that OnSceneGUI of this window
//should be called when drawing the scene.
SceneView.onSceneGUIDelegate += OnSceneGUI;
}
private void OnDisable()
{
//cleanup: when the window is gone
//we don't want to try and call it's function!
SceneView.onSceneGUIDelegate -= OnSceneGUI;
}
private void OnSceneGUI(SceneView sv)
{
//DO SceneGUI stuff here...
//for example something like this:
Vector3 mousePos = Event.current.mousePosition;
mousePos.y = sv.camera.pixelHeight - mousePos.y;
Ray ray = sv.camera.ScreenPointToRay(mousePos);
RaycastHit hit;
if (Physics.Raycast(brushRay, out hit))
{
Handles.color = Color.red;
Handles.DrawWireDisc(hit.point,hit.normal, 5);
sv.Repaint();
}
}
}
Same problem here...
– Metrical