New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-unity-webgl

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-unity-webgl - npm Package Compare versions

Comparing version 6.3.1 to 6.4.0

library/modules/RegisterExternalEmitter.js

7

library/index.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports.SendMessage = exports.RegisterExternalListener = undefined;
exports.UnityEvent = exports.SendMessage = exports.RegisterExternalListener = undefined;

@@ -17,2 +17,4 @@ var _Unity = require('./components/Unity');

var _UnityEvent = require('./modules/UnityEvent');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -22,2 +24,3 @@

exports.RegisterExternalListener = _RegisterExternalListener.RegisterExternalListener;
exports.SendMessage = _SendMessage.SendMessage;
exports.SendMessage = _SendMessage.SendMessage;
exports.UnityEvent = _UnityEvent.UnityEvent;

@@ -7,10 +7,3 @@ 'use strict';

exports.RegisterExternalListener = RegisterExternalListener;
/**
* Registers a listener to this window. When a message is sent
* from Unity using 'CallExternal', the listener will forward it
* into your React Application.
* @param {string} functionName
* @param {function} callback
*/
function RegisterExternalListener(functionName, callback) {
function RegisterExternalListener(methodName, callback) {
/**

@@ -23,4 +16,4 @@ * LEGACY

*/
window[functionName] = function (paramterValue) {
callback(paramterValue);
window[methodName] = function (parameter) {
callback(parameter);
};

@@ -34,5 +27,5 @@

if (typeof window.ReactUnityWebGL === 'undefined') window.ReactUnityWebGL = {};
window.ReactUnityWebGL[functionName] = function (paramterValue) {
callback(paramterValue);
window.ReactUnityWebGL[methodName] = function (parameter) {
callback(parameter);
};
}

@@ -10,14 +10,5 @@ 'use strict';

/**
* Sends a message to the Unity content. This works the same
* as Unity's internal 'SendMessage' system. The paramaterValue
* is an optional field.
* @param {string} gameObjectName
* @param {string} methodName
* @param {object} paramterValue
*/
function SendMessage(gameObjectName, methodName, paramterValue) {
if (typeof paramterValue === 'undefined') paramterValue = '';
if (typeof _Unity.UnityInstance !== 'undefined') _Unity.UnityInstance.SendMessage(gameObjectName, methodName, paramterValue);else console.warn('Wait for Unity to be instantiated before sending a message to \'' + gameObjectName + '\'');
console.warn('SendMessage is deprecated since version 6.4.0, use UnityEvent instead.');
if (typeof _Unity.UnityInstance !== 'undefined') _Unity.UnityInstance.SendMessage(gameObjectName, methodName, paramterValue || '');else console.warn('Wait for Unity to be instantiated before sending a message to \'' + gameObjectName + '\'');
}
{
"name": "react-unity-webgl",
"version": "6.3.1",
"version": "6.4.0",
"description": "A Unity WebGL component for your React application",
"main": "library/index.js",
"types": "source/types.d.ts",
"types": "./types.d.ts",
"scripts": {

@@ -8,0 +8,0 @@ "compile": "babel --presets react source --out-dir library"

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

# React Unity WebGL
# 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)]()
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.

@@ -88,19 +89,23 @@

# Calling Unity scripts functions from JavaScript in React
Sometimes you need to send some data or notification to the Unity script from the browser’s JavaScript. The recommended way of doing it is to call methods on GameObjects in your content. To get started import the function SendMessage from react-unity-webgl.
Sometimes you need to send some data or notification to the Unity script from the browser’s JavaScript. The recommended way of doing it is to call methods on GameObjects in your content. To get started import the class UnityEvent from react-unity-webgl.
```js
SendMessage (objectName: String, methodName: String, value: Object): void;
UnityEvent (objectName: String, methodName: String);
```
Where objectName is the name of an object in your scene; methodName is the name of a method in the script, currently attached to that object; value can be a string, a number, or can be empty. For example:
Where objectName is the name of an object in your scene; methodName is the name of a method in the script, currently attached to that object. When you've created a new UnityEvent, you can call the 'emit' function to fire it into Unity. You can pass an optional parameter value.
```js
import React from 'react'
import { SendMessage } from 'react-unity-webgl'
import { UnityEvent } from 'react-unity-webgl'
export class App extends React.Component {
spawnEnemy (count) {
SendMessage ('SpawnBehaviour', 'SpawnEnemies', count)
constructor () {
this.spawnEnemies = new UnityEvent ('SpawnBehaviour', 'SpawnEnemies')
}
onClickSpawnEnemies (count) {
if (this.spawnEnemies.canEmit () === true)
this.spawnEnemies.emit (count)
}
render () {
return <div onClick={ this.spawnEnemy.bind(this, 5) }>
return <div onClick={ this.onClickSpawnEnemies.bind (this, 5) }>
Click to Spawn 5 Enemies</div>

@@ -110,3 +115,3 @@ }

```
While in Unity, for example:
While in Unity the following script is attached the a game object named 'SpawnBehaviour'.
```cs

@@ -192,2 +197,2 @@ using UnityEngine;

# Contributing
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. Before commiting, please compile your code using `npm run compile` and open a pull request. Thank you very much!
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. Before commiting, please compile your code using `npm run compile` and open a pull request. Thank you very much!

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc