1、在Assets/Plugins/WebGL文件夹下创建MyPlugin.jslib文件
文件内容:
var MyPlugin = {
StringReturnValueFunction: function () {
var returnStr = window.top.location.href;
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
return buffer;
}
};
mergeInto(LibraryManager.library, MyPlugin);
2、创建脚本显示地址文章来源:https://www.toymoban.com/news/detail-612624.html
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.UI;
public class Test : MonoBehaviour
{
[DllImport("__Internal")]
private static extern string StringReturnValueFunction();
public Text text;
void Start()
{
string UrlMsg = "地址参数";
try
{
UrlMsg = StringReturnValueFunction();
}
catch (System.Exception e)
{
UrlMsg = "[catch]"+e.Message;
}
text.text = UrlMsg;
}
}
3、BuildAndRun或者打包后用IIS部署一个服务器运行就行了文章来源地址https://www.toymoban.com/news/detail-612624.html
到了这里,关于Unity WebGL获取地址栏参数的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!