将字符串发送到 UnityWebGL jslib

Send string to UnityWebGL jslib

我尝试使用 jslib 来显示警报消息,但警报 windows 对我显示奇怪的数字。

喜欢 48616488 58926312 20535112 21654936 25634800

但是我发送相同的字符串,我得到这个数字是什么?

这是代码:

jslib

  IAUDIO: function (str) {
            alert(str);
  }

c#

    [DllImport("__Internal")]
    public static extern void IAUDIO(string s);

    void SendData(){
    IAUDIO("Test");
    }

就像你的 question. You can't use string sent from C# directly. The string is passed as a pointer and you need a way to access it from the memory. The Pointer_stringify函数就是用来做这个的。

IAUDIO: function (str) 
{
    alert(Pointer_stringify(str));
},

您的 C# 代码看起来不错。