I need to write a custom editor tools for my application. One of those tools should draw a 2d grid inside the scene. I use Debug.DrawLine to do it. The grid should also redraw if user changes the grid parameters in my tool. Yet, I can't seem to find the function to clear already drawn lines. How can I clear already drawn lines? I think it would be beneficial to provide a code. Note that Im' not redrawing it here every frame. It only draws on button stroke.
public void OnGUI()
{
...............................................................................
if(GUILayout.Button("Map world", GuiLOpt)) { DrawGrid(); }
}
protected void DrawGrid()
{
HandleUtility.Repaint();
float XShift, ZShift;
XShift = cellSize * ((float)cellNumX) / 2;
ZShift = cellSize * ((float)cellNumY) / 2;
for(int i = 0; i <= cellNumY; i++)
Debug.DrawLine(new Vector3(-XShift, 0, -ZShift + i * cellSize), new Vector3(XShift, 0, -ZShift + i * cellSize));
for(int i = 0; i <= cellNumX; i++)
Debug.DrawLine(new Vector3(-XShift + i * cellSize, 0, -ZShift), new Vector3(-XShift + i * cellSize, 0, ZShift));
}