private void initDictionary(PFontInfo pfontInfo) { chars = new Dictionary <char, CharInfo>(); Sprite[] sprites = Resources.LoadAll <Sprite>(pfontInfo.path); //Debug.Log("" + pfontInfo.path + " " + sprites.Length); Char[] chs = pfontInfo.characters.ToCharArray(); int i = 0; float width = 0; foreach (char ch in chs) { CharInfo ci = new CharInfo(ch, sprites[i], sprites[i].rect.width); chars[ch] = ci; if (sprites[i].rect.width > width) { width = sprites[i].rect.width; } i++; } charWidthInPixel = width; charHeightInPixel = sprites[0].rect.height; }
public PFontLoader(PFontInfo pfontInfo) { if (pfontInfo == null) { throw new ArgumentNullException(); } PFontLoader pFontLoader; PFontDict.TryGetValue(pfontInfo, out pFontLoader); if (pFontLoader != null) { chars = pFontLoader.chars; charWidthInPixel = pFontLoader.charWidthInPixel; charHeightInPixel = pFontLoader.charHeightInPixel; } else { initDictionary(pfontInfo); PFontDict[pfontInfo] = this; } }