FontLoader.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 font1 = await LoadFontAsync(ResPathUtil.GetFontPath2("FZKTJW--GB1-0", "ttf"));
  12. FontManager.RegisterFont(new DynamicFont("FZKTJW--GB1-0", font1));
  13. }
  14. public async Task Init2()
  15. {
  16. Font font0 = await LoadFontAsync(ResPathUtil.GetFontPath1("FangZhengHeiTiJianTi-1", "ttf"));
  17. FontManager.RegisterFont(new DynamicFont("FangZhengHeiTiJianTi-1", font0));
  18. Font font2 = await LoadFontAsync(ResPathUtil.GetFontPath5("SourceHanSerifCN-Regular-1", "otf"));
  19. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Regular-1", font2));
  20. Font font3 = await LoadFontAsync(ResPathUtil.GetFontPath2("SourceHanSerifCN-Bold-2", "otf"));
  21. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Bold-2", font3));
  22. Font font4 = await LoadFontAsync(ResPathUtil.GetFontPath3("SourceHanSerifCN-ExtraLight-3", "otf"));
  23. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-ExtraLight-3", font4));
  24. Font font5 = await LoadFontAsync(ResPathUtil.GetFontPath4("SourceHanSerifCN-Heavy-4", "otf"));
  25. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Heavy-4", font5));
  26. Font font6 = await LoadFontAsync(ResPathUtil.GetFontPath4("SourceHanSerifCN-Light-5", "otf"));
  27. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Light-5", font6));
  28. Font font7 = await LoadFontAsync(ResPathUtil.GetFontPath4("SourceHanSerifCN-Medium-6", "otf"));
  29. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Medium-6", font7));
  30. Font font8 = await LoadFontAsync(ResPathUtil.GetFontPath5("SourceHanSerifCN-SemiBold-7", "otf"));
  31. FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-SemiBold-7", font8));
  32. }
  33. private async Task<Font> LoadFontAsync(string resPath)
  34. {
  35. AssetOperationHandle handle = YooAssets.LoadAssetAsync<Font>(resPath);
  36. await handle.Task;
  37. return handle.AssetObject as Font;
  38. }
  39. }
  40. }