SceneView and custom inspector questions

Hi,

I have a few custom window / inspector scripts where i use Debug.DrawLine to draw lines on the sceneView to display what is going on.

Once I finish calling all the DrawLine() methods for the frame, I do :

SceneView.RepaintAll();

That works allright for drawing new lines, problem is, when it is needed to get rid of the previous line drawings and display new ones.
Using SceneView.RepaintAll() will draw the new lines as intended, but it will not hide the old ones.

I’ve found a little trick that forces the SceneView to update and erase the old drawings and paint a new frame. The trick is to change a gameObject transform.position and then change it back again to its original position. It goes like this :

Vector3 pos = terrain.transform.position;
terrain.transform.position = pos + new Vector3(1, 0, 0);
terrain.transform.position = pos;

This will cause the SceneView to Update or Repaint imediatly, i dont really know exactly what goes on there, but it somehow works.

Now, I want to move my drawings along with the mouse position in the scene view, for that I would like to ask a few questions :

  1. How to (continuously) get (X, 0, Z) world coordinates of the current mouse position in the scene view from a custom inspector or a custom editor window.
  2. How to get mouse events from editor such as mouse key down and key up.
  3. How to properly erase the old Debug.DrawLines and display the new ones in the scene view.

Thank you!

  1. Debug.DrawLine should only be shown the frame it’s drawn and not need anything to be updated. Put it in an Update method instead of the GUI method and it should work as expected.