🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

unity-webgl

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unity-webgl - npm Package Compare versions

Comparing version

to
1.2.2

61

dist/UnityWebgl.esm.js

@@ -34,4 +34,4 @@ import _typeof from '@babel/runtime/helpers/typeof';

* Registers an event to the system.
* @param {*} eventName event's name
* @param {*} eventListener event's function
* @param {string} eventName event's name
* @param {function} eventListener event's function
* @returns

@@ -53,4 +53,4 @@ */

* Registers an event and it only run one time
* @param {*} eventName event's name
* @param {*} eventListener event's function
* @param {string} eventName event's name
* @param {function} eventListener event's function
* @returns

@@ -75,3 +75,3 @@ */

* Removes all the Event Listeners with a specific Event Name.
* @param {*} eventName event's name
* @param {string} eventName event's name
* @returns

@@ -110,3 +110,3 @@ */

* Dispatches an event that has been registered to the event system.
* @param {*} eventName event's name
* @param {string} eventName event's name
* @param {...any} args event's parameters

@@ -117,4 +117,4 @@ * @returns

}, {
key: "dispatch",
value: function dispatch(eventName) {
key: "emit",
value: function emit(eventName) {
var event = this.eventMap.get(eventName);

@@ -213,3 +213,3 @@

/**
*
* generate UnityInstance parameters
* @param {object} unityContext

@@ -225,7 +225,7 @@ * @param {object} unityProps

unityParameters.print = function (message) {
unity.dispatch('debug', message);
unity.emit('debug', message);
};
unityParameters.printErr = function (message) {
unity.dispatch('error', message);
unity.emit('error', message);
};

@@ -332,10 +332,10 @@

}).then(function (unity) {
ctx.dispatch('created');
ctx.emit('created');
ctx.unityInstance = unity;
}).catch(function (err) {
ctx.dispatch('error', err);
ctx.emit('error', err);
ctx.unityInstance = null;
});
} catch (err) {
ctx.dispatch('error', err);
ctx.emit('error', err);
ctx.unityInstance = null;

@@ -351,3 +351,3 @@ }

* set Progression
* @param {*} val progress
* @param {number} val progress
*/

@@ -359,12 +359,12 @@

if (val === 1) {
this.dispatch('loaded');
this.emit('loaded');
}
this.dispatch('progress', val);
this.emit('progress', val);
}
/**
* Sends a message to the UnityInstance to invoke a public method.
* @param {*} objectName Unity scene name.
* @param {*} methodName public method name.
* @param {*} params an optional method parameter.
* @param {string} objectName Unity scene name.
* @param {string} methodName public method name.
* @param {any} params an optional method parameter.
* @returns

@@ -451,3 +451,3 @@ */

_this2.dispatch('quitted');
_this2.emit('destroyed');
});

@@ -476,2 +476,13 @@ }

var unityInstanceIdentifier = 0;
function cssUnit(val) {
var regx = /^\d+(px|em|%|vw|vh|rem)?$/;
if (regx.test(val)) {
return isNaN(val) ? val : val + 'px';
}
return '';
}
var script = {

@@ -495,4 +506,4 @@ name: 'UnityWebgl',

return {
width: width + (typeof width === 'number' ? 'px' : ''),
height: height + (typeof height === 'number' ? 'px' : '')
width: cssUnit(width),
height: cssUnit(height)
};

@@ -506,7 +517,7 @@ }

if (htmlCanvasElement) {
unity.create(htmlCanvasElement);
unity === null || unity === void 0 ? void 0 : unity.create(htmlCanvasElement);
}
this.$once('hook:beforeDestroy', function () {
unity && unity.destroy();
unity === null || unity === void 0 ? void 0 : unity.destroy();
});

@@ -513,0 +524,0 @@ },

@@ -1,1 +0,1 @@

var UnityWebgl=function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function u(t,e){return u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},u(t,e)}function c(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return o(t)}function a(t){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}function s(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var l="__UnityLib__",f=function(){function t(){n(this,t),s(this,"eventMap",new Map),void 0!==window&&void 0===window.__UnityLib__&&(window.__UnityLib__={})}return i(t,[{key:"global_name",get:function(){return l}},{key:"on",value:function(t,e){return this.eventMap.set(t,e),void 0!==window.__UnityLib__&&(window.__UnityLib__[t]=e),this}},{key:"once",value:function(t,e){return this.on(t,function n(){e&&e.apply(this,arguments),this.off(t,n)}.bind(this)),this}},{key:"off",value:function(t){return this.eventMap.delete(t),void 0!==window.__UnityLib__&&delete window.__UnityLib__[t],this}},{key:"clear",value:function(){return void 0!==window.__UnityLib__&&this.eventMap.forEach((function(t,e){delete window.__UnityLib__[e]})),this.eventMap.clear(),this}},{key:"dispatch",value:function(t){var e=this.eventMap.get(t);if(void 0!==e){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];e.apply(void 0,r)}return this}}]),t}();function d(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=a(t);if(e){var i=a(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return c(this,n)}}function y(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function h(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?y(Object(n),!0).forEach((function(e){s(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}f.global_name=l;var p=function(t){return"[object Object]"===Object.prototype.toString.call(t)};function v(t){return t instanceof HTMLCanvasElement?t:"string"==typeof t?document.querySelector(t):null}var b=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}(c,t);var r=d(c);function c(t){var e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n(this,c),s(o(e=r.call(this)),"unityLoader",null),s(o(e),"canvasElement",null),s(o(e),"unityInstance",null),p(t))e.config=h({},t);else{e.config=h({},i);var u=v(t);u&&e.create(u)}return e}return i(c,[{key:"create",value:function(t){if(this.unityInstance&&this.canvasElement&&this.unityLoader)return console.warn("UnityWebgl: Unity Instance already exists"),!1;var e=v(t);if(!e)return console.warn("UnityWebgl: CanvasElement not found."),!1;this.canvasElement=e;var n,r,i=this,o=((r=h({},(n=this).config)).print=function(t){n.dispatch("debug",t)},r.printErr=function(t){n.dispatch("error",t)},r);this.unityLoader=function(t,e){var n=e.resolve,r=e.reject;if(!t)return r&&r(new Error("UnityLoader: src not found.")),null;function i(e){"ready"===e?n&&n():r&&r(new Error("'UnityLoader: ".concat(t,"' load failed.")))}var o=document.querySelector('script[src="'.concat(t,'"]'));if(null===o){(o=document.createElement("script")).src=t,o.async=!0,o.setAttribute("data-status","loading"),document.body.appendChild(o);var u=function(t){var e,n="load"===t.type?"ready":"error";null===(e=o)||void 0===e||e.setAttribute("data-status",n)};o.addEventListener("load",u),o.addEventListener("error",u)}else i(o.getAttribute("data-status"));var c=function(t){i("load"===t.type?"ready":"error")};return o.addEventListener("load",c),o.addEventListener("error",c),function(){o&&(o.removeEventListener("load",c),o.removeEventListener("error",c),document.body.removeChild(o))}}(o.loaderUrl,{resolve:function(){try{window.createUnityInstance(e,o,(function(t){return i._setProgression(t)})).then((function(t){i.dispatch("created"),i.unityInstance=t})).catch((function(t){i.dispatch("error",t),i.unityInstance=null}))}catch(t){i.dispatch("error",t),i.unityInstance=null}},reject:function(t){console.error("UnityWebgl: ",null==t?void 0:t.message)}})}},{key:"_setProgression",value:function(t){1===t&&this.dispatch("loaded"),this.dispatch("progress",t)}},{key:"send",value:function(t,n,r){if(null!==this.unityInstance)if(null==r)this.unityInstance.SendMessage(t,n);else{var i="object"===e(r)?JSON.stringify(r):r;this.unityInstance.SendMessage(t,n,i)}return this}},{key:"requestPointerLock",value:function(){null!==this.canvasElement&&this.canvasElement.requestPointerLock()}},{key:"takeScreenshot",value:function(t,e){var n;return null!==this.canvasElement?(!0!==(null===(n=this.config.webglContextAttributes)||void 0===n?void 0:n.preserveDrawingBuffer)&&console.warn("Taking a screenshot requires 'preserveDrawingBuffer'."),this.canvasElement.toDataURL(t,e)):null}},{key:"setFullscreen",value:function(t){null!==this.unityInstance&&this.unityInstance.SetFullscreen(t?1:0)}},{key:"quitUnityInstance",value:function(){var t=this;null!==this.unityInstance&&this.unityInstance.Quit().then((function(){t.unityInstance=null,t.dispatch("quitted")}))}},{key:"destroy",value:function(){this.unityLoader&&(this.unityLoader(),this.unityLoader=null),this.quitUnityInstance()}}]),c}(f),_=0;function w(t,e,n,r,i,o,u,c,a,s){"boolean"!=typeof u&&(a=c,c=u,u=!1);const l="function"==typeof n?n.options:n;let f;if(t&&t.render&&(l.render=t.render,l.staticRenderFns=t.staticRenderFns,l._compiled=!0,i&&(l.functional=!0)),r&&(l._scopeId=r),o?(f=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,a(t)),t&&t._registeredComponents&&t._registeredComponents.add(o)},l._ssrRegister=f):e&&(f=u?function(t){e.call(this,s(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,c(t))}),f)if(l.functional){const t=l.render;l.render=function(e,n){return f.call(n),t(e,n)}}else{const t=l.beforeCreate;l.beforeCreate=t?[].concat(t,f):[f]}return n}var g=w({},undefined,{name:"UnityWebgl",props:{unity:Object,width:{type:[String,Number],default:"100%"},height:{type:[String,Number],default:"100%"}},computed:{canvasStyle:function(){var t=this.width,e=this.height;return{width:t+("number"==typeof t?"px":""),height:e+("number"==typeof e?"px":"")}}},mounted:function(){var t=this.$refs.canvas,e=this.unity;t&&e.create(t),this.$once("hook:beforeDestroy",(function(){e&&e.destroy()}))},render:function(t){return _++,t("canvas",{ref:"canvas",attrs:{id:"unity-canvas-".concat(_)},style:this.canvasStyle})}},undefined,undefined,undefined,!1,void 0,void 0,void 0),m=function t(e){t.installed||(t.installed=!0,e.component("Unity",g))};return"undefined"!=typeof window&&window.Vue&&Vue.use(m),b.install=m,t.VueUnity=g,t.default=b,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
var UnityWebgl=function(e){"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){return u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},u(e,t)}function c(e,n){if(n&&("object"===t(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return o(e)}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l="__UnityLib__",f=function(){function e(){n(this,e),s(this,"eventMap",new Map),void 0!==window&&void 0===window.__UnityLib__&&(window.__UnityLib__={})}return i(e,[{key:"global_name",get:function(){return l}},{key:"on",value:function(e,t){return this.eventMap.set(e,t),void 0!==window.__UnityLib__&&(window.__UnityLib__[e]=t),this}},{key:"once",value:function(e,t){return this.on(e,function n(){t&&t.apply(this,arguments),this.off(e,n)}.bind(this)),this}},{key:"off",value:function(e){return this.eventMap.delete(e),void 0!==window.__UnityLib__&&delete window.__UnityLib__[e],this}},{key:"clear",value:function(){return void 0!==window.__UnityLib__&&this.eventMap.forEach((function(e,t){delete window.__UnityLib__[t]})),this.eventMap.clear(),this}},{key:"emit",value:function(e){var t=this.eventMap.get(e);if(void 0!==t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];t.apply(void 0,r)}return this}}]),e}();function d(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=a(e);if(t){var i=a(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return c(this,n)}}function y(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?y(Object(n),!0).forEach((function(t){s(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}f.global_name=l;var h=function(e){return"[object Object]"===Object.prototype.toString.call(e)};function p(e){return e instanceof HTMLCanvasElement?e:"string"==typeof e?document.querySelector(e):null}var b=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}(c,e);var r=d(c);function c(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n(this,c),s(o(t=r.call(this)),"unityLoader",null),s(o(t),"canvasElement",null),s(o(t),"unityInstance",null),h(e))t.config=v({},e);else{t.config=v({},i);var u=p(e);u&&t.create(u)}return t}return i(c,[{key:"create",value:function(e){if(this.unityInstance&&this.canvasElement&&this.unityLoader)return console.warn("UnityWebgl: Unity Instance already exists"),!1;var t=p(e);if(!t)return console.warn("UnityWebgl: CanvasElement not found."),!1;this.canvasElement=t;var n,r,i=this,o=((r=v({},(n=this).config)).print=function(e){n.emit("debug",e)},r.printErr=function(e){n.emit("error",e)},r);this.unityLoader=function(e,t){var n=t.resolve,r=t.reject;if(!e)return r&&r(new Error("UnityLoader: src not found.")),null;function i(t){"ready"===t?n&&n():r&&r(new Error("'UnityLoader: ".concat(e,"' load failed.")))}var o=document.querySelector('script[src="'.concat(e,'"]'));if(null===o){(o=document.createElement("script")).src=e,o.async=!0,o.setAttribute("data-status","loading"),document.body.appendChild(o);var u=function(e){var t,n="load"===e.type?"ready":"error";null===(t=o)||void 0===t||t.setAttribute("data-status",n)};o.addEventListener("load",u),o.addEventListener("error",u)}else i(o.getAttribute("data-status"));var c=function(e){i("load"===e.type?"ready":"error")};return o.addEventListener("load",c),o.addEventListener("error",c),function(){o&&(o.removeEventListener("load",c),o.removeEventListener("error",c),document.body.removeChild(o))}}(o.loaderUrl,{resolve:function(){try{window.createUnityInstance(t,o,(function(e){return i._setProgression(e)})).then((function(e){i.emit("created"),i.unityInstance=e})).catch((function(e){i.emit("error",e),i.unityInstance=null}))}catch(e){i.emit("error",e),i.unityInstance=null}},reject:function(e){console.error("UnityWebgl: ",null==e?void 0:e.message)}})}},{key:"_setProgression",value:function(e){1===e&&this.emit("loaded"),this.emit("progress",e)}},{key:"send",value:function(e,n,r){if(null!==this.unityInstance)if(null==r)this.unityInstance.SendMessage(e,n);else{var i="object"===t(r)?JSON.stringify(r):r;this.unityInstance.SendMessage(e,n,i)}return this}},{key:"requestPointerLock",value:function(){null!==this.canvasElement&&this.canvasElement.requestPointerLock()}},{key:"takeScreenshot",value:function(e,t){var n;return null!==this.canvasElement?(!0!==(null===(n=this.config.webglContextAttributes)||void 0===n?void 0:n.preserveDrawingBuffer)&&console.warn("Taking a screenshot requires 'preserveDrawingBuffer'."),this.canvasElement.toDataURL(e,t)):null}},{key:"setFullscreen",value:function(e){null!==this.unityInstance&&this.unityInstance.SetFullscreen(e?1:0)}},{key:"quitUnityInstance",value:function(){var e=this;null!==this.unityInstance&&this.unityInstance.Quit().then((function(){e.unityInstance=null,e.emit("destroyed")}))}},{key:"destroy",value:function(){this.unityLoader&&(this.unityLoader(),this.unityLoader=null),this.quitUnityInstance()}}]),c}(f),_=0;function m(e){return/^\d+(px|em|%|vw|vh|rem)?$/.test(e)?isNaN(e)?e:e+"px":""}function w(e,t,n,r,i,o,u,c,a,s){"boolean"!=typeof u&&(a=c,c=u,u=!1);const l="function"==typeof n?n.options:n;let f;if(e&&e.render&&(l.render=e.render,l.staticRenderFns=e.staticRenderFns,l._compiled=!0,i&&(l.functional=!0)),r&&(l._scopeId=r),o?(f=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,a(e)),e&&e._registeredComponents&&e._registeredComponents.add(o)},l._ssrRegister=f):t&&(f=u?function(e){t.call(this,s(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,c(e))}),f)if(l.functional){const e=l.render;l.render=function(t,n){return f.call(n),e(t,n)}}else{const e=l.beforeCreate;l.beforeCreate=e?[].concat(e,f):[f]}return n}var g=w({},undefined,{name:"UnityWebgl",props:{unity:Object,width:{type:[String,Number],default:"100%"},height:{type:[String,Number],default:"100%"}},computed:{canvasStyle:function(){var e=this.width,t=this.height;return{width:m(e),height:m(t)}}},mounted:function(){var e=this.$refs.canvas,t=this.unity;e&&(null==t||t.create(e)),this.$once("hook:beforeDestroy",(function(){null==t||t.destroy()}))},render:function(e){return _++,e("canvas",{ref:"canvas",attrs:{id:"unity-canvas-".concat(_)},style:this.canvasStyle})}},undefined,undefined,undefined,!1,void 0,void 0,void 0),O=function e(t){e.installed||(e.installed=!0,t.component("Unity",g))};return"undefined"!=typeof window&&window.Vue&&Vue.use(O),b.install=O,e.VueUnity=g,e.default=b,Object.defineProperty(e,"__esModule",{value:!0}),e}({});

@@ -133,4 +133,4 @@ (function (global, factory) {

* Registers an event to the system.
* @param {*} eventName event's name
* @param {*} eventListener event's function
* @param {string} eventName event's name
* @param {function} eventListener event's function
* @returns

@@ -152,4 +152,4 @@ */

* Registers an event and it only run one time
* @param {*} eventName event's name
* @param {*} eventListener event's function
* @param {string} eventName event's name
* @param {function} eventListener event's function
* @returns

@@ -174,3 +174,3 @@ */

* Removes all the Event Listeners with a specific Event Name.
* @param {*} eventName event's name
* @param {string} eventName event's name
* @returns

@@ -209,3 +209,3 @@ */

* Dispatches an event that has been registered to the event system.
* @param {*} eventName event's name
* @param {string} eventName event's name
* @param {...any} args event's parameters

@@ -216,4 +216,4 @@ * @returns

}, {
key: "dispatch",
value: function dispatch(eventName) {
key: "emit",
value: function emit(eventName) {
var event = this.eventMap.get(eventName);

@@ -312,3 +312,3 @@

/**
*
* generate UnityInstance parameters
* @param {object} unityContext

@@ -324,7 +324,7 @@ * @param {object} unityProps

unityParameters.print = function (message) {
unity.dispatch('debug', message);
unity.emit('debug', message);
};
unityParameters.printErr = function (message) {
unity.dispatch('error', message);
unity.emit('error', message);
};

@@ -431,10 +431,10 @@

}).then(function (unity) {
ctx.dispatch('created');
ctx.emit('created');
ctx.unityInstance = unity;
}).catch(function (err) {
ctx.dispatch('error', err);
ctx.emit('error', err);
ctx.unityInstance = null;
});
} catch (err) {
ctx.dispatch('error', err);
ctx.emit('error', err);
ctx.unityInstance = null;

@@ -450,3 +450,3 @@ }

* set Progression
* @param {*} val progress
* @param {number} val progress
*/

@@ -458,12 +458,12 @@

if (val === 1) {
this.dispatch('loaded');
this.emit('loaded');
}
this.dispatch('progress', val);
this.emit('progress', val);
}
/**
* Sends a message to the UnityInstance to invoke a public method.
* @param {*} objectName Unity scene name.
* @param {*} methodName public method name.
* @param {*} params an optional method parameter.
* @param {string} objectName Unity scene name.
* @param {string} methodName public method name.
* @param {any} params an optional method parameter.
* @returns

@@ -550,3 +550,3 @@ */

_this2.dispatch('quitted');
_this2.emit('destroyed');
});

@@ -575,2 +575,13 @@ }

var unityInstanceIdentifier = 0;
function cssUnit(val) {
var regx = /^\d+(px|em|%|vw|vh|rem)?$/;
if (regx.test(val)) {
return isNaN(val) ? val : val + 'px';
}
return '';
}
var script = {

@@ -594,4 +605,4 @@ name: 'UnityWebgl',

return {
width: width + (typeof width === 'number' ? 'px' : ''),
height: height + (typeof height === 'number' ? 'px' : '')
width: cssUnit(width),
height: cssUnit(height)
};

@@ -605,7 +616,7 @@ }

if (htmlCanvasElement) {
unity.create(htmlCanvasElement);
unity === null || unity === void 0 ? void 0 : unity.create(htmlCanvasElement);
}
this.$once('hook:beforeDestroy', function () {
unity && unity.destroy();
unity === null || unity === void 0 ? void 0 : unity.destroy();
});

@@ -612,0 +623,0 @@ },

@@ -11,3 +11,3 @@ {

],
"version": "1.2.1",
"version": "1.2.2",
"main": "dist/UnityWebgl.umd.js",

@@ -14,0 +14,0 @@ "module": "dist/UnityWebgl.esm.js",

@@ -137,3 +137,3 @@ # unity-webgl

* `clear()`
* `dispatch(eventName: string)`
* `emit(eventName: string)`

@@ -161,2 +161,12 @@ instance:

```js
// # in Unity
// Call the `showDialog` method in unity.
__UnityLib__.showDialog(data)
// 📢 `__UnityLib__` is a global function collection.
```
```js
// # in webApp
const Unity = new UnityWebgl.default()

@@ -170,9 +180,7 @@

// call function.
Unity.dispatch('showDialog', data)
// you also can call function.
Unity.emit('showDialog', data)
// or
window[Unity.global_name].showDialog(data) // ⚠️ Unity.global_name = __UnityLib__
window[Unity.global_name].showDialog(data) // 📢 Unity.global_name = __UnityLib__
// call function in unity application
__UnityLib__.showDialog(data)
```

@@ -183,3 +191,3 @@

2. JS call Unity public methods.
在web页面内调用 unity应用公用方法。
在web页面内调用 Unity public方法。

@@ -197,8 +205,9 @@ ```js

Unity.send('mainScene', 'init', {
id: 'b0001',
name: 'building#0001',
length: 100,
width: 75,
height: 200
id: 'b001',
name: 'building#001',
length: 95,
width: 27,
height: 120
})
```

@@ -86,3 +86,3 @@ // const UNITY_GLOBAL_NAME = 'UnityWebGL'

*/
dispatch(eventName, ...args) {
emit(eventName, ...args) {
const event = this.eventMap.get(eventName)

@@ -89,0 +89,0 @@ if (event !== undefined) {

@@ -1,2 +0,2 @@

import UnityWebgl from "./UnityWebgl"
import UnityWebgl from './UnityWebgl.js'
import VueUnity from './Unity.vue'

@@ -3,0 +3,0 @@

@@ -72,7 +72,7 @@ import EventSystem from './Events.js'

unityParameters.print = function (message) {
unity.dispatch('debug', message)
unity.emit('debug', message)
}
unityParameters.printErr = function (message) {
unity.dispatch('error', message)
unity.emit('error', message)
}

@@ -161,10 +161,10 @@

).then(unity => {
ctx.dispatch('created')
ctx.emit('created')
ctx.unityInstance = unity
}).catch(err => {
ctx.dispatch('error', err)
ctx.emit('error', err)
ctx.unityInstance = null
})
} catch (err) {
ctx.dispatch('error', err)
ctx.emit('error', err)
ctx.unityInstance = null

@@ -185,5 +185,5 @@ }

if (val === 1) {
this.dispatch('loaded')
this.emit('loaded')
}
this.dispatch('progress', val)
this.emit('progress', val)
}

@@ -257,3 +257,3 @@

this.unityInstance = null
this.dispatch('destroyed')
this.emit('destroyed')
})

@@ -260,0 +260,0 @@ }

Sorry, the diff of this file is not supported yet