C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
using System.IO;
using System.Text;
using UnityEngine.UI;
public class TestXLua : MonoBehaviour
{
LuaEnv lua;
void Start()
{
lua = new LuaEnv();
//加载Lua
lua.AddLoader(LoadLua);
lua.DoString("require 'TestLua'");
}
byte[] LoadLua(ref string file)
{
Debug.Log(file);
string slua = File.ReadAllText(Application.dataPath + "/Lua/" + file + ".lua");
byte[] bytes = new UTF8Encoding().GetBytes(slua);
return bytes;
}
void OnDestroy()
{
lua.Dispose();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player
{
public void PFunction()
{
Debug.Log("PFunction:");
}
public void PFunction(int i,float f)
{
Debug.Log("PFunction:" + i + "/" + f);
}
public void PFunction(int i, string s)
{
Debug.Log("PFunction:" + i + "/" + s);
}
}
Lua
player = CS.Player()
player:PFunction()
player:PFunction(12,12.6)
player:PFunction(24,"aaa")