134 lines
3.7 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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");
ResourceMgr.Instance.GetGoFromPoolAsync(Constants.UICommonPath, "SymbolTextInit", (o) =>
{
var go = o;
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 = null;
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);
}
}
}
}