SymbolTextInit.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. namespace WXB
  4. {
  5. public class SymbolTextInit : MonoBehaviour
  6. {
  7. static Dictionary<string, Font> Fonts; // 当前所有的字库
  8. static Dictionary<string, Sprite> Sprites; // 当前所有的精灵
  9. static Dictionary<string, Cartoon> Cartoons; // 当前所有的动画
  10. [SerializeField]
  11. int cartoonWidth = 100;
  12. [SerializeField]
  13. int cartoonHeight = 65;
  14. [SerializeField]
  15. Font[] fonts = null;
  16. [SerializeField]
  17. Sprite[] sprites = null;
  18. [SerializeField]
  19. public Cartoon[] cartoons = null; // 所有的动画
  20. void init()
  21. {
  22. if (Fonts == null)
  23. Fonts = new Dictionary<string, Font>();
  24. else
  25. Fonts.Clear();
  26. if (fonts != null)
  27. {
  28. for (int i = 0; i < fonts.Length; ++i)
  29. Fonts.Add(fonts[i].name, fonts[i]);
  30. }
  31. if (Sprites == null)
  32. Sprites = new Dictionary<string, Sprite>();
  33. else
  34. Sprites.Clear();
  35. if (sprites != null)
  36. {
  37. for (int i = 0; i < sprites.Length; ++i)
  38. Sprites.Add(sprites[i].name, sprites[i]);
  39. }
  40. if (Cartoons == null)
  41. Cartoons = new Dictionary<string, Cartoon>();
  42. else
  43. Cartoons.Clear();
  44. if (cartoons != null)
  45. {
  46. for (int i = 0; i < cartoons.Length; ++i)
  47. {
  48. string[] fps = cartoons[i].content.Split(';');
  49. cartoons[i].fps = new int[fps.Length];
  50. for (int j = 0; j < fps.Length; ++j)
  51. {
  52. int v = 0;
  53. int.TryParse(fps[j], out v);
  54. cartoons[i].fps[j] = v;
  55. }
  56. cartoons[i].frameWidth = cartoonWidth;
  57. cartoons[i].frameHeight = cartoonHeight;
  58. Cartoons.Add(cartoons[i].name, cartoons[i]);
  59. }
  60. }
  61. }
  62. static void Init()
  63. {
  64. //SymbolTextInit sti = Resources.Load<SymbolTextInit>("SymbolTextInit");
  65. var go = ResourceMgr.Instance.GetGoFromPool(Constants.UICommonPath, "SymbolTextInit");
  66. var sti = go.GetComponent<SymbolTextInit>();
  67. sti.init();
  68. }
  69. public static Font GetFont(string name)
  70. {
  71. if (Fonts == null)
  72. Init();
  73. Font font;
  74. if (Fonts.TryGetValue(name, out font))
  75. return font;
  76. return null;
  77. }
  78. public static Sprite GetSprite(string name)
  79. {
  80. if (Sprites == null)
  81. Init();
  82. Sprite sprite;
  83. if (Sprites.TryGetValue(name, out sprite))
  84. return sprite;
  85. return null;
  86. }
  87. public static Cartoon GetCartoon(string name)
  88. {
  89. if (Cartoons == null)
  90. Init();
  91. Cartoon cartoon;
  92. if (Cartoons.TryGetValue(name, out cartoon))
  93. return cartoon;
  94. return null;
  95. }
  96. public static void GetCartoons(List<Cartoon> cartoons)
  97. {
  98. if (Cartoons == null)
  99. Init();
  100. foreach (var itor in Cartoons)
  101. {
  102. cartoons.Add(itor.Value);
  103. }
  104. }
  105. }
  106. }