FontLoader.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using FairyGUI;
  2. using System.Threading.Tasks;
  3. using UnityEngine;
  4. using YooAsset;
  5. namespace GFGGame
  6. {
  7. public class FontLoader : SingletonBase<FontLoader>
  8. {
  9. public async Task Init()
  10. {
  11. Font font0 = await LoadFontAsync(ResPathUtil.GetFontPath("FangZhengHeiTiJianTi-1", "ttf"));
  12. FontManager.RegisterFont(new DynamicFont("FangZhengHeiTiJianTi-1", font0));
  13. Font font1 = await LoadFontAsync(ResPathUtil.GetFontPath("FZKTJW--GB1-0", "ttf"));
  14. FontManager.RegisterFont(new DynamicFont("FZKTJW--GB1-0", font1));
  15. Font font2 = await LoadFontAsync(ResPathUtil.GetFontPath("SourceHanSerifCN-Regular-1", "otf"));
  16. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Regular-1", font2));
  17. Font font3 = await LoadFontAsync(ResPathUtil.GetFontPath("SourceHanSerifCN-Bold-2", "otf"));
  18. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Bold-2", font3));
  19. Font font4 = await LoadFontAsync(ResPathUtil.GetFontPath("SourceHanSerifCN-ExtraLight-3", "otf"));
  20. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-ExtraLight-3", font4));
  21. Font font5 = await LoadFontAsync(ResPathUtil.GetFontPath("SourceHanSerifCN-Heavy-4", "otf"));
  22. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Heavy-4", font5));
  23. Font font6 = await LoadFontAsync(ResPathUtil.GetFontPath("SourceHanSerifCN-Light-5", "otf"));
  24. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Light-5", font6));
  25. Font font7 = await LoadFontAsync(ResPathUtil.GetFontPath("SourceHanSerifCN-Medium-6", "otf"));
  26. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Medium-6", font7));
  27. Font font8 = await LoadFontAsync(ResPathUtil.GetFontPath("SourceHanSerifCN-SemiBold-7", "otf"));
  28. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-SemiBold-7", font8));
  29. }
  30. private async Task<Font> LoadFontAsync(string resPath)
  31. {
  32. AssetOperationHandle handle = YooAssets.LoadAssetAsync<Font>(resPath);
  33. await handle.Task;
  34. return handle.AssetObject as Font;
  35. }
  36. }
  37. }