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