You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ When building content for the web, you might need to communicate with other elem
19
19
-[Calling JavaScript functions within React from Unity scripts](#calling-javascript-functions-within-react-from-unity-scripts)
20
20
-[Notes](#notes)
21
21
-[5.x to 6.x Upgrade note](#5x-to-6x-upgrade-note)
22
+
-[Best practices for adding the src and loader files on a public path](#best-practices-for-adding-the-src-and-loader-files-on-a-public-path)
22
23
-[Contributing](#contributing)
23
24
24
25
@@ -37,7 +38,7 @@ $ npm install react-unity-webgl
37
38
38
39
39
40
# Usage
40
-
To get started import the default Unity class from react-unity-webgl and include it in your render while giving the public path to your src and loader files.
41
+
To get started import the default Unity class from react-unity-webgl and include it in your render while giving the public path to your src and loader files.[Best practices for adding the src and loader files on a public path](#best-practices-for-adding-the-src-and-loader-files-on-a-public-path).
41
42
42
43
```js
43
44
importReactfrom'react'
@@ -150,6 +151,16 @@ public class MenuController: MonoBehaviour {
150
151
}
151
152
}
152
153
```
154
+
Or using the **legacy** way in Unity, for example:
155
+
```cs
156
+
usingUnityEngine;
157
+
158
+
publicclassMenuController: MonoBehaviour {
159
+
publicvoidOpenReactMenuById (stringmenuId) {
160
+
Application.ExternalCall ("OpenMenu", menuId);
161
+
}
162
+
}
163
+
```
153
164
Simple numeric types can be passed to JavaScript in function parameters without requiring any conversion. Other data types will be passed as a pointer in the emscripten heap (which is really just a big array in JavaScript). For strings, you can use the Pointer_stringify helper function to convert to a JavaScript string. To return a string value you need to call _malloc_ to allocate some memory and the writeStringToMemory helper function to write a JavaScript string to it. If the string is a return value, then the il2cpp runtime will take care of freeing the memory for you. For arrays of primitive types, emscripten provides different ArrayBufferViews into it’s heap for different sizes of integer, unsigned integer or floating point representations of memory: HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64. To access a texture in WebGL, emscripten provides the GL.textures array which maps native texture IDs from Unity to WebGL texture objects. WebGL functions can be called on emscripten’s WebGL context, GLctx.
154
165
155
166
Legacy ways of calling JavaScript code from Unity. You can use the Application.ExternalCall () and Application.ExternalEval () functions to invoke JavaScript code on the embedding web page. Note that expressions are evaluated in the local scope of the build. If you would like to execute JavaScript code in the global scope, see the Code Visibility section below.
@@ -159,7 +170,8 @@ Legacy ways of calling JavaScript code from Unity. You can use the Application.E
159
170
160
171
161
172
# Notes
162
-
Make sure your Unity build is in your public folder, this is due to the component **and** Unity itself will load files in Runtime and not Compile/Bundle time.
173
+
## Best practices for adding the src and loader files on a public path
174
+
Make sure your Unity build is in your public folder, this is due to the component **and** Unity itself will load files in Runtime and not Compile/Bundle time. The public folder means that the folder should be accesible via a public web adress. The path within your `src` and `loader` should be relative to the html file your app is running in.
163
175
## 5.x to 6.x Upgrade note
164
176
When upgrading from 5.x to 6.x, make sure you add the `loader` prop to the Unity component and remove the script tag from your HTML page refering to the UnityLoader.js file. See [Usage](#usage) for further details.
165
177
@@ -168,4 +180,4 @@ When upgrading from 5.x to 6.x, make sure you add the `loader` prop to the Unity
168
180
169
181
170
182
# Contributing
171
-
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!
183
+
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!
0 commit comments