如何進行調試(luaide):
1.保證addLoader中的路徑是絕對路徑,把調試文件放到main文件同級目錄。
2.在main文件中加入代碼
3.使用其中的高階用法可以在斷點時查看c#屬性的值
http://www.lxweimin.com/p/dda945be6bc2
local breakSocketHandle,debugXpCall = require("LuaDebugjit")("localhost",7003)
XLua代碼提示(luaide):
在vscode設置中搜索:apiType --> xlua
隱藏.mete文件
在settings.json文件中加入"files.exclude": 欄
添加 "*/.meta":true 項
如:
image.png
使用lua的基本思路
調用mian文件時,給mian文件加上新的類(例如:start)的元表,在新的類(例如:start)中去初始化其他業務類,并把業務類存儲到一個inittable中,在__index中設置awake,update等方法,并遍歷所有的inittable,調用其中的awake,update等方法,然后再c#中相應的函數中調用這些函數,以實現初始化,update等特定需求。
使用靜態列表和動態列表配置C#文件供lua腳本使用
using System.Collections.Generic;
using System;
using XLua;
using System.Reflection;
using System.Linq;
public static class HotfixCfg
{
[Hotfix]
public static List<Type> by_property
{
get
{
return (from type in Assembly.Load("Assembly-CSharp").GetTypes()
where type.Namespace == "XLua"
select type).ToList();
}
}
}
using System.Collections.Generic;
using System;
using XLua;
using System.Reflection;
using System.Linq;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public static class StaticCfg
{
[LuaCallCSharp]
public static List<Type> mymodule_lua_call_cs_list = new List<Type>()
{
typeof(GameObject),
typeof(Dictionary<string, int>),
typeof(GameObject),
--typeof(PrefabsMap),
};
}
以上文件放到XLua中的Editor文件夾中才會生效。