public static string GetText(TextAsset textAsset) { ByteReader byteReader = new ByteReader(textAsset); string contents = ""; if (byteReader.canRead) { contents = byteReader.ReadLine(); } while (byteReader.canRead) { contents = contents + '\n' + byteReader.ReadLine(); } return(contents); }
public string ReadLine(bool skipEmptyLines) { int num = this.mBuffer.Length; if (skipEmptyLines) { while (this.mOffset < num && this.mBuffer[this.mOffset] < 32) { this.mOffset++; } } int i = this.mOffset; if (i < num) { while (i < num) { int num2 = (int)this.mBuffer[i++]; if (num2 == 10 || num2 == 13) { IL_87: string result = ByteReader.ReadLine(this.mBuffer, this.mOffset, i - this.mOffset - 1); this.mOffset = i; return(result); } } i++; goto IL_87; } this.mOffset = num; return(null); }
static public int ReadLine(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 1) { ByteReader self = (ByteReader)checkSelf(l); var ret = self.ReadLine(); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 2) { ByteReader self = (ByteReader)checkSelf(l); System.Boolean a1; checkType(l, 2, out a1); var ret = self.ReadLine(a1); pushValue(l, true); pushValue(l, ret); return(2); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
/* fields */ /* methods */ public static void init(byte[] bytes) { dic = new Dictionary <string, string> (); ByteReader reader = new ByteReader(bytes); while (reader.canRead) { string str = reader.ReadLine().Trim(); if (str.StartsWith("#")) { continue; } string[] strs = str.Split(chars); if (strs.Length < 2) { continue; } dic [strs [0]] = strs [1]; } }
public string ReadLine() { int length = (int)this.mBuffer.Length; while (this.mOffset < length && this.mBuffer[this.mOffset] < 32) { ByteReader byteReader = this; byteReader.mOffset = byteReader.mOffset + 1; } int num = this.mOffset; if (num >= length) { this.mOffset = length; return(null); } while (true) { if (num >= length) { num++; break; } else { int num1 = num; num = num1 + 1; int num2 = this.mBuffer[num1]; if (num2 == 10 || num2 == 13) { break; } } } string str = ByteReader.ReadLine(this.mBuffer, this.mOffset, num - this.mOffset - 1); this.mOffset = num; return(str); }
static public string Read() { TextAsset ta = (TextAsset)Resources.Load(VersionFilePath); if (ta == null) { NGUIDebug.Log("加载记录版本文件失败: " + VersionFilePath); return(""); } ByteReader reader = new ByteReader(ta); try { CurRecordVersion = reader.ReadLine(); Debug.Log("读取:" + CurRecordVersion); } catch (Exception ex) { throw ex; } return(CurRecordVersion); }
public string ReadLine(bool skipEmptyLines) { int length = this.mBuffer.Length; if (skipEmptyLines) { while (this.mOffset < length && (int)this.mBuffer[this.mOffset] < 32) { ++this.mOffset; } } int mOffset = this.mOffset; if (mOffset < length) { while (mOffset < length) { switch (this.mBuffer[mOffset++]) { case 10: case 13: goto label_7; default: continue; } } ++mOffset; label_7: string str = ByteReader.ReadLine(this.mBuffer, this.mOffset, mOffset - this.mOffset - 1); this.mOffset = mOffset; return(str); } this.mOffset = length; return((string)null); }
/// <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 { Debug.LogError("Unexpected number of entries for the 'common' field (" + name + ", " + split.Length + "):\n" + line); break; } } else if (split[0] == "page") { // Expected data style: // page id=0 file="textureName.png" if (len > 2) { font.spriteName = GetString(split[2]).Replace("\"", ""); font.spriteName = font.spriteName.Replace(".png", ""); font.spriteName = font.spriteName.Replace(".tga", ""); } } } } }
/// <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 { Debug.LogError("Unexpected number of entries for the 'common' field (" + name + ", " + split.Length + "):\n" + line); break; } } else if (split[0] == "page") { // Expected data style: // page id=0 file="textureName.png" if (len > 2) { font.spriteName = GetString(split[2]).Replace("\"", ""); font.spriteName = font.spriteName.Replace(".png", ""); font.spriteName = font.spriteName.Replace(".tga", ""); } } } } }
/// <summary> /// Opens the INI file at the given path and enumerates the values in the IniParser. /// </summary> /// <param name="iniPath">Full path to INI file.</param> public IniParser(string _loadPath) { String strLine = null; String currentRoot = null; String[] keyPair = null; TextAsset ta = (TextAsset)Resources.Load(_loadPath); if (ta == null) { NGUIDebug.Log("加载Ini配置文件失败: " + _loadPath); return; } ByteReader reader = new ByteReader(ta); try { strLine = reader.ReadLine(); while (strLine != null) { strLine = strLine.Trim().ToUpper(); if (strLine != "") { if (strLine.StartsWith("[") && strLine.EndsWith("]")) { currentRoot = strLine.Substring(1, strLine.Length - 2); } else { keyPair = strLine.Split(new char[] { '=' }, 2); SectionPair sectionPair; String value = null; if (currentRoot == null) { currentRoot = "ROOT"; } sectionPair.Section = currentRoot; sectionPair.Key = keyPair[0]; if (keyPair.Length > 1) { value = keyPair[1]; } keyPairs.Add(sectionPair, value); } } strLine = reader.ReadLine(); } } catch (Exception ex) { throw ex; } }
private static List <CharInfo> GetCharInfo(byte[] textBytes, ref FontTxt fontTxt, ref string txtName) { if (textBytes == null) { return(null); } List <CharInfo> charInfos = new List <CharInfo>(); ByteReader reader = new ByteReader(textBytes); char[] separater = new char[] { ' ' }; while (reader.canRead) { string line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } string[] splits = line.Split(separater, StringSplitOptions.RemoveEmptyEntries); int len = splits.Length; if (splits[0].Equals("char")) { int chnl = len > 10 ? GetInt(splits[10]) : 15; if (len > 9 && GetInt(splits[9]) > 0) { Debug.LogError("Your font was exported with more than one texture. Only one texture is supported by ArtistFont.\n" + "You need to re-export your font, enlarging the texture's dimensions until everything fits into just one texture."); break; } if (len > 8) { CharInfo charInfo = new CharInfo(); charInfo.index = GetInt(splits[1]); charInfo.x = GetInt(splits[2]); charInfo.y = GetInt(splits[3]); charInfo.width = GetInt(splits[4]); charInfo.height = GetInt(splits[5]); charInfo.offsetX = GetInt(splits[6]); charInfo.offsetY = GetInt(splits[7]); charInfo.advance = GetInt(splits[8]); charInfo.channel = chnl; charInfos.Add(charInfo); } else { Debug.LogError("Unexpected number of entries for the 'char' field with " + splits.Length + "\n" + line); break; } } else if (splits[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) { fontTxt.charSize = GetInt(splits[1]); fontTxt.baseOffset = GetInt(splits[2]); fontTxt.texWidth = GetInt(splits[3]); fontTxt.texHeight = GetInt(splits[4]); int pages = GetInt(splits[5]); if (pages != 1) { Debug.LogError("Artist Font must be created with only 1 texture, not " + pages); break; } } else { Debug.LogError("Unexpected number of entries for the 'common' field:\n" + line); break; } } else if (splits[0] == "page") { // Expected data style: // page id=0 file="textureName.png" if (len > 2) { txtName = GetString(splits[2]).Replace("\"", ""); } } } return(charInfos); }
public unsafe static long $Invoke6(long instance, long *args) { return(GCHandledObjects.ObjectToGCHandle(ByteReader.ReadLine((byte[])GCHandledObjects.GCHandleToPinnedArrayObject(*args), *(int *)(args + 1), *(int *)(args + 2)))); }
/// <summary> /// Load the specified localization dictionary. /// </summary> static bool LoadDictionary(string value) { // Try to load the Localization CSV byte[] bytes = null; if (!localizationHasBeenSet) { if (loadFunction == null) { TextAsset asset = Resources.Load <TextAsset>("Localization"); if (asset != null) { bytes = asset.bytes; } } else { bytes = loadFunction("Localization"); } localizationHasBeenSet = true; ByteReader reader = new ByteReader(bytes); List <string> strList = new List <string>(); while (reader.canRead) { string str = reader.ReadLine(); if (str != null) { strList.Add(str); } } mLanguages = new string[strList.Count]; for (int i = 0; i < mLanguages.Length; ++i) { mLanguages[i] = strList[i]; } mDictionary.Clear(); } // Try to load the localization file //if (LoadCSV(bytes)) return true; // If this point was reached, the localization file was not present if (string.IsNullOrEmpty(value)) { return(false); } // Not a referenced asset -- try to load it dynamically if (loadFunction == null) { TextAsset asset = Resources.Load <TextAsset>(value); if (asset != null) { bytes = asset.bytes; } } else { bytes = loadFunction(value); } if (bytes != null) { Set(value, bytes); return(true); } return(false); }
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); } } } }