| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using UnityEngine;
- using System.Collections.Generic;
- namespace WXB
- {
- public class SymbolTextInit : MonoBehaviour
- {
- static Dictionary<string, Font> Fonts; // 当前所有的字库
- static Dictionary<string, Sprite> Sprites; // 当前所有的精灵
- static Dictionary<string, Cartoon> Cartoons; // 当前所有的动画
- [SerializeField]
- int cartoonWidth = 100;
- [SerializeField]
- int cartoonHeight = 65;
- [SerializeField]
- Font[] fonts = null;
- [SerializeField]
- Sprite[] sprites = null;
- [SerializeField]
- public Cartoon[] cartoons = null; // 所有的动画
- void init()
- {
- if (Fonts == null)
- Fonts = new Dictionary<string, Font>();
- else
- Fonts.Clear();
- if (fonts != null)
- {
- for (int i = 0; i < fonts.Length; ++i)
- Fonts.Add(fonts[i].name, fonts[i]);
- }
- if (Sprites == null)
- Sprites = new Dictionary<string, Sprite>();
- else
- Sprites.Clear();
- if (sprites != null)
- {
- for (int i = 0; i < sprites.Length; ++i)
- Sprites.Add(sprites[i].name, sprites[i]);
- }
- if (Cartoons == null)
- Cartoons = new Dictionary<string, Cartoon>();
- else
- Cartoons.Clear();
- if (cartoons != null)
- {
- for (int i = 0; i < cartoons.Length; ++i)
- {
- string[] fps = cartoons[i].content.Split(';');
- cartoons[i].fps = new int[fps.Length];
- for (int j = 0; j < fps.Length; ++j)
- {
- int v = 0;
- int.TryParse(fps[j], out v);
- cartoons[i].fps[j] = v;
- }
- cartoons[i].frameWidth = cartoonWidth;
- cartoons[i].frameHeight = cartoonHeight;
- Cartoons.Add(cartoons[i].name, cartoons[i]);
- }
-
- }
- }
- static void Init()
- {
- //SymbolTextInit sti = Resources.Load<SymbolTextInit>("SymbolTextInit");
- var go = ResourceMgr.Instance.GetGoFromPool(Constants.UICommonPath, "SymbolTextInit");
- var sti = go.GetComponent<SymbolTextInit>();
- sti.init();
- }
- public static Font GetFont(string name)
- {
- if (Fonts == null)
- Init();
- Font font;
- if (Fonts.TryGetValue(name, out font))
- return font;
- return null;
- }
- public static Sprite GetSprite(string name)
- {
- if (Sprites == null)
- Init();
- Sprite sprite;
- if (Sprites.TryGetValue(name, out sprite))
- return sprite;
- return null;
- }
- public static Cartoon GetCartoon(string name)
- {
- if (Cartoons == null)
- Init();
- Cartoon cartoon;
- if (Cartoons.TryGetValue(name, out cartoon))
- return cartoon;
- return null;
- }
- public static void GetCartoons(List<Cartoon> cartoons)
- {
- if (Cartoons == null)
- Init();
-
- foreach (var itor in Cartoons)
- {
- cartoons.Add(itor.Value);
- }
- }
- }
- }
|