Guest User

Untitled

a guest
Oct 24th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #if UNITY_EDITOR
  2. using System.Reflection;
  3. using UnityEngine;
  4. using UnityEditor;
  5.  
  6. public class FontSwitcher : EditorWindow
  7. {
  8. [MenuItem("Font/Show Window")]
  9. public static void ShowFontWindow()
  10. {
  11. GetWindow<FontSwitcher>();
  12. }
  13.  
  14. public void OnGUI ()
  15. {
  16. EditorGUI.BeginChangeCheck();
  17. string newFontName = EditorGUILayout.DelayedTextField("Unity Font", GUI.skin.font.fontNames[0]);
  18. if (EditorGUI.EndChangeCheck())
  19. {
  20. ReplaceFont((Font)EditorGUIUtility.LoadRequired("Fonts/Lucida Grande.ttf"), newFontName);
  21. ReplaceFont((Font)EditorGUIUtility.LoadRequired("Fonts/Lucida Grande Bold.ttf"), newFontName);
  22. ReplaceFont((Font)EditorGUIUtility.LoadRequired("Fonts/Lucida Grande Small.ttf"), newFontName);
  23. ReplaceFont((Font)EditorGUIUtility.LoadRequired("Fonts/Lucida Grande Small Bold.ttf"), newFontName);
  24. ReplaceFont((Font)EditorGUIUtility.LoadRequired("Fonts/Lucida Grande Big.ttf"), newFontName);
  25.  
  26. typeof(EditorApplication).GetMethod("RequestRepaintAllViews", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
  27. }
  28. }
  29.  
  30. private void ReplaceFont(Font font, string fontName)
  31. {
  32. if (font.name.Contains("Bold"))
  33. font.fontNames = new string[] { fontName + " Bold" };
  34. else
  35. font.fontNames = new string[] { fontName };
  36. font.hideFlags = HideFlags.HideAndDontSave;
  37. }
  38. }
  39. #endif
Add Comment
Please, Sign In to add comment