123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- [Serializable]
- public class BMFont
- {
- public bool isValid
- {
- get
- {
- return this.mSaved.Count > 0;
- }
- }
- public int charSize
- {
- get
- {
- return this.mSize;
- }
- set
- {
- this.mSize = value;
- }
- }
- public int baseOffset
- {
- get
- {
- return this.mBase;
- }
- set
- {
- this.mBase = value;
- }
- }
- public int texWidth
- {
- get
- {
- return this.mWidth;
- }
- set
- {
- this.mWidth = value;
- }
- }
- public int texHeight
- {
- get
- {
- return this.mHeight;
- }
- set
- {
- this.mHeight = value;
- }
- }
- public int glyphCount
- {
- get
- {
- return (!this.isValid) ? 0 : this.mSaved.Count;
- }
- }
- public string spriteName
- {
- get
- {
- return this.mSpriteName;
- }
- set
- {
- this.mSpriteName = value;
- }
- }
- public List<BMGlyph> glyphs
- {
- get
- {
- return this.mSaved;
- }
- }
- public BMGlyph GetGlyph(int index, bool createIfMissing)
- {
- BMGlyph bmglyph = null;
- if (this.mDict.Count == 0)
- {
- int i = 0;
- int count = this.mSaved.Count;
- while (i < count)
- {
- BMGlyph bmglyph2 = this.mSaved[i];
- this.mDict.Add(bmglyph2.index, bmglyph2);
- i++;
- }
- }
- if (!this.mDict.TryGetValue(index, out bmglyph) && createIfMissing)
- {
- bmglyph = new BMGlyph();
- bmglyph.index = index;
- this.mSaved.Add(bmglyph);
- this.mDict.Add(index, bmglyph);
- }
- return bmglyph;
- }
- public BMGlyph GetGlyph(int index)
- {
- return this.GetGlyph(index, false);
- }
- public void Clear()
- {
- this.mDict.Clear();
- this.mSaved.Clear();
- }
- public void Trim(int xMin, int yMin, int xMax, int yMax)
- {
- if (this.isValid)
- {
- int i = 0;
- int count = this.mSaved.Count;
- while (i < count)
- {
- BMGlyph bmglyph = this.mSaved[i];
- if (bmglyph != null)
- {
- bmglyph.Trim(xMin, yMin, xMax, yMax);
- }
- i++;
- }
- }
- }
- [HideInInspector]
- [SerializeField]
- private int mSize = 16;
- [HideInInspector]
- [SerializeField]
- private int mBase;
- [HideInInspector]
- [SerializeField]
- private int mWidth;
- [HideInInspector]
- [SerializeField]
- private int mHeight;
- [HideInInspector]
- [SerializeField]
- private string mSpriteName;
- [HideInInspector]
- [SerializeField]
- private List<BMGlyph> mSaved = new List<BMGlyph>();
- private Dictionary<int, BMGlyph> mDict = new Dictionary<int, BMGlyph>();
- }
|