| | |
| | | |
| | | public class LuaUtility : SingletonMonobehaviour<LuaUtility> |
| | | { |
| | | internal static LuaEnv env = new LuaEnv(); |
| | | public readonly static LuaEnv env = new LuaEnv(); |
| | | static float lastGCTime = 0; |
| | | const float GCInterval = 1;//1 second |
| | | |
| | | static LuaUtility() |
| | | { |
| | | env.AddLoader(new LuaEnv.CustomLoader(LoadAsset)); |
| | | env.AddLoader(new LuaEnv.CustomLoader(LoadAssetBytes)); |
| | | } |
| | | |
| | | public static LuaTable GetNewTable() |
| | | { |
| | | return env.NewTable(); |
| | | } |
| | | |
| | | public static LuaTable Global { |
| | | get { return env.Global; } |
| | | } |
| | | |
| | | public void Init() |
| | |
| | | env.DoString(command, chunkName, _table); |
| | | } |
| | | |
| | | private static byte[] LoadAsset(ref string _fileName) |
| | | public static void DoString(string _file, string chunkName = "chunk", LuaTable _table = null) |
| | | { |
| | | var content = LoadAsset(ref _file); |
| | | env.DoString(content, chunkName, _table); |
| | | } |
| | | |
| | | private static string LoadAsset(ref string _fileName) |
| | | { |
| | | _fileName = _fileName.Replace('.', '/'); |
| | | |
| | | var path = string.Empty; |
| | | byte[] bytes = null; |
| | | |
| | | if (AssetSource.luaFromEditor) |
| | | { |
| | | path = ResourcesPath.LUA_FODLER + "/" + _fileName + ".lua"; |
| | | } |
| | | else |
| | | { |
| | | var assetVersion = AssetVersionUtility.GetAssetVersion(StringUtility.Contact("lua/", _fileName, ".lua")); |
| | | path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, assetVersion.relativePath); |
| | | path = AssetVersionUtility.GetAssetFilePath(StringUtility.Contact("lua/", _fileName, ".lua")); |
| | | } |
| | | |
| | | bytes = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path)); |
| | | return bytes; |
| | | return File.ReadAllText(path); |
| | | } |
| | | |
| | | private static byte[] LoadAssetBytes(ref string _fileName) |
| | | { |
| | | return System.Text.Encoding.UTF8.GetBytes(LoadAsset(ref _fileName)); |
| | | } |
| | | } |