public void ChangeFont(object ui) { if (ui == null) { return; } var type = ui.GetType(); if (ClrTypes.Text != null && ClrTypes.Text.IsAssignableFrom(type)) { if (string.IsNullOrEmpty(Settings.OverrideFont)) { return; } var Text_fontProperty = ClrTypes.Text.CachedProperty("font"); var Text_fontSizeProperty = ClrTypes.Text.CachedProperty("fontSize"); var previousFont = (Font)Text_fontProperty.Get(ui); var Font_fontSizeProperty = previousFont.GetType().CachedProperty("fontSize"); var newFont = FontCache.GetOrCreate((int?)Font_fontSizeProperty?.Get(previousFont) ?? (int)Text_fontSizeProperty.Get(ui)); if (newFont == null || previousFont == null) { return; } if (!ReferenceEquals(newFont, previousFont)) { Text_fontProperty.Set(ui, newFont); _unfont = obj => { Text_fontProperty.Set(obj, previousFont); }; } } else if ((ClrTypes.TextMeshPro != null && ClrTypes.TextMeshPro.IsAssignableFrom(type)) || (ClrTypes.TextMeshProUGUI != null && ClrTypes.TextMeshProUGUI.IsAssignableFrom(type))) { if (string.IsNullOrEmpty(Settings.OverrideFontTextMeshPro)) { return; } var fontProperty = ReflectionCache.CachedProperty(type, "font"); var previousFont = fontProperty.Get(ui); var newFont = FontCache.GetOrCreateTextMeshProFont(); if (newFont == null || previousFont == null) { return; } if (!ReferenceEquals(newFont, previousFont)) { fontProperty.Set(ui, newFont); _unfont = obj => { fontProperty.Set(obj, previousFont); }; } } }