//代码段一
mergeInto(LibraryManager.library, {
SetCookie: function(name, value, exdays,url) {
var urr = UTF8ToString(url);
var cname = UTF8ToString(name);
var cvalue = UTF8ToString(value);
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toGMTString();
var ull="domain="+urr;
var msg = cname + "=" + cvalue + "; " + expires+";"+ull+";path=/";
document.cookie = msg;
},
GetCookie: function(zname) {
var cname = UTF8ToString(zname);
var returnArg;
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name) == 0) {
returnArg = c.substring(name.length, c.length);
var bufferSize = lengthBytesUTF8(returnArg) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnArg, buffer, bufferSize);
return buffer;
}
}
return "";
},
ClearCookies: function() {
let cookies = document.cookie.split(";");
cookies.forEach(cookie => {
let cookieName = cookie.split("=")[0];
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";
});
},
CloseWindow: function() {
if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") != -1) {
window.location.href = "about:blank";
window.close();
} else {
window.opener = null;
window.open("", "_self");
window.close();
}
},
LoadImageFile: function() {
var fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = ".jpg,.png";
fileInput.style.position = 'fixed';
fileInput.style.left = '-100vw';
fileInput.onchange = function(e) {
var url = URL.createObjectURL(fileInput.files[0]);
window.unityInstance.Module.SendMessage('PlayerCenter', 'SetPath', url);
};
document.body.appendChild(fileInput);
fileInput.click();
setTimeout(function() {
document.body.removeChild(fileInput);
},
100);
},
GetUrlToken:function(){
var queryString = window.location.search;
var urlParams = new URLSearchParams(queryString);
var token = urlParams.get('token');
if (token){
var bufferSize = lengthBytesUTF8(token) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(token, buffer, bufferSize);
return buffer;
}
else
return "";
}
});
//代码段二
mergeInto(LibraryManager.library, {
WebGL_OpenURL: function (urlPtr) {
var url = UTF8ToString(urlPtr);
window.location.href = url;
},
WebGL_ClosePage: function () {
try {
window.open('', '_self').close();
} catch (e) {
console.log("Window close blocked:", e);
}
},
WebGL_RedirectBlank: function () {
window.location.href = "about:blank";
},
// 用户点击按钮触发全屏
WebGL_RequestFullscreen: function () {
let canvas = document.getElementById("unity-canvas");
if (canvas.requestFullscreen) {
canvas.requestFullscreen();
} else if (canvas.webkitRequestFullscreen) {
canvas.webkitRequestFullscreen();
} else if (canvas.msRequestFullscreen) {
canvas.msRequestFullscreen();
} else {
console.log("Fullscreen API not supported");
}
}
});
代码段一LoadImageFile需要在index页面有unityInstance的地方添加 window.unityInstance=unityInstance才能正常使用
434

被折叠的 条评论
为什么被折叠?



