🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

unity-webgl

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unity-webgl - npm Package Compare versions

Comparing version

to
3.4.2

/*!
* unity-webgl.js v3.4.1
* unity-webgl.js v3.4.2
* (c) 2023 Mervin<mengqing723@gmail.com>

@@ -317,8 +317,8 @@ * Released under the MIT License.

return this.unityInstance.Quit().then(() => {
this.emit('unmounted');
this.emit('destroyed'); // todo 待删除
this.unityInstance = null;
// Clear all events
this.clear();
// this.clear()
delete window[BRIDGE_NAME];
this.emit('unmounted');
this.emit('destroyed'); // todo 待删除
});

@@ -325,0 +325,0 @@ }

/*!
* unity-webgl.js v3.4.1
* unity-webgl.js v3.4.2
* (c) 2023 Mervin<mengqing723@gmail.com>
* Released under the MIT License.
*/
var UnityWebgl=function(){"use strict";const t=t=>"[object Object]"===Object.prototype.toString.call(t),e="[UnityWebgl]: ";function n(t){console.log(e,t)}function i(t){return t instanceof HTMLCanvasElement?t:"string"==typeof t?document.querySelector(t):(n.warn("CanvasElement not found."),null)}n.warn=t=>console.warn(e,t),n.error=t=>console.error(e,t);let r="__UnityLib__";const s={streamingAssetsUrl:"StreamingAssets",companyName:"Unity",productName:"Unity"};return class extends class{constructor(t={}){this._eventMap=t}on(t,n){if("function"!=typeof n)throw new TypeError(e+"The argument handler must be function");return this._eventMap[t]=n,this}off(t){return delete this._eventMap[t],this}once(t,e){const n=this;return this.on(t,(function(...i){"function"==typeof e&&(n.off(t),e.apply(n,i))}))}emit(t,...e){const n=this._eventMap[t];n&&n.apply(this,e)}clear(){for(const t in this._eventMap)delete this._eventMap[t]}}{constructor(o,a,u){if(void 0===window)throw new Error(e+"Must be running in browser.");if(u=null!=u?u:r,t(o)&&"string"==typeof a&&(u=a||u),u in window&&n.error(`[UnityWebgl]: window.${u} already exists.`),r=u,super(window[u]={}),this.canvasElement=null,this.unityLoader=null,this.unityInstance=null,t(o))this.unityConfig=Object.assign({},s,o);else{this.unityConfig=Object.assign({},s,a);const t=i(o);t&&this.create(t)}}get bridge(){return r}set bridge(t){window[t]=window[r],delete window[r],r=t}create(t){if(this.unityInstance&&this.canvasElement&&this.unityLoader)return void n.warn("Unity Instance already exists!");const r=i(t);if(!r)return void n.warn("CanvasElement not found.");this.emit("beforeMount",this),this.canvasElement=r;const s=this,o=function(t){const e=Object.assign({},t.unityConfig);return e.print=function(e){t.emit("debug",e)},e.printError=function(e){t.emit("error",e)},e}(this),a=function(t,{resolve:n,reject:i}){if(!t)return void(i&&i(new Error(`${e} loaderUrl not found.`)));if("function"==typeof window.createUnityInstance)return void(n&&n());function r(r){"ready"===r?n&&n():i&&i(new Error(`${e} ${t} loading failure.`))}let s=document.querySelector(`script[src="${t}"]`);if(null===s){s=document.createElement("script"),s.src=t,s.async=!0,s.setAttribute("data-status","loading"),document.body.appendChild(s);const e=function(t){const e="load"===t.type?"ready":"error";null==s||s.setAttribute("data-status",e)};s.addEventListener("load",e),s.addEventListener("error",e)}else r(s.getAttribute("data-status"));const o=function(t){r("load"===t.type?"ready":"error")};return s.addEventListener("load",o),s.addEventListener("error",o),function(){s&&(s.removeEventListener("load",o),s.removeEventListener("error",o),document.body.removeChild(s))}}(this.unityConfig.loaderUrl,{resolve(){try{window.createUnityInstance(r,o,(t=>s.emit("progress",t))).then((t=>{s.unityInstance=t,s.emit("created",t),s.emit("mounted",s)})).catch((t=>{s.unityInstance=null,s.emit("error",t)}))}catch(t){s.unityInstance=null,s.emit("error",t)}},reject(t){n.error(t.message)}});"function"==typeof a&&(this.unityLoader=a)}send(t,e,i){if(this.unityInstance)if(null==i)this.unityInstance.SendMessage(t,e);else{const n="object"==typeof i?JSON.stringify(i):i;this.unityInstance.SendMessage(t,e,n)}else n.warn("Unable to Send Message while Unity is not Instantiated.");return this}requestPointerLock(){var t,e;const n=this.canvasElement||(null===(e=null===(t=this.unityInstance)||void 0===t?void 0:t.Module)||void 0===e?void 0:e.canvas);n&&n.requestPointerLock()}takeScreenshot(t="image/jpeg",e){var i,r,s;const o=this.canvasElement||(null===(r=null===(i=this.unityInstance)||void 0===i?void 0:i.Module)||void 0===r?void 0:r.canvas);if(o)return!0!==(null===(s=this.unityConfig.webglContextAttributes)||void 0===s?void 0:s.preserveDrawingBuffer)&&n.warn('Taking a screenshot requires "preserveDrawingBuffer".'),o.toDataURL(t,e);n.warn("Unable to Take Screenshot while Unity is not Instantiated or Canvas is not available.")}setFullscreen(t){this.unityInstance?this.unityInstance.SetFullscreen(t?1:0):n.warn("Unable to Set Fullscreen while Unity is not Instantiated.")}unload(){return null===this.unityInstance?(n.warn("Unable to Quit Unity while Unity is not Instantiated."),Promise.reject()):(this.emit("beforeUnmount",this),this.unityLoader&&(this.unityLoader(),this.unityLoader=null),this.unityInstance.Quit().then((()=>{this.unityInstance=null,this.clear(),delete window[r],this.emit("unmounted"),this.emit("destroyed")})))}_unsafe_unload(){try{if(null===this.unityInstance||!this.unityInstance.Module.canvas)return n.warn("No Unity Instance found."),Promise.reject();const t=this.unityInstance.Module.canvas;return document.body.appendChild(t),t.style.display="none",this.unload().then((()=>{t.remove()}))}catch(t){return n.error(t.message),Promise.reject(t)}}}}();
var UnityWebgl=function(){"use strict";const t=t=>"[object Object]"===Object.prototype.toString.call(t),e="[UnityWebgl]: ";function n(t){console.log(e,t)}function i(t){return t instanceof HTMLCanvasElement?t:"string"==typeof t?document.querySelector(t):(n.warn("CanvasElement not found."),null)}n.warn=t=>console.warn(e,t),n.error=t=>console.error(e,t);let r="__UnityLib__";const s={streamingAssetsUrl:"StreamingAssets",companyName:"Unity",productName:"Unity"};return class extends class{constructor(t={}){this._eventMap=t}on(t,n){if("function"!=typeof n)throw new TypeError(e+"The argument handler must be function");return this._eventMap[t]=n,this}off(t){return delete this._eventMap[t],this}once(t,e){const n=this;return this.on(t,(function(...i){"function"==typeof e&&(n.off(t),e.apply(n,i))}))}emit(t,...e){const n=this._eventMap[t];n&&n.apply(this,e)}clear(){for(const t in this._eventMap)delete this._eventMap[t]}}{constructor(o,a,u){if(void 0===window)throw new Error(e+"Must be running in browser.");if(u=null!=u?u:r,t(o)&&"string"==typeof a&&(u=a||u),u in window&&n.error(`[UnityWebgl]: window.${u} already exists.`),r=u,super(window[u]={}),this.canvasElement=null,this.unityLoader=null,this.unityInstance=null,t(o))this.unityConfig=Object.assign({},s,o);else{this.unityConfig=Object.assign({},s,a);const t=i(o);t&&this.create(t)}}get bridge(){return r}set bridge(t){window[t]=window[r],delete window[r],r=t}create(t){if(this.unityInstance&&this.canvasElement&&this.unityLoader)return void n.warn("Unity Instance already exists!");const r=i(t);if(!r)return void n.warn("CanvasElement not found.");this.emit("beforeMount",this),this.canvasElement=r;const s=this,o=function(t){const e=Object.assign({},t.unityConfig);return e.print=function(e){t.emit("debug",e)},e.printError=function(e){t.emit("error",e)},e}(this),a=function(t,{resolve:n,reject:i}){if(!t)return void(i&&i(new Error(`${e} loaderUrl not found.`)));if("function"==typeof window.createUnityInstance)return void(n&&n());function r(r){"ready"===r?n&&n():i&&i(new Error(`${e} ${t} loading failure.`))}let s=document.querySelector(`script[src="${t}"]`);if(null===s){s=document.createElement("script"),s.src=t,s.async=!0,s.setAttribute("data-status","loading"),document.body.appendChild(s);const e=function(t){const e="load"===t.type?"ready":"error";null==s||s.setAttribute("data-status",e)};s.addEventListener("load",e),s.addEventListener("error",e)}else r(s.getAttribute("data-status"));const o=function(t){r("load"===t.type?"ready":"error")};return s.addEventListener("load",o),s.addEventListener("error",o),function(){s&&(s.removeEventListener("load",o),s.removeEventListener("error",o),document.body.removeChild(s))}}(this.unityConfig.loaderUrl,{resolve(){try{window.createUnityInstance(r,o,(t=>s.emit("progress",t))).then((t=>{s.unityInstance=t,s.emit("created",t),s.emit("mounted",s)})).catch((t=>{s.unityInstance=null,s.emit("error",t)}))}catch(t){s.unityInstance=null,s.emit("error",t)}},reject(t){n.error(t.message)}});"function"==typeof a&&(this.unityLoader=a)}send(t,e,i){if(this.unityInstance)if(null==i)this.unityInstance.SendMessage(t,e);else{const n="object"==typeof i?JSON.stringify(i):i;this.unityInstance.SendMessage(t,e,n)}else n.warn("Unable to Send Message while Unity is not Instantiated.");return this}requestPointerLock(){var t,e;const n=this.canvasElement||(null===(e=null===(t=this.unityInstance)||void 0===t?void 0:t.Module)||void 0===e?void 0:e.canvas);n&&n.requestPointerLock()}takeScreenshot(t="image/jpeg",e){var i,r,s;const o=this.canvasElement||(null===(r=null===(i=this.unityInstance)||void 0===i?void 0:i.Module)||void 0===r?void 0:r.canvas);if(o)return!0!==(null===(s=this.unityConfig.webglContextAttributes)||void 0===s?void 0:s.preserveDrawingBuffer)&&n.warn('Taking a screenshot requires "preserveDrawingBuffer".'),o.toDataURL(t,e);n.warn("Unable to Take Screenshot while Unity is not Instantiated or Canvas is not available.")}setFullscreen(t){this.unityInstance?this.unityInstance.SetFullscreen(t?1:0):n.warn("Unable to Set Fullscreen while Unity is not Instantiated.")}unload(){return null===this.unityInstance?(n.warn("Unable to Quit Unity while Unity is not Instantiated."),Promise.reject()):(this.emit("beforeUnmount",this),this.unityLoader&&(this.unityLoader(),this.unityLoader=null),this.unityInstance.Quit().then((()=>{this.emit("unmounted"),this.emit("destroyed"),this.unityInstance=null,delete window[r]})))}_unsafe_unload(){try{if(null===this.unityInstance||!this.unityInstance.Module.canvas)return n.warn("No Unity Instance found."),Promise.reject();const t=this.unityInstance.Module.canvas;return document.body.appendChild(t),t.style.display="none",this.unload().then((()=>{t.remove()}))}catch(t){return n.error(t.message),Promise.reject(t)}}}}();
//# sourceMappingURL=index.global.js.map
/*!
* unity-webgl.js v3.4.1
* unity-webgl.js v3.4.2
* (c) 2023 Mervin<mengqing723@gmail.com>

@@ -319,8 +319,8 @@ * Released under the MIT License.

return this.unityInstance.Quit().then(() => {
this.emit('unmounted');
this.emit('destroyed'); // todo 待删除
this.unityInstance = null;
// Clear all events
this.clear();
// this.clear()
delete window[BRIDGE_NAME];
this.emit('unmounted');
this.emit('destroyed'); // todo 待删除
});

@@ -327,0 +327,0 @@ }

{
"name": "unity-webgl",
"version": "3.4.1",
"version": "3.4.2",
"description": "Unity-Webgl provides an easy solution for embedding Unity WebGL builds in your webApp or Vue.js project, with two-way communication between your webApp and Unity application with advanced API's.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet