Xlua文件在熱更新中調用方法
?public class news : MonoBehaviour
{
???? LuaEnv luaEnv;//定義Lua初始變量
??? void Awake()
??? {
??????? luaEnv = new LuaEnv();//new開辟空間
??????? luaEnv.AddLoader(myload);//調用方法地址、返回字節
??????? luaEnv.DoString("require'fish'");//更新文件
??? }
void ?OnDisable ()
??? ??{
? ? ? ? ? //調用xlua.hotfix執行完數據歸空
????? ???? luaEnv.DoString (xlua.hotfix(CS.Treasour,'CreatePrize',nil);
??? ??}
??? ?void OnDestroy()
??? ?{
??? ?????luaEnv.Dispose();
??? ?}
???????? //方法myload加載、返回類型字節、參數路徑
??? private byte[] myload(ref string filepath)
{
???????? //文件地址,加載地址的切換
??????? string abspath = @"F:\5.6.1\FishingJoy\AssetBundles\" + filepath + ".lua.txt";
? ? ? ? ? //換回數據流
??????? return System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(abspath));
??? }
}
注:在C#通過LuaTable.Get獲取并保存到對象成員,賦值該成員為null,通過xlua.hotfix(class, method, func)注入到C#,則通過xlua.hotfix(class, method, nil)刪除,操作在Dispose之前完成