Search Unity

Setting gizmo material?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Alex_curiscope, Oct 9, 2017.

  1. Alex_curiscope

    Alex_curiscope

    Joined:
    Apr 4, 2017
    Posts:
    55
    I'm trying to draw an editor gizmo for a procedurally generated asset and have it clickable. I thought the only way to do this was to draw meshes using Gizmos.DrawMesh - but I'm finding I can't set the material to do it - my quad just comes out as a grey lit quad instead of using my material.

    Code (CSharp):
    1.  
    2.     private void OnDrawGizmos()
    3.     {
    4. #if (UNITY_EDITOR)
    5.         if (Application.isPlaying) return;
    6.         CheckEditorMesh();
    7.         iconMat.SetPass(0);
    8.         Camera cam = Camera.current;
    9.         if (cam == null) cam = Camera.main;
    10.         if (cam != null)
    11.         {
    12.             Vector3 dif = cam.transform.position - transform.position;
    13.             dif.y = 0;
    14.             Quaternion q = Quaternion.FromToRotation(Vector3.forward, dif); // face camera
    15.             for (int i = 0; i < 10; i++)
    16.             {
    17.                 Gizmos.DrawMesh(sceneViewMesh, transform.position + Vector3.up * i, q);
    18.             }
    19.         }
    20. #endif
    21.     }
    22.  
    Any ideas?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    I don't know how to set the Gizmos material, but I used Graphics.DrawMeshNow inside OnDrawGizmos and it does properly use the applied material if I remember correctly. Perhaps it's worth a try.
     
  3. Alex_curiscope

    Alex_curiscope

    Joined:
    Apr 4, 2017
    Posts:
    55
    Ohh. Ah. Thanks! And does that make the mesh clickable? So probably using DrawMesh adds the draw call to a queue that gets drawn outside the gizmos code that makes meshes drawn clickable...
     
  4. Alex_curiscope

    Alex_curiscope

    Joined:
    Apr 4, 2017
    Posts:
    55
    DrawMeshNow isn't making my drawn polygons clickable. Is there some secret to doing it?
     
  5. Alex_curiscope

    Alex_curiscope

    Joined:
    Apr 4, 2017
    Posts:
    55