1
\$\begingroup\$

I'am building a game using the webcam where I have to step back from the screen for testing. Thus I would like to display a single value in the inspector using a larger font.

Is there a possibility to change the text size in the inspector of a single entry?

I'm currently using [Title ("$currentState")] which creates bold text, but does not increase text size.

\$\endgroup\$
3
  • \$\begingroup\$ Have you tried using a PropertyDrawer to create something like a [LargeText] attribute you can use on the relevant fields? \$\endgroup\$
    – DMGregory
    Jun 7, 2022 at 11:25
  • \$\begingroup\$ Sounds good, but seems to work differently than I expect... \$\endgroup\$
    – cagcoach
    Jun 7, 2022 at 12:02
  • 1
    \$\begingroup\$ Unity doesn't serialize and display property getters - you'd need to put the attribute on the backing field instead. \$\endgroup\$
    – DMGregory
    Jun 7, 2022 at 12:07

1 Answer 1

1
\$\begingroup\$

Using the PropertyDrawer as proposed by @DMGregory finally works:

using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer (typeof (LargeTextInGUI))]
public class LargeTextInGUIDrawer : PropertyDrawer
{
    public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
    {
        var style = new GUIStyle ();
        style.fontSize = 40;
        EditorGUI.LabelField (position, label.text, property.intValue.ToString(), style);
    }

    public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
    {
        return 45;
    }
}
using UnityEngine;

public class LargeTextInGUI : PropertyAttribute
{
}
public class MyClass: ScriptableObject{
    [LargeTextInGUI]
    public int currentState;
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ If you want both an editable field at normal size and a large display field, you could make this a [RepeatWithLargeTextAttribute], and use a PropertyField first to draw the regular control for the field, then follow up with your expanded label. \$\endgroup\$
    – DMGregory
    Jun 7, 2022 at 12:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .