BMFont.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [Serializable]
  5. public class BMFont
  6. {
  7. public bool isValid
  8. {
  9. get
  10. {
  11. return this.mSaved.Count > 0;
  12. }
  13. }
  14. public int charSize
  15. {
  16. get
  17. {
  18. return this.mSize;
  19. }
  20. set
  21. {
  22. this.mSize = value;
  23. }
  24. }
  25. public int baseOffset
  26. {
  27. get
  28. {
  29. return this.mBase;
  30. }
  31. set
  32. {
  33. this.mBase = value;
  34. }
  35. }
  36. public int texWidth
  37. {
  38. get
  39. {
  40. return this.mWidth;
  41. }
  42. set
  43. {
  44. this.mWidth = value;
  45. }
  46. }
  47. public int texHeight
  48. {
  49. get
  50. {
  51. return this.mHeight;
  52. }
  53. set
  54. {
  55. this.mHeight = value;
  56. }
  57. }
  58. public int glyphCount
  59. {
  60. get
  61. {
  62. return (!this.isValid) ? 0 : this.mSaved.Count;
  63. }
  64. }
  65. public string spriteName
  66. {
  67. get
  68. {
  69. return this.mSpriteName;
  70. }
  71. set
  72. {
  73. this.mSpriteName = value;
  74. }
  75. }
  76. public List<BMGlyph> glyphs
  77. {
  78. get
  79. {
  80. return this.mSaved;
  81. }
  82. }
  83. public BMGlyph GetGlyph(int index, bool createIfMissing)
  84. {
  85. BMGlyph bmglyph = null;
  86. if (this.mDict.Count == 0)
  87. {
  88. int i = 0;
  89. int count = this.mSaved.Count;
  90. while (i < count)
  91. {
  92. BMGlyph bmglyph2 = this.mSaved[i];
  93. this.mDict.Add(bmglyph2.index, bmglyph2);
  94. i++;
  95. }
  96. }
  97. if (!this.mDict.TryGetValue(index, out bmglyph) && createIfMissing)
  98. {
  99. bmglyph = new BMGlyph();
  100. bmglyph.index = index;
  101. this.mSaved.Add(bmglyph);
  102. this.mDict.Add(index, bmglyph);
  103. }
  104. return bmglyph;
  105. }
  106. public BMGlyph GetGlyph(int index)
  107. {
  108. return this.GetGlyph(index, false);
  109. }
  110. public void Clear()
  111. {
  112. this.mDict.Clear();
  113. this.mSaved.Clear();
  114. }
  115. public void Trim(int xMin, int yMin, int xMax, int yMax)
  116. {
  117. if (this.isValid)
  118. {
  119. int i = 0;
  120. int count = this.mSaved.Count;
  121. while (i < count)
  122. {
  123. BMGlyph bmglyph = this.mSaved[i];
  124. if (bmglyph != null)
  125. {
  126. bmglyph.Trim(xMin, yMin, xMax, yMax);
  127. }
  128. i++;
  129. }
  130. }
  131. }
  132. [HideInInspector]
  133. [SerializeField]
  134. private int mSize = 16;
  135. [HideInInspector]
  136. [SerializeField]
  137. private int mBase;
  138. [HideInInspector]
  139. [SerializeField]
  140. private int mWidth;
  141. [HideInInspector]
  142. [SerializeField]
  143. private int mHeight;
  144. [HideInInspector]
  145. [SerializeField]
  146. private string mSpriteName;
  147. [HideInInspector]
  148. [SerializeField]
  149. private List<BMGlyph> mSaved = new List<BMGlyph>();
  150. private Dictionary<int, BMGlyph> mDict = new Dictionary<int, BMGlyph>();
  151. }