编辑代码

using System;
using XLua;
using System.IO;

public class LuaDemo01 : MonoBehaviour
{
    private LuaEnv luaenv;
    void Start()
    {
        env = new LuaEnv();

        // 自定义loader lua文件放在自定义目录 而非Resources目录的情况下
        env.AddLoader(MyLoader);
        env.DoString("require 'test007'");
        
    }


    private byte[] MyLoader(ref string filePath)
    {
        string absPath = Application.streamingAssetsPath + "/" + filePath + ".lua.txt";
        return System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(absPath));        
    }


    private void OnDestroy()
    {
        env.Dispose();  // 释放掉lua环境
    }


}