Pointer_stringify返回乱码文本

时间:2017-07-03 18:13:34

标签: javascript c# unity3d

我有以下lib.jslib文件

mergeInto(LibraryManager.library, {
  IsGuestUser: function (objectName, objectMethodName) {
    gamesmart.user.isGuest(function (result) {
      console.log(Pointer_stringify(objectName), Pointer_stringify(objectMethodName), result);
      gameSmartGameInstance.SendMessage(Pointer_stringify(objectName), Pointer_stringify(objectMethodName), result);
    });
  }
});

从这里开始调用:

namespace GameSmart {
  public class User : API {
    [DllImport("__Internal")]
    public static extern void IsGuestUser(string objectName, string objectMethodName);

    public static void IsGuest(string objectName, string objectMethodName) {
      IsGuestUser(objectName, objectMethodName);
    }
  }
}

并且是这样开始的:

public class Test : MonoBehaviour {
  void Start() {
    GameSmart.User.IsGuest("GameSmart", "OnIsGuest");
  }
}

如上所示,我将GameSmartOnIsGuest传递给JavaScript,当它转到JavaScript时,我会在两个值上调用Pointer_stringify()

转换并记录后,我得到以下输出:0Zހﳀ�我应该得到GameSmartOnIsGuest但是我没有导致这个发生了吗?

1 个答案:

答案 0 :(得分:0)

所以解决这个问题的方法是将Pointer_stringify移到匿名函数之外,所以它看起来像这样:

mergeInto(LibraryManager.library, {
  IsGuestUser: function (objectName, objectMethodName) {
    var jsObjectName = Pointer_stringify(objectName);
    var jsObjectMethodName = Pointer_stringify(objectMethodName);
    gamesmart.user.isGuest(function (result) {
      gameSmartGameInstance.SendMessage(jsObjectName, jsObjectMethodName, result);
    });
  }
});