使用moonsharp将C#对象传递到lua函数。

使用moonsharp将C#对象传递到lua函数。,c#,unity3d,lua,mono,moonsharp,C#,Unity3d,Lua,Mono,Moonsharp,我在Unity3d中使用Moonsharp时遇到问题。我正在尝试传递“AppletMessage”对象: [MoonSharpUserData] public class AppletMessage { public string Name; public string[] Args; public AppletMessage(string _name, string[] _args) { Name = _name; Args = _ar

我在Unity3d中使用Moonsharp时遇到问题。我正在尝试传递“AppletMessage”对象:

[MoonSharpUserData]
public class AppletMessage {
    public string Name;
    public string[] Args;

    public AppletMessage(string _name, string[] _args) {
        Name = _name;
        Args = _args;
    }
}
我不知道怎么做。 我目前正在做的是:

//In a start function
UserData.RegisterType<AppletMessage>();

//Later on, after popping the latest message from a stack as 'LatestMessage'
result = applet.Call( applet.Globals["OnCatchMessage"],new AppletMessage[] {LatestMessage});
//在启动函数中
UserData.RegisterType();
//稍后,从堆栈中弹出最新消息作为“LatestMessage”后
结果=applet.Call(applet.Globals[“OnCatchMessage”]、新的AppletMessage[]{LatestMessage});
当applet类试图调用函数并传入AppletMessage时,这给了我一个来自applet类的错误:

cannot access field  of userdata<AppletMessage>
无法访问用户数据的字段

您是否添加了
Moonsharp.explorer.UserData.RegisterAssembly()游戏何时开始?您需要此选项来检测并确保
[MoonSharpUserData]
标记正常工作。

如果您不确定这是答案,您应该将其作为注释(需要10分),您必须正确回答一个问题。我们都赢得了特权好吧,我试试看!但我认为我的答案是正确的,至少从我与Moonsharp的经验来看,这似乎是造成错误的最可能原因。