public static byte[] ReadByteForLua(string fileName) { #if UNITY_EDITOR return(System.IO.File.ReadAllBytes(PathTools.Combine(Application.dataPath + "/Resources", fileName))); #else return(ReadRes.ReadByte(fileName)); #endif }
public Csvr ReadStr(String text, char sep, char quote) { Reader reader = new Reader(text, sep, quote); List <String> columns = new List <String>(); List <String[]> rows = new List <String[]>(); while (true) { String column; ReadRes res = reader.ReadStr(out column); if (res.HasFlag(ReadRes.DataRead)) { columns.Add(column); if (res.HasFlag(ReadRes.Sep | ReadRes.EOF)) { columns.Add(""); } } else { if (res.HasFlag(ReadRes.Sep)) { columns.Add(""); } if (res.HasFlag(ReadRes.EOF) || res.HasFlag(ReadRes.EOL)) { if (columns.Count != 0) { columns.Add(""); } } } if (res.HasFlag(ReadRes.EOL)) { rows.Add(columns.ToArray()); columns.Clear(); } else if (res.HasFlag(ReadRes.EOF)) { if (columns.Count != 0) { rows.Add(columns.ToArray()); columns.Clear(); } break; } } Rows = rows.ToArray(); return(this); }
private void DecodeCsv(string text, char sep, char quote) { Reader reader = new Reader(text, sep, quote); List <String> columns = new List <String>(); List <String[]> rows = new List <String[]>(); while (true) { String column; ReadRes res = reader.ReadStr(out column); if (0 != (res & ReadRes.DataRead)) { columns.Add(column); if (ReadRes.SepAndEOF == (res & ReadRes.SepAndEOF)) { columns.Add(""); } } else { if (0 != (res & ReadRes.Sep)) { columns.Add(""); } if (0 != (res & ReadRes.EOF) || 0 != (res & ReadRes.EOL)) { if (columns.Count != 0) { columns.Add(""); } } } if (0 != (res & ReadRes.EOL)) { rows.Add(columns.ToArray()); columns.Clear(); } else if (0 != (res & ReadRes.EOF)) { if (columns.Count != 0) { rows.Add(columns.ToArray()); columns.Clear(); } break; } } Rows = rows.ToArray(); }
public virtual void Init() { if (scriptEnv != null) { return; } if (string.IsNullOrEmpty(luaPath)) { luaFilePathDic.TryGetValue(gameObject, out luaPath); luaFilePathDic.Remove(gameObject); } if (string.IsNullOrEmpty(luaPath)) { Debug.LogError(" luaPath = null !"); return; } if (!luaPath.Trim().EndsWith(".lua")) { luaPath = luaPath + ".lua"; } string luaCode; string filePath; byte[] code = null; #if UNITY_EDITOR /* 在编辑器下从 Resources 下加载 */ filePath = Application.dataPath + "/Resources/" + luaPath; code = System.IO.File.ReadAllBytes(filePath); Debug.LogWarningFormat("LuaBaseBehaviour load file {0}", filePath); #else //filePath = Application.persistentDataPath + "/" + luaPath; code = ReadRes.ReadByte(luaPath); #endif if (code == null) { Debug.LogError("lua code is null " + luaPath); return; } luaEnv = LuaManager.GetInstance().LuaEnvGetOrNew(); scriptEnv = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); scriptEnv.Set("scriptEnv", scriptEnv); if (injections != null) { foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } } scriptEnv.Set("luaPath", luaPath); luaEnv.DoString(code, "LuaBaseBehaviour", scriptEnv); //luaEnv.DoString(string.Format("require '{0}'",luaPath), "LuaBaseBehaviour_"+gameObject.GetInstanceID(), scriptEnv); //luaEnv.DoString("function awake()\n\nend\t\n\nfunction start()\n\tprint(\"LuaBaseBehaviour start...\"..self.luaPath)\nend\n\nfunction update()\n\tlocal r = CS.UnityEngine.Vector3.up * CS.UnityEngine.Time.deltaTime\n\tself.transform:Rotate(r)\nend\n\nfunction ondestroy()\n print(\"LuaBaseBehaviour destroy...\"..self.luaPath)\nend", "LuaBaseBehaviour", scriptEnv); scriptEnv.Get("awake", out luaAwake); /* * if (luaAwake == null) { * Debug.LogError ("awake null"); * } else { * Debug.LogError ("awake "); * } */ //#if UNITY_EDITOR if (luaAwake != null && !luaAwakeInited) { luaAwake(); luaAwakeInited = true; } //#endif scriptEnv.Get("start", out luaStart); //scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); }
public static byte[] ReadByte(string fileName) { return(ReadRes.ReadByte(fileName)); }
private IEnumerable <ReadRes> FilterSharedFiles(IEnumerable <ReadRes> sharedFiles, ReadRes puzzleFile) { var sharedFilesToInclude = puzzleFile.Requires.Select(req => sharedFiles.FirstOrDefault(shared => FileNameMatch(shared.FileName, req))).Where(i => i != null).ToList(); if (sharedFilesToInclude.Count != puzzleFile.Requires.Count) { LogError($"X Include count for file incorrect, expected {puzzleFile.Requires.Count}, but found {sharedFilesToInclude.Count} shared"); } sharedFilesToInclude = sharedFilesToInclude.Distinct(new FileResComparer()).ToList(); return(sharedFilesToInclude); }