|
Unity WebGL 调用js文件内方法 传递参数
test.jslib文件,放到Assets/Plugins下,这里是:Assets/Plugins/WebGL
JS文件
——————————————————————————————————————
var MyPlugin = {
//调用这个方法
StringReturnValueFunction: function ()
{
var returnStr = window.location.search;
var buffer = _malloc(lengthBytesUTF8(returnStr) + 1);
writeStringToMemory(returnStr, buffer);
return buffer;
},
UnitySeddata:function(Jsonstr)
{
//方法名(参数)
seddata(Jsonstr)
}
};
mergeInto(LibraryManager.library, MyPlugin);
——————————————————————————————————————
场景测试文件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
//上传成绩
[System.Runtime.InteropServices.DllImport("__Internal")]
public static extern string StringReturnValueFunction();
[System.Runtime.InteropServices.DllImport("__Internal")]
public static extern string UnitySeddata(List<string> jsonstr);
void Start()
{
GreadData g1 = new GreadData(1, "选择题", 100, 101, 1, 2, 100, 100, 1, "You", "wu", "wu");
GreadData g2 = new GreadData(2, "选择题", 100, 101, 1, 2, 100, 100, 1, "You", "wu", "wu");
string a = g1.Convert(g1);
string b = g2.Convert(g2);
UnitySeddata(g1);
UnitySeddata(g2);
}
}
—————————————————————————————————————— |
|