Search Unity

Handles.DrawSolidDisc not working

Discussion in 'Editor & General Support' started by kyleyoungblom, Apr 28, 2021.

  1. kyleyoungblom

    kyleyoungblom

    Joined:
    May 1, 2014
    Posts:
    29
    I'm trying to get handles, specifically Handles.DrawSolidDisc, to display in editor. They weren't showing with my custom script, so I grabbed this example from the docs to test, and it doesn't seem to work either. I attach the script to a gameObject, but no handles are drawn in editor. Tested in 2020.2.0f1 and 2021.1.0f1. They were working on my custom script a few months ago; not sure what might have changed in the meantime. Any ideas?

    Mono
    Code (CSharp):
    1.     using UnityEngine;
    2.  
    3.     [ExecuteInEditMode]
    4.     public class DrawSolidDisc : MonoBehaviour
    5.     {
    6.         public float shieldArea = 5;
    7.     }

    Editor
    Code (CSharp):
    1.     using UnityEngine;
    2.     using UnityEditor;
    3.  
    4.     [CustomEditor( typeof( DrawSolidDisc ) )]
    5.     public class DrawSolidDiscEditor : Editor
    6.     {
    7.         void OnSceneGUI( )
    8.         {
    9.             DrawSolidDisc t = target as DrawSolidDisc;
    10.  
    11.             Handles.color = Color.blue;
    12.             Handles.Label( t.transform.position + Vector3.up * 2,
    13.                                 t.transform.position.ToString( ) + "\nShieldArea: " +
    14.                                 t.shieldArea.ToString( ) );
    15.  
    16.             Handles.BeginGUI( );
    17.             GUILayout.BeginArea( new Rect( Screen.width - 100, Screen.height - 80, 90, 50 ) );
    18.  
    19.             if( GUILayout.Button( "Reset Area" ) )
    20.                 t.shieldArea = 5;
    21.  
    22.             GUILayout.EndArea( );
    23.             Handles.EndGUI( );
    24.  
    25.             Handles.color = new Color( 1, 1, 1, 0.2f );
    26.             Handles.DrawSolidDisc( t.transform.position, t.transform.up, t.shieldArea );
    27.  
    28.             Handles.color = Color.white;
    29.             t.shieldArea = Handles.ScaleValueHandle( t.shieldArea,
    30.                             t.transform.position + t.transform.forward * t.shieldArea,
    31.                             t.transform.rotation, 1, Handles.ConeHandleCap, 1 );
    32.         }
    33.     }
     
  2. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,255
    You want to do something like this:
    Code (CSharp):
    1. private void OnEnable()
    2. {
    3.     SceneView.duringSceneGui -= SceneGUI;
    4.   SceneView.duringSceneGui += SceneGUI;
    5. }
    6.  
    7. private void OnDestroy()
    8. {
    9.     SceneView.duringSceneGui -= SceneGUI;
    10. }
    11.  
    12. private void SceneGUI(SceneView sv)
    13. {
    14.     using (new Handles.DrawingScope(Color.blue))
    15.     {
    16.         Handles.DrawSolidDisc(t.transform.position, mysize);
    17.     }
    18. }
     
    megame_dev likes this.