using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
/*
* Author:W
* 以txt文本格式形式从Resource文件夹下加载lua文件运行
*/
public class LuaFileLoaderResource : MonoBehaviour
{
private LuaEnv luaEnv;
// Start is called before the first frame update
void Start()
{
//注意:指定Resources的加载类型为TextAsset时,会去寻找.txt格式的文件
TextAsset luaTextAsset = Resources.Load<TextAsset>("HelloUnity.lua");
luaEnv = new LuaEnv();
luaEnv.DoString(luaTextAsset.text);
}
private void OnDestroy()
{
luaEnv.Dispose();
}
}
运行结果截图如下: