Skip to content

Commit 15759a4

Browse files
author
Jeffrey Lanters
authored
Merge pull request #25 from jeffreylanters/development
Fixed bug #24
2 parents 555998f + 6f902b5 commit 15759a4

File tree

8 files changed

+54
-54
lines changed

8 files changed

+54
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 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)]()
1+
# 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)]()
22

33
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.
44

library/modules/UnityEvent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var UnityEvent = exports.UnityEvent = function () {
2222
_createClass(UnityEvent, [{
2323
key: 'emit',
2424
value: function emit(parameter) {
25-
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 + '\'');
25+
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 + '\'');
2626
}
2727
}, {
2828
key: 'canEmit',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-unity-webgl",
3-
"version": "6.4.1",
3+
"version": "6.4.2",
44
"description": "A Unity WebGL component for your React application",
55
"main": "library/index.js",
66
"types": "./types.d.ts",
@@ -34,4 +34,4 @@
3434
"babel-preset-env": "1.6.1",
3535
"babel-preset-react": "6.24.1"
3636
}
37-
}
37+
}

source/components/Unity.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,59 @@ import UnityLoaderService from '../services/UnityLoaderService'
33
import Styles from './Unity.styles'
44

55
export default class Unity extends Component {
6-
constructor (props) {
7-
super (props)
6+
constructor(props) {
7+
super(props)
88
this.state = {
99
error: null
1010
}
11-
this._unityLoaderService = new UnityLoaderService ()
11+
this._unityLoaderService = new UnityLoaderService()
1212
}
13-
componentDidMount () {
14-
this._instantiate ()
13+
componentDidMount() {
14+
this._instantiate()
1515
}
16-
componentWillUnmount () {
17-
this._unityLoaderService.unmount ()
16+
componentWillUnmount() {
17+
this._unityLoaderService.unmount()
1818
}
19-
_instantiate () {
19+
_instantiate() {
2020
let error = null
2121
if (typeof this.props.loader === 'undefined')
2222
error = 'Please provide Unity with a path to the UnityLoader in the loader prop.'
2323
if (typeof this.props.src === 'undefined')
2424
error = 'Please provide Unity with a path to a valid JSON in the src prop.'
2525

2626
if (error !== null) {
27-
console.error (error)
28-
this.setState ({ error: error })
29-
}
27+
console.error(error)
28+
this.setState({ error: error })
29+
}
3030
else {
31-
this._unityLoaderService.append (this.props.loader).then (() => {
32-
let unityInstance = UnityLoader.instantiate ('unity', this.props.src, {
33-
onProgress: this._onProgress.bind (this),
34-
Module : this.props.module
31+
this._unityLoaderService.append(this.props.loader).then(() => {
32+
let unityInstance = UnityLoader.instantiate('unity', this.props.src, {
33+
onProgress: this._onProgress.bind(this),
34+
Module: this.props.module
3535
})
3636
module.exports.UnityInstance = unityInstance
3737
})
3838
}
3939
}
40-
_onProgress (unityInstance, progression) {
40+
_onProgress(unityInstance, progression) {
4141
if (typeof this.props.onProgress !== 'undefined') {
42-
this.props.onProgress (progression)
42+
this.props.onProgress(progression)
4343
}
4444
}
45-
_getContainerStyles () {
45+
_getContainerStyles() {
4646
return {
4747
width: this.props.width || '100%',
4848
height: this.props.height || '100%'
4949
}
5050
}
51-
render () {
51+
render() {
5252
return (
53-
<div className='unity' style={this._getContainerStyles ()}>
53+
<div className='unity' style={this._getContainerStyles()}>
5454
{this.state.error !== null ? (
5555
<b>React-Unity-Webgl error {this.state.error}</b>
56-
):(
57-
<div style={Styles.unity} id='unity'></div>
58-
)}
56+
) : (
57+
<div style={Styles.unity} id='unity'></div>
58+
)}
5959
</div>
6060
)
6161
}

source/modules/RegisterExternalListener.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function RegisterExternalListener (methodName, callback) {
1+
export function RegisterExternalListener(methodName, callback) {
22
/**
33
* LEGACY
44
* bind the function to the window to allow
@@ -7,7 +7,7 @@ export function RegisterExternalListener (methodName, callback) {
77
* Application.ExternalEval.
88
*/
99
window[methodName] = parameter => {
10-
callback (parameter)
10+
callback(parameter)
1111
}
1212

1313
/**
@@ -18,6 +18,6 @@ export function RegisterExternalListener (methodName, callback) {
1818
if (typeof window.ReactUnityWebGL === 'undefined')
1919
window.ReactUnityWebGL = {}
2020
window.ReactUnityWebGL[methodName] = parameter => {
21-
callback (parameter)
21+
callback(parameter)
2222
}
2323
}

source/modules/SendMessage.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { UnityInstance } from '../components/Unity'
22

3-
export function SendMessage (gameObjectName, methodName, paramterValue) {
4-
console.warn (`SendMessage is deprecated since version 6.4.0, use UnityEvent instead.`)
3+
export function SendMessage(gameObjectName, methodName, paramterValue) {
4+
console.warn(`SendMessage is deprecated since version 6.4.0, use UnityEvent instead.`)
55
if (typeof UnityInstance !== 'undefined')
6-
UnityInstance.SendMessage (
7-
gameObjectName,
8-
methodName,
6+
UnityInstance.SendMessage(
7+
gameObjectName,
8+
methodName,
99
paramterValue || '')
1010
else
11-
console.warn (`Wait for Unity to be instantiated before sending a message to '${gameObjectName}'`)
11+
console.warn(`Wait for Unity to be instantiated before sending a message to '${gameObjectName}'`)
1212
}

source/modules/UnityEvent.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { UnityInstance } from '../components/Unity'
22

33
export class UnityEvent {
4-
constructor (gameObjectName, methodName) {
4+
constructor(gameObjectName, methodName) {
55
this.gameObjectName = gameObjectName
66
this.methodName = methodName
77
}
8-
emit (parameter) {
9-
if (this.canEmit () === true)
10-
UnityInstance.SendMessage (
11-
this.gameObjectName,
12-
this.methodName,
13-
parameter || '')
8+
emit(parameter) {
9+
if (this.canEmit() === true)
10+
UnityInstance.SendMessage(
11+
this.gameObjectName,
12+
this.methodName,
13+
typeof parameter !== 'undefined' ? parameter : '')
1414
else
15-
console.warn (`Wait for Unity to be instantiated before sending an event '${this.methodName}'`)
15+
console.warn(`Wait for Unity to be instantiated before sending an event '${this.methodName}'`)
1616
}
17-
canEmit () {
17+
canEmit() {
1818
return typeof UnityInstance !== 'undefined'
1919
}
2020
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
export default class UnityLoaderService {
2-
constructor () {
3-
this.documentHead = document.getElementsByTagName ('head')[0]
2+
constructor() {
3+
this.documentHead = document.getElementsByTagName('head')[0]
44
this.unityLoaderScript = null
55
}
6-
append (src) {
7-
return new Promise ((resolve, reject) => {
8-
this.unityLoaderScript = document.createElement ('script')
6+
append(src) {
7+
return new Promise((resolve, reject) => {
8+
this.unityLoaderScript = document.createElement('script')
99
this.unityLoaderScript.type = 'text/javascript'
1010
this.unityLoaderScript.async = true
1111
this.unityLoaderScript.src = src
1212
this.unityLoaderScript.onload = () => {
13-
resolve ()
13+
resolve()
1414
}
15-
this.documentHead.appendChild (this.unityLoaderScript)
15+
this.documentHead.appendChild(this.unityLoaderScript)
1616
})
1717
}
18-
unmount () {
18+
unmount() {
1919
if (this.unityLoaderScript !== null) {
20-
this.documentHead.removeChild (this.unityLoaderScript)
20+
this.documentHead.removeChild(this.unityLoaderScript)
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)