Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

No GUI Implemented

Discussion in 'Scripting' started by The-Oddler, Jun 29, 2014.

  1. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    133
    I'm trying to use a CustomPropertyDrawer to make my class look nicer in the inspector. It's a very simple class, just two ints, but I can't get it to work. Instead of it drawing the 2 ints next to eachother, I get the message "No GUI Implemented" twice :(

    The Class:
    Code (CSharp):
    1.  
    2. [System.Serializable]
    3. public class UsageLevel {
    4.     public int Level;
    5.     public int JumpToLevel;
    6. }
    7.  
    My drawer:
    Code (CSharp):
    1.  
    2. [CustomPropertyDrawer (typeof(UsageLevel))]
    3. public class UsageLevelDrawer : PropertyDrawer {
    4.    
    5.     // Draw the property inside the given rect
    6.     void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
    7.         // Using BeginProperty / EndProperty on the parent property means that
    8.         // prefab override logic works on the entire property.
    9.         EditorGUI.BeginProperty (position, label, property);
    10.        
    11.         // Draw label
    12.         position = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID (FocusType.Passive), label);
    13.        
    14.         // Don't make child fields be indented
    15.         var indent = EditorGUI.indentLevel;
    16.         EditorGUI.indentLevel = 0;
    17.        
    18.         // Calculate rects
    19.         float width = position.width;
    20.         Rect levelRect =        new Rect (position.x,                position.y,        width/2-5,                position.height);
    21.         Rect jumpToLevelRect =    new Rect (position.x + width/2,        position.y,        width/2,                position.height);
    22.        
    23.         // Draw fields - passs GUIContent.none to each so they are drawn without labels
    24.         EditorGUI.PropertyField (levelRect, property.FindPropertyRelative ("Level"), GUIContent.none);
    25.         EditorGUI.PropertyField (jumpToLevelRect, property.FindPropertyRelative ("JumpToLevel"), GUIContent.none);
    26.        
    27.         // Set indent back to what it was
    28.         EditorGUI.indentLevel = indent;
    29.        
    30.         EditorGUI.EndProperty ();
    31.     }
    32.    
    33. }
    34.  

    I's just a copy paste from the unity documentation with very little changes, though apparently something is still wrong...
    Anyone here spot the problem?

    Thanks!
     
  2. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    133
    Never mind, I fixed it! Turns out you have to override the OnGUI method. So it becomes:
    Code (CSharp):
    1. override public void OnGUI (Rect position, SerializedProperty property, GUIContent label) { ... }
    This doesn't seem to be documented...