三国卡牌客户端基础资源仓库
hch
8 天以前 7f957ecb475adb30eb692884d22412b765fa1a7d
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
//----------------------------------------------
//            NGUI: Next-Gen UI kit
// Copyright © 2011-2014 Tasharen Entertainment
//----------------------------------------------
 
using UnityEngine;
using System.Collections.Generic;
 
/// <summary>
/// BMFont reader. C# implementation of http://www.angelcode.com/products/bmfont/
/// </summary>
 
[System.Serializable]
public class BMFont
{
    [HideInInspector][SerializeField] int mSize = 16;            // How much to move the cursor when moving to the next line
    [HideInInspector][SerializeField] int mBase = 0;            // Offset from the top of the line to the base of each character
    [HideInInspector][SerializeField] int mWidth = 0;            // Original width of the texture
    [HideInInspector][SerializeField] int mHeight = 0;            // Original height of the texture
    [HideInInspector][SerializeField] string mSpriteName;
 
    // List of serialized glyphs
    [HideInInspector][SerializeField] List<BMGlyph> mSaved = new List<BMGlyph>();
 
    // Actual glyphs that we'll be working with are stored in a dictionary, making the lookup faster
    Dictionary<int, BMGlyph> mDict = new Dictionary<int, BMGlyph>();
 
    /// <summary>
    /// Whether the font can be used.
    /// </summary>
 
    public bool isValid { get { return (mSaved.Count > 0); } }
 
    /// <summary>
    /// Size of this font (for example 32 means 32 pixels).
    /// </summary>
 
    public int charSize { get { return mSize; } set { mSize = value; } }
 
    /// <summary>
    /// Base offset applied to characters.
    /// </summary>
 
    public int baseOffset { get { return mBase; } set { mBase = value; } }
 
    /// <summary>
    /// Original width of the texture.
    /// </summary>
 
    public int texWidth { get { return mWidth; } set { mWidth = value; } }
 
    /// <summary>
    /// Original height of the texture.
    /// </summary>
 
    public int texHeight { get { return mHeight; } set { mHeight = value; } }
 
    /// <summary>
    /// Number of valid glyphs.
    /// </summary>
 
    public int glyphCount { get { return isValid ? mSaved.Count : 0; } }
 
    /// <summary>
    /// Original name of the sprite that the font is expecting to find (usually the name of the texture).
    /// </summary>
 
    public string spriteName { get { return mSpriteName; } set { mSpriteName = value; } }
 
    /// <summary>
    /// Access to BMFont's entire set of glyphs.
    /// </summary>
 
    public List<BMGlyph> glyphs { get { return mSaved; } }
 
    /// <summary>
    /// Helper function that retrieves the specified glyph, creating it if necessary.
    /// </summary>
 
    public BMGlyph GetGlyph (int index, bool createIfMissing)
    {
        // Get the requested glyph
        BMGlyph glyph = null;
 
        if (mDict.Count == 0)
        {
            // Populate the dictionary for faster access
            for (int i = 0, imax = mSaved.Count; i < imax; ++i)
            {
                BMGlyph bmg = mSaved[i];
                mDict.Add(bmg.index, bmg);
            }
        }
 
        // Saved check is here so that the function call is not needed if it's true
        if (!mDict.TryGetValue(index, out glyph) && createIfMissing)
        {
            glyph = new BMGlyph();
            glyph.index = index;
            mSaved.Add(glyph);
            mDict.Add(index, glyph);
        }
        return glyph;
    }
 
    /// <summary>
    /// Retrieve the specified glyph, if it's present.
    /// </summary>
 
    public BMGlyph GetGlyph (int index) { return GetGlyph(index, false); }
 
    /// <summary>
    /// Clear the glyphs.
    /// </summary>
 
    public void Clear ()
    {
        mDict.Clear();
        mSaved.Clear();
    }
 
    /// <summary>
    /// Trim the glyphs, ensuring that they will never go past the specified bounds.
    /// </summary>
 
    public void Trim (int xMin, int yMin, int xMax, int yMax)
    {
        if (isValid)
        {
            for (int i = 0, imax = mSaved.Count; i < imax; ++i)
            {
                BMGlyph glyph = mSaved[i];
                if (glyph != null) glyph.Trim(xMin, yMin, xMax, yMax);
            }
        }
    }
}