5

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

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

    public AppletMessage(string _name, string[] _args) {
        Name = _name;
        Args = _args;
    }
}

进入lua中的一个函数,我不知道该怎么做。我目前正在做的是这样的:

//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});

当它尝试调用函数并传入 AppletMessage 时,这给了我来自 applet 类的错误:

cannot access field  of userdata<AppletMessage>
4

1 回答 1

0

你是Moonsharp.Interpreter.UserData.RegisterAssembly();在游戏开始时添加的吗?您需要它来检测标签并使[MoonSharpUserData]标签正常工作。

于 2018-08-05T04:54:40.943 回答