Search Unity

Feedback Remove spaces from public variables in Inspector

Discussion in 'Immediate Mode GUI (IMGUI)' started by Layarion, Aug 24, 2020.

  1. Layarion

    Layarion

    Joined:
    Jun 5, 2020
    Posts:
    10

    I hate the spacing between words on the Inspector for serialized or public variables. To me it's not as easy to look at this way, and I just want the option to remove the spacing. Make this an option in the Unity Editor settings, so that instead of "Main Menu Object" I can have "MainMenuObject"
     
    Last edited: Aug 24, 2020
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,193
    You can achieve this with a custom editor.

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.UI;
    4.  
    5. [CanEditMultipleObjects]
    6. [CustomEditor(typeof(Foo), true)]
    7. public class FooEditor : Editor
    8. {
    9.     private SerializedProperty myVariable;
    10.     private GUIContent myVariableLabel = new GUIContent("myVariable");
    11.  
    12.     public void OnEnable()
    13.     {
    14.         base.OnEnable();
    15.  
    16.         myVariable = serializedObject.FindProperty("myVariable");
    17.     }
    18.  
    19.     public override void OnInspectorGUI()
    20.     {
    21.         EditorGUI.BeginChangeCheck();
    22.  
    23.         EditorGUILayout.PropertyField(myVariable, myVariableLabel);
    24.    
    25.         if (EditorGUI.EndChangeCheck())
    26.             serializedObject.ApplyModifiedProperties();
    27.     }
    28. }
     
    karl_jones likes this.
  3. Layarion

    Layarion

    Joined:
    Jun 5, 2020
    Posts:
    10
    thanks, i'll look into this.