Search Unity

Debug.Draw using EditorWindow

Discussion in 'Immediate Mode GUI (IMGUI)' started by MathiasDG, Dec 20, 2014.

  1. MathiasDG

    MathiasDG

    Joined:
    Jul 1, 2014
    Posts:
    114
    Hello,

    I'm trying to draw some triangles in the scene view using Debug.Draw from a custom editor window.
    Problem is, calling the Debug.Draw will draw A LOT, its like it is getting called more than once per scene frame.

    Here is a part of the window code :

    Code (CSharp):
    1. public class MeshWindow : EditorWindow
    2.             {
    3.  
    4.                 public void OnFocus()
    5.                 {
    6.                     SceneView.onSceneGUIDelegate += this.OnSceneGUI;
    7.                 }
    8.  
    9.                 public void OnDestroy()
    10.                 {
    11.                     SceneView.onSceneGUIDelegate -= this.OnSceneGUI;
    12.                 }
    13.  
    14.                 public void OnSceneGUI(SceneView sceneView)
    15.                 {
    16.                     if (_drawMesh)
    17.                     {
    18.                         _mesh.Draw();
    19.                     }
    20.                 }
    21.             }
    This draws the mesh, but it draws it a thousand times for each time the scene view gets rendered.

    What would the solution to this be?

    Thanks!