Skip to content

Font members of EditorStyles is no longer using backing fields since 2019.3 #13

@EmiyaSyahriel

Description

@EmiyaSyahriel

Since Unity 2019.3, the properties to get fonts (e.g EditorStyles.standardFont) is changed from getting the value from a backing field to calling EditorResources.GetFont(FontDef.Style.[style]), and the backing field seems to be removed. Changes : UnityCsReference 2019.2 -> UnityCsReference 2019.3

Therefore these lines :

//EditorStyles static was pulled from s_Current which was populated from `EditorGUIUtility.GetBuiltinSkin` which we cannot interfere.
//s_Current is internal and therefore we need to reflect to change the font. All other styles are accessible except the fonts.
var eType = typeof(EditorStyles);
var es = (EditorStyles)(eType.GetField("s_Current", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null));
eType.GetField("m_StandardFont", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(es, normalFont);
eType.GetField("m_BoldFont", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(es, boldFont);
eType.GetField("m_MiniFont", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(es, smallFont);
eType.GetField("m_MiniBoldFont", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(es, smallBoldFont);

will throw either NullPointerException or FieldNotFoundException and the code will no longer works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions