From fc3ab921ce0ada80864fe288b380a5036370c91d Mon Sep 17 00:00:00 2001 From: Jeffrey Lanters Date: Fri, 12 Jan 2018 17:13:39 +0100 Subject: [PATCH 1/3] Updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 01aee468..78c68a45 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# React Unity WebGL · [![license](https://img.shields.io/badge/license-MIT-red.svg)]() [![npm](https://img.shields.io/npm/v/react-unity-webgl.svg)]() [![npm](https://img.shields.io/badge/react-v12%3E-blue.svg)]() [![npm](https://img.shields.io/badge/build-passing-brightgreen.svg)]() [![npm](https://img.shields.io/npm/dt/react-unity-webgl.svg)]() [![npm](https://img.shields.io/badge/typescript-supported-2a507e.svg)]() +# React Unity WebGL · [![license](https://img.shields.io/badge/license-MIT-red.svg)]() [![npm](https://img.shields.io/npm/v/react-unity-webgl.svg)]() [![npm](https://img.shields.io/badge/build-passing-brightgreen.svg)]() [![npm](https://img.shields.io/npm/dt/react-unity-webgl.svg)]() [![npm](https://img.shields.io/badge/typescript-supported-2a507e.svg)]() When building content for the web, you might need to communicate with other elements on React Application. Or you might want to implement functionality using Web APIs which [Unity](https://unity3d.com) does not currently expose by default. In both cases, you need to directly interface with the browser’s JavaScript engine. React Unity WebGL provides an easy library for Unity 5.6 / 2017 or newer with different methods to do this. From 754c0f5956ebeceeef5ae172a6e852d3be9ff977 Mon Sep 17 00:00:00 2001 From: Jeffrey Lanters Date: Wed, 17 Jan 2018 10:29:45 +0100 Subject: [PATCH 2/3] Reformatted --- source/components/Unity.js | 46 +++++++++++----------- source/modules/RegisterExternalListener.js | 6 +-- source/modules/SendMessage.js | 12 +++--- source/modules/UnityEvent.js | 16 ++++---- source/services/UnityLoaderService.js | 18 ++++----- 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/source/components/Unity.js b/source/components/Unity.js index cc599892..b468d258 100644 --- a/source/components/Unity.js +++ b/source/components/Unity.js @@ -3,20 +3,20 @@ import UnityLoaderService from '../services/UnityLoaderService' import Styles from './Unity.styles' export default class Unity extends Component { - constructor (props) { - super (props) + constructor(props) { + super(props) this.state = { error: null } - this._unityLoaderService = new UnityLoaderService () + this._unityLoaderService = new UnityLoaderService() } - componentDidMount () { - this._instantiate () + componentDidMount() { + this._instantiate() } - componentWillUnmount () { - this._unityLoaderService.unmount () + componentWillUnmount() { + this._unityLoaderService.unmount() } - _instantiate () { + _instantiate() { let error = null if (typeof this.props.loader === 'undefined') error = 'Please provide Unity with a path to the UnityLoader in the loader prop.' @@ -24,38 +24,38 @@ export default class Unity extends Component { error = 'Please provide Unity with a path to a valid JSON in the src prop.' if (error !== null) { - console.error (error) - this.setState ({ error: error }) - } + console.error(error) + this.setState({ error: error }) + } else { - this._unityLoaderService.append (this.props.loader).then (() => { - let unityInstance = UnityLoader.instantiate ('unity', this.props.src, { - onProgress: this._onProgress.bind (this), - Module : this.props.module + this._unityLoaderService.append(this.props.loader).then(() => { + let unityInstance = UnityLoader.instantiate('unity', this.props.src, { + onProgress: this._onProgress.bind(this), + Module: this.props.module }) module.exports.UnityInstance = unityInstance }) } } - _onProgress (unityInstance, progression) { + _onProgress(unityInstance, progression) { if (typeof this.props.onProgress !== 'undefined') { - this.props.onProgress (progression) + this.props.onProgress(progression) } } - _getContainerStyles () { + _getContainerStyles() { return { width: this.props.width || '100%', height: this.props.height || '100%' } } - render () { + render() { return ( -
+
{this.state.error !== null ? ( React-Unity-Webgl error {this.state.error} - ):( -
- )} + ) : ( +
+ )}
) } diff --git a/source/modules/RegisterExternalListener.js b/source/modules/RegisterExternalListener.js index eed8a57f..909478fe 100644 --- a/source/modules/RegisterExternalListener.js +++ b/source/modules/RegisterExternalListener.js @@ -1,4 +1,4 @@ -export function RegisterExternalListener (methodName, callback) { +export function RegisterExternalListener(methodName, callback) { /** * LEGACY * bind the function to the window to allow @@ -7,7 +7,7 @@ export function RegisterExternalListener (methodName, callback) { * Application.ExternalEval. */ window[methodName] = parameter => { - callback (parameter) + callback(parameter) } /** @@ -18,6 +18,6 @@ export function RegisterExternalListener (methodName, callback) { if (typeof window.ReactUnityWebGL === 'undefined') window.ReactUnityWebGL = {} window.ReactUnityWebGL[methodName] = parameter => { - callback (parameter) + callback(parameter) } } \ No newline at end of file diff --git a/source/modules/SendMessage.js b/source/modules/SendMessage.js index 06c7c179..fb779496 100644 --- a/source/modules/SendMessage.js +++ b/source/modules/SendMessage.js @@ -1,12 +1,12 @@ import { UnityInstance } from '../components/Unity' -export function SendMessage (gameObjectName, methodName, paramterValue) { - console.warn (`SendMessage is deprecated since version 6.4.0, use UnityEvent instead.`) +export function SendMessage(gameObjectName, methodName, paramterValue) { + console.warn(`SendMessage is deprecated since version 6.4.0, use UnityEvent instead.`) if (typeof UnityInstance !== 'undefined') - UnityInstance.SendMessage ( - gameObjectName, - methodName, + UnityInstance.SendMessage( + gameObjectName, + methodName, paramterValue || '') else - console.warn (`Wait for Unity to be instantiated before sending a message to '${gameObjectName}'`) + console.warn(`Wait for Unity to be instantiated before sending a message to '${gameObjectName}'`) } \ No newline at end of file diff --git a/source/modules/UnityEvent.js b/source/modules/UnityEvent.js index 1857e5ee..1d847df9 100644 --- a/source/modules/UnityEvent.js +++ b/source/modules/UnityEvent.js @@ -1,20 +1,20 @@ import { UnityInstance } from '../components/Unity' export class UnityEvent { - constructor (gameObjectName, methodName) { + constructor(gameObjectName, methodName) { this.gameObjectName = gameObjectName this.methodName = methodName } - emit (parameter) { - if (this.canEmit () === true) - UnityInstance.SendMessage ( - this.gameObjectName, - this.methodName, + emit(parameter) { + if (this.canEmit() === true) + UnityInstance.SendMessage( + this.gameObjectName, + this.methodName, parameter || '') else - console.warn (`Wait for Unity to be instantiated before sending an event '${this.methodName}'`) + console.warn(`Wait for Unity to be instantiated before sending an event '${this.methodName}'`) } - canEmit () { + canEmit() { return typeof UnityInstance !== 'undefined' } } \ No newline at end of file diff --git a/source/services/UnityLoaderService.js b/source/services/UnityLoaderService.js index 189ae500..96274dde 100644 --- a/source/services/UnityLoaderService.js +++ b/source/services/UnityLoaderService.js @@ -1,23 +1,23 @@ export default class UnityLoaderService { - constructor () { - this.documentHead = document.getElementsByTagName ('head')[0] + constructor() { + this.documentHead = document.getElementsByTagName('head')[0] this.unityLoaderScript = null } - append (src) { - return new Promise ((resolve, reject) => { - this.unityLoaderScript = document.createElement ('script') + append(src) { + return new Promise((resolve, reject) => { + this.unityLoaderScript = document.createElement('script') this.unityLoaderScript.type = 'text/javascript' this.unityLoaderScript.async = true this.unityLoaderScript.src = src this.unityLoaderScript.onload = () => { - resolve () + resolve() } - this.documentHead.appendChild (this.unityLoaderScript) + this.documentHead.appendChild(this.unityLoaderScript) }) } - unmount () { + unmount() { if (this.unityLoaderScript !== null) { - this.documentHead.removeChild (this.unityLoaderScript) + this.documentHead.removeChild(this.unityLoaderScript) } } } \ No newline at end of file From 6f902b5f56fa9601193e52a50656c6c7f16b234d Mon Sep 17 00:00:00 2001 From: Jeffrey Lanters Date: Wed, 17 Jan 2018 10:31:34 +0100 Subject: [PATCH 3/3] Fixed bug #24 --- library/modules/UnityEvent.js | 2 +- package.json | 4 ++-- source/modules/UnityEvent.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/modules/UnityEvent.js b/library/modules/UnityEvent.js index b6747570..5944236b 100644 --- a/library/modules/UnityEvent.js +++ b/library/modules/UnityEvent.js @@ -22,7 +22,7 @@ var UnityEvent = exports.UnityEvent = function () { _createClass(UnityEvent, [{ key: 'emit', value: function emit(parameter) { - if (this.canEmit() === true) _Unity.UnityInstance.SendMessage(this.gameObjectName, this.methodName, parameter || '');else console.warn('Wait for Unity to be instantiated before sending an event \'' + this.methodName + '\''); + if (this.canEmit() === true) _Unity.UnityInstance.SendMessage(this.gameObjectName, this.methodName, typeof parameter !== 'undefined' ? parameter : '');else console.warn('Wait for Unity to be instantiated before sending an event \'' + this.methodName + '\''); } }, { key: 'canEmit', diff --git a/package.json b/package.json index c68c66f0..3057afbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-unity-webgl", - "version": "6.4.1", + "version": "6.4.2", "description": "A Unity WebGL component for your React application", "main": "library/index.js", "types": "./types.d.ts", @@ -34,4 +34,4 @@ "babel-preset-env": "1.6.1", "babel-preset-react": "6.24.1" } -} +} \ No newline at end of file diff --git a/source/modules/UnityEvent.js b/source/modules/UnityEvent.js index 1d847df9..7fbe3891 100644 --- a/source/modules/UnityEvent.js +++ b/source/modules/UnityEvent.js @@ -10,7 +10,7 @@ export class UnityEvent { UnityInstance.SendMessage( this.gameObjectName, this.methodName, - parameter || '') + typeof parameter !== 'undefined' ? parameter : '') else console.warn(`Wait for Unity to be instantiated before sending an event '${this.methodName}'`) }