|
1.声明interface,只声明lua配置表的访问函数,例如:
[CSharpCallLua]
public interface IMonsterConfig
{
int modelId(int id);
}
对应的lua配置表访问函数(Excel插件自动生成)为:
function MonsterConfig:modelId(id)
local data = MonsterConfig[id]
if data == nil then
print("MonsterConfig没有id:" .. id)
return nil
end
return data.modelId
end2.在Editor/XLuaGenConfig.cs里的CSharpCallLua加上该interface:
//C#静态调用Lua的配置(包括事件的原型),仅可以配delegate,interface
[CSharpCallLua]
[LuaCallCSharp]
public static List<Type> CSharpCallLua = new List<Type>() {
typeof(Action),
typeof(Func<double, double, double>),
typeof(Func<long, long>),
typeof(Func<long, string>),
typeof(Func<string, long>),
typeof(Action<string>),
typeof(Action<double>),
typeof(Action<bool>),
typeof(Action<float, float>),
typeof(UnityEngine.Events.UnityAction),
typeof(UnityEngine.Events.UnityAction<long>),
typeof(UnityEngine.Events.UnityAction<long,long>),
typeof(UnityEngine.Events.UnityAction<string>),
typeof(UnityEngine.Events.UnityAction<UnityEngine.Vector2>),
typeof(UnityEngine.Events.UnityEvent<UnityEngine.Vector2>),
typeof(System.Collections.IEnumerator),
typeof(LuaConfigReader.IMonsterConfig),
};
3.先后执行Unity编辑里的XLua菜单的“Clear Generated Code”和“Generate Code”,生成相关代码;
4.读取lua配置表的数据:
LuaEnv luaenv = XLuaManager.Instance.GetLuaEnv();
IMonsterConfig m = luaenv.Global.Get<IMonsterConfig>(&#34;MonsterConfig&#34;);
int modelId = m.modelId(tid); |
|