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();
}
}
運行結果截圖如下: