1 line
43 KiB
JavaScript
Raw Permalink Normal View History

2025-06-16 21:48:59 +08:00
function createUnityInstance(t,n,l){function c(e,t){if(!c.aborted&&n.showBanner)return"error"==t&&(c.aborted=!0),n.showBanner(e,t);switch(t){case"error":console.error(e);break;case"warning":console.warn(e);break;default:console.log(e)}}function r(e){var t=e.reason||e.error,n=t?t.toString():e.message||e.reason||"",r=t&&t.stack?t.stack.toString():"";(n+="\n"+(r=r.startsWith(n)?r.substring(n.length):r).trim())&&u.stackTraceRegExp&&u.stackTraceRegExp.test(n)&&x(n,e.filename||t&&(t.fileName||t.sourceURL)||"",e.lineno||t&&(t.lineNumber||t.line)||0)}function e(e,t,n){var r=e[t];void 0!==r&&r||(console.warn('Config option "'+t+'" is missing or empty. Falling back to default value: "'+n+'". Consider updating your WebGL template to include the missing config option.'),e[t]=n)}l=l||function(){};var o,u={canvas:t,webglContextAttributes:{preserveDrawingBuffer:!1,powerPreference:2},cacheControl:function(e){return e==u.dataUrl||e.match(/\.bundle/)?"must-revalidate":"no-store"},streamingAssetsUrl:"StreamingAssets",downloadProgress:{},deinitializers:[],intervals:{},setInterval:function(e,t){e=window.setInterval(e,t);return this.intervals[e]=!0,e},clearInterval:function(e){delete this.intervals[e],window.clearInterval(e)},preRun:[],postRun:[],print:function(e){console.log(e)},printErr:function(e){console.error(e),"string"==typeof e&&-1!=e.indexOf("wasm streaming compile failed")&&(-1!=e.toLowerCase().indexOf("mime")?c('HTTP Response Header "Content-Type" configured incorrectly on the server for file '+u.codeUrl+' , should be "application/wasm". Startup time performance will suffer.',"warning"):c('WebAssembly streaming compilation failed! This can happen for example if "Content-Encoding" HTTP header is incorrectly enabled on the server for file '+u.codeUrl+", but the file is not pre-compressed on disk (or vice versa). Check the Network tab in browser Devtools to debug server header configuration.","warning"))},locateFile:function(e){return e},disabledCanvasEvents:["contextmenu","dragstart"]};for(o in e(n,"companyName","Unity"),e(n,"productName","WebGL Player"),e(n,"productVersion","1.0"),n)u[o]=n[o];u.streamingAssetsUrl=new URL(u.streamingAssetsUrl,document.URL).href;var a=u.disabledCanvasEvents.slice();function i(e){e.preventDefault()}a.forEach(function(e){t.addEventListener(e,i)}),window.addEventListener("error",r),window.addEventListener("unhandledrejection",r);var s="",d="";function f(e){document.webkitCurrentFullScreenElement===t?t.style.width&&(s=t.style.width,d=t.style.height,t.style.width="100%",t.style.height="100%"):s&&(t.style.width=s,t.style.height=d,d=s="")}document.addEventListener("webkitfullscreenchange",f),u.deinitializers.push(function(){for(var e in u.disableAccessToMediaDevices(),a.forEach(function(e){t.removeEventListener(e,i)}),window.removeEventListener("error",r),window.removeEventListener("unhandledrejection",r),document.removeEventListener("webkitfullscreenchange",f),u.intervals)window.clearInterval(e);u.intervals={}}),u.QuitCleanup=function(){for(var e=0;e<u.deinitializers.length;e++)u.deinitializers[e]();u.deinitializers=[],"function"==typeof u.onQuit&&u.onQuit()};var h,m,b,g,p,w,v,y,k,_={Module:u,SetFullscreen:function(){if(u.SetFullscreen)return u.SetFullscreen.apply(u,arguments);u.print("Failed to set Fullscreen mode: Player not loaded yet.")},SendMessage:function(){if(u.SendMessage)return u.SendMessage.apply(u,arguments);u.print("Failed to execute SendMessage: Player not loaded yet.")},Quit:function(){return new Promise(function(e,t){u.shouldQuit=!0,u.onQuit=e})},GetMemoryInfo:function(){var e=u._getMemInfo();return{totalWASMHeapSize:u.HEAPU32[e>>2],usedWASMHeapSize:u.HEAPU32[1+(e>>2)],totalJSHeapSize:u.HEAPF64[1+(e>>3)],usedJSHeapSize:u.HEAPF64[2+(e>>3)]}}};function x(e,t,n){-1==e.indexOf("fullscreen error")&&(u.startupErrorHandler?u.startupErrorHandler(e,t,n):u.errorHandler&&u.errorHandler(e,t,n)||(console.log("Invoking error handler due to\n"+e),"function"==typeof dump&&dump("Invoking error handler due to\n"+e),x.didShowErrorMessage||(-1!=(e="An error occurred running the Unity content on this page. See