当前位置: 代码迷 >> 综合 >> Unity WebGL 调用js文件方法传递参数
  详细解决方案

Unity WebGL 调用js文件方法传递参数

热度:70   发布时间:2023-11-25 06:51:41.0

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);}}
  相关解决方案