Download XLua: https://github.com/tencent/xlua
Used in the project XLua simply Plugins and XLua two folders can be copied to the U3D
XLua just the core for implementing interactive Lua and C #, but does not provide a convenient "framework", we use XLua in the project, then, implement frame section, so as to achieve "Lua download AB and resources from the server to complete the client's hot update"
C # call Lua
a using XLua;
// a LuaEnv example is a Lua virtual machine, it is recommended globally unique
LuaEnv luaEnv new new LuaEnv = ();
luaEnv.DoString ( "Print ( 'the Test')");
external Lua call C # code files
in XLua \ Resources folder, create a lua file, the file extension is txt; XLua in complete Lua file name format: fileName.lua.txt
The method then DoString Lua virtual machine by C # code that loads and executes lua file:
luaEnv.DoString ( "the require 'extraTestLua'"); // Do not write path and suffix
C # Lua code data acquired in
luaEnv.Global.Get <int> ( "a") ; // get values of lua
luaEnv.Global.Get <string> ( "b" ); // get the string in Lua
luaEnv.Global.Get <bool> ( "c" ); // get lua Boolean
luaEnv.Global.Get <LuaFunction> ( "d" ); // get method of lua
Lua calls C #
CS.UnityEngine.GameObject
CS.UnityEngine.Debug.Log ()
CS.UnityEngine.GameObject.Find ()
// Lua calls C #, needed before the namespace prefix to C #: CS.
LuaEnv = LuaEnv new new LuaEnv (); // Lua virtual machine running // luaEnv.DoString ( "Print ( 'hellow')"); luaEnv.DoString ( " The require 'extraTestLua' " ); // C # call external code file Lua , no write path and suffix int a = luaEnv.Global.Get < int > ( " a " ); // get values of lua String B = luaEnv.Global.Get < String > ( " B " ); // obtaining a string in Lua BOOL C = luaEnv.Global.Get < BOOL >("c"); //获取lua中的布尔 LuaFunction d = luaEnv.Global.Get<LuaFunction>("d"); //获取lua中的方法 d.Call(); string luaScript = @" local GameObject = CS.UnityEngine.GameObject local Debug = CS.UnityEngine.Debug local player = GameObject('xxxxx') Debug.Log(player.name) local camera = GameObject.Find('Main Camera') Debug.Log(camera.name) "; luaEnv.DoString(luaScript);