u3dchina_Unity_tolua基础教学2_lua调c#
创建一个c# 文件(代码如下):using System.Collections;using System.Collections.Generic;
using UnityEngine;
using LuaInterface;
public class GameDebugTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//创建lua虚拟机
LuaStateluaState = new LuaState();
//绑定lua虚拟机
LuaBinder.Bind(luaState);
luaState.Start();
string fullPath = Application.dataPath + "\\ToLua/Test";
luaState.AddSearchPath(fullPath);
LuaTable lt = luaState.DoFile<LuaTable>( "TestLuaToC.lua");
//调用lua游戏入口
lt.Call("GameEnter", lt);
lt.Dispose();
}
// Update is called once per frame
void Update()
{
}
public static void LogError(object msg)
{
Debug.LogError("打印:" + msg.ToString());
}
}
建立一个lua脚本放到Asset/ToLua/Test 中,GameDebugTest.js local Main={};
local c1,c2;
function Main:GameEnter()
GameDebugTest.LogError("开始");
end
returnMain;在Assets/Editor/Custom/CustomSetting.js中增加lua对c#的绑定,在 _GT(typeof(SleepTimeout)),后面增加一行 _GT(typeof(GameDebugTest)),
运行结果:
页:
[1]