using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using XLua;
|
using System.IO;
|
|
public class LuaLoader
|
{
|
|
static LuaLoader()
|
{
|
LuaUtility.env.AddLoader(new LuaEnv.CustomLoader(LoadAsset));
|
}
|
|
public static void Init()
|
{
|
Load("custom.ButtonUtil");
|
Load("global.logex");
|
}
|
|
public static TextAsset LoadRawFile(string _fileName)
|
{
|
_fileName = _fileName.Replace('.', '/');
|
TextAsset textAsset = null;
|
|
if (AssetSource.luaFromEditor)
|
{
|
#if UNITY_EDITOR
|
var path = ResourcesPath.ResourcesOutAssetPath + "Lua/" + _fileName + ".lua.txt";
|
textAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(path);
|
#endif
|
}
|
else
|
{
|
var pathArray = _fileName.Split('/');
|
var bundleName = StringUtility.Contact("lua/", pathArray[0].ToLower());
|
var assetInfo = new AssetInfo(bundleName, pathArray[1].ToLower());
|
textAsset = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as TextAsset;
|
}
|
|
return textAsset;
|
}
|
|
public static void Load(string _file)
|
{
|
var command = string.Format("require '{0}'", _file);
|
LuaUtility.env.DoString(command);
|
}
|
|
private static byte[] LoadAsset(ref string _fileName)
|
{
|
_fileName = _fileName.Replace('.', '/');
|
|
var path = string.Empty;
|
byte[] bytes = null;
|
|
if (AssetSource.luaFromEditor)
|
{
|
path = ResourcesPath.LUA_FODLER + "/" + _fileName + ".lua.txt";
|
}
|
else
|
{
|
var assetVersion = AssetVersionUtility.GetAssetVersion(StringUtility.Contact("lua/", _fileName, ".lua.txt"));
|
path = StringUtility.Contact(ResourcesPath.Instance.ExternalStorePath, assetVersion.relativePath);
|
}
|
|
bytes = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(path));
|
return bytes;
|
}
|
}
|