本文整理汇总了C#中ByteReader.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# ByteReader.ReadLine方法的具体用法?C# ByteReader.ReadLine怎么用?C# ByteReader.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteReader
的用法示例。
在下文中一共展示了ByteReader.ReadLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// Reload the font data.
/// </summary>
static public void Load (BMFont font, string name, byte[] bytes)
{
font.Clear();
if (bytes != null)
{
ByteReader reader = new ByteReader(bytes);
char[] separator = new char[] { ' ' };
while (reader.canRead)
{
string line = reader.ReadLine();
if (string.IsNullOrEmpty(line)) break;
string[] split = line.Split(separator, System.StringSplitOptions.RemoveEmptyEntries);
int len = split.Length;
if (split[0] == "char")
{
// Expected data style:
// char id=13 x=506 y=62 width=3 height=3 xoffset=-1 yoffset=50 xadvance=0 page=0 chnl=15
int channel = (len > 10) ? GetInt(split[10]) : 15;
if (len > 9 && GetInt(split[9]) > 0)
{
Debug.LogError("Your font was exported with more than one texture. Only one texture is supported by NGUI.\n" +
"You need to re-export your font, enlarging the texture's dimensions until everything fits into just one texture.");
break;
}
if (len > 8)
{
int id = GetInt(split[1]);
BMGlyph glyph = font.GetGlyph(id, true);
if (glyph != null)
{
glyph.x = GetInt(split[2]);
glyph.y = GetInt(split[3]);
glyph.width = GetInt(split[4]);
glyph.height = GetInt(split[5]);
glyph.offsetX = GetInt(split[6]);
glyph.offsetY = GetInt(split[7]);
glyph.advance = GetInt(split[8]);
glyph.channel = channel;
}
else Debug.Log("Char: " + split[1] + " (" + id + ") is NULL");
}
else
{
Debug.LogError("Unexpected number of entries for the 'char' field (" + name + ", " + split.Length + "):\n" + line);
break;
}
}
else if (split[0] == "kerning")
{
// Expected data style:
// kerning first=84 second=244 amount=-5
if (len > 3)
{
int first = GetInt(split[1]);
int second = GetInt(split[2]);
int amount = GetInt(split[3]);
BMGlyph glyph = font.GetGlyph(second, true);
if (glyph != null) glyph.SetKerning(first, amount);
}
else
{
Debug.LogError("Unexpected number of entries for the 'kerning' field (" +
name + ", " + split.Length + "):\n" + line);
break;
}
}
else if (split[0] == "common")
{
// Expected data style:
// common lineHeight=64 base=51 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=1 redChnl=4 greenChnl=4 blueChnl=4
if (len > 5)
{
font.charSize = GetInt(split[1]);
font.baseOffset = GetInt(split[2]);
font.texWidth = GetInt(split[3]);
font.texHeight = GetInt(split[4]);
int pages = GetInt(split[5]);
if (pages != 1)
{
Debug.LogError("Font '" + name + "' must be created with only 1 texture, not " + pages);
break;
}
}
else
//.........这里部分代码省略.........
示例2: LoadFromByteReader
public void LoadFromByteReader(ByteReader sr)
{
dictionary.Clear();
string line, section = "";
while ((line = sr.ReadLine()) != null)
{
line = line.Trim();
if (line.Length == 0) continue; // empty line
if (!String.IsNullOrEmpty(CommentDelimiter) && line.StartsWith(CommentDelimiter))
continue; // comment
if (line.StartsWith("[") && line.Contains("]")) // [section]
{
int index = line.IndexOf(']');
section = line.Substring(1, index - 1).Trim();
continue;
}
if (line.Contains("=")) // key=value
{
int index = line.IndexOf('=');
string key = line.Substring(0, index).Trim();
string val = line.Substring(index + 1).Trim();
string key2 = String.Format("[{0}]{1}", section, key).ToLower();
if (val.StartsWith("\"") && val.EndsWith("\"")) // strip quotes
val = val.Substring(1, val.Length - 2);
if (dictionary.ContainsKey(key2)) // multiple values can share the same key
{
index = 1;
string key3;
while (true)
{
key3 = String.Format("{0}~{1}", key2, ++index);
if (!dictionary.ContainsKey(key3))
{
dictionary.Add(key3, val);
break;
}
}
}
else
{
dictionary.Add(key2, val);
}
}
}
}