FontManager.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using UnityEngine;
  2. using System.Collections;
  3. /// <summary>
  4. /// 字体管理者,向外部提供字体
  5. /// </summary>
  6. public class FontManager : MonoBehaviour
  7. {
  8. /// <summary>
  9. /// 单键
  10. /// </summary>
  11. private static FontManager pInit = null;
  12. /// <summary>
  13. /// UI字体
  14. /// </summary>
  15. [SerializeField]
  16. private Font uiFont = null;
  17. /// <summary>
  18. /// 获取字体管理者
  19. /// </summary>
  20. /// <returns>单键实例</returns>
  21. public static FontManager Instance()
  22. {
  23. return pInit;
  24. }
  25. /// <summary>
  26. /// 初始化
  27. /// </summary>
  28. private void Awake()
  29. {
  30. pInit = this;
  31. Init();
  32. // 切换关卡时不删除
  33. DontDestroyOnLoad(this);
  34. }
  35. /// <summary>
  36. /// 获取当前字体
  37. /// </summary>
  38. public Font CurFont
  39. {
  40. get
  41. {
  42. return uiFont;
  43. }
  44. }
  45. private string chineseText = null;
  46. public void Init()
  47. {
  48. if (chineseText == null)
  49. {
  50. var wordFileRes = Resources.Load("Font/chineseWords");
  51. if (wordFileRes != null)
  52. {
  53. TextAsset worldFile = wordFileRes as TextAsset;
  54. chineseText = worldFile.text;
  55. chineseText = worldFile.text;
  56. Debug.Log(string.Format("chinese font size: {0}", chineseText.Length));
  57. }
  58. }
  59. ////uiFont = Resources.Load("Font/AMCSL", typeof(Font)) as Font;
  60. ////uiFont.material = Resources.Load("Font/AMCSL", typeof(Material)) as Material;
  61. ////if (uiFont != null)
  62. ////{
  63. //// uiFont.RequestCharactersInTexture(chineseText);
  64. //// Texture texture = uiFont.material.mainTexture;
  65. //// Debug.Log(string.Format("Texture size: {0}, {1}", texture.width, texture.height));
  66. ////}
  67. }
  68. }