Skip to content

Commit 36b7406

Browse files
docs: improve readme
1 parent 6b4f707 commit 36b7406

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ import { UnityLoaderConfig } from 'react-unity-renderer';
157157
export async function fetchLoaderConfig(
158158
baseUrl: string
159159
): Promise<UnityLoaderConfig> {
160-
// set the URL of where we expect the loader config to be and disable caching
161-
const url = `${baseUrl}/build.json?t=${new Date().getTime()}`;
160+
// set the URL of where we expect the loader config to be
161+
const url = `${baseUrl}/build.json`;
162162

163163
let response: Response | undefined;
164164

@@ -222,7 +222,7 @@ If the event name has no registered event handlers, the `UnityBridge(event: stri
222222
### On the React side
223223

224224
```tsx
225-
import { VFC, useState } from 'react';
225+
import { VFC, useState, useEffect } from 'react';
226226
import { UnityContext, UnityRenderer } from 'react-unity-renderer';
227227

228228
export const UnityGameComponent: VFC = (): JSX.Element => {
@@ -255,7 +255,7 @@ messages are a way to communicate the other way, from JavaScript to Unity.
255255
Messages are emitted from the `UnityContext`, the API for emitting then is the same as in the Unity WebGL documentation:
256256

257257
```tsx
258-
import { VFC, useState } from 'react';
258+
import { VFC, useState, useEffect } from 'react';
259259
import { UnityContext, UnityRenderer } from 'react-unity-renderer';
260260

261261
export const UnityGameComponent: VFC = (): JSX.Element => {
@@ -334,3 +334,25 @@ ctx.on('info', (message) => {
334334
console.log(message);
335335
});
336336
```
337+
338+
## API
339+
340+
### `UnityRenderer`
341+
342+
```tsx
343+
<UnityRenderer
344+
context={ ... }
345+
onUnityProgressChange={ ... }
346+
onUnityReadyStateChange={ ... }
347+
onUnityError={ ... }
348+
{ ...HTMLAttributes }
349+
/>
350+
```
351+
352+
| | | |
353+
|---|---|---|
354+
| context | The context of the game build, which handles loading and event I/O. | `UnityContext` | `undefined` |
355+
| onUnityProgressChange | Callback to execute when the loading progress of the game changes. Ranges from `0.0` to `1.0`. | `(progress: number) => void` | `undefined` |
356+
| onUnityReadyStateChange | Callback to execute when the game build finished loading and begins to render. | `(ready: boolean) => void` | `undefined` |
357+
| onUnityError | Callback which executes when an error occurs while loading the game. Currently Unity limits what errors can be cought, so some errors still appear via `window.alert()`. | `(error: Error) => void` | `undefined` |
358+
| `{...HTMLAttributes}` | All default attributes of a `<canvas>` element are supported to allow for an atomic component, supporting custom styling and libraries like `styled-components`. | `Omit<HTMLAttributes<HtmlCanvasElement>, 'ref' | 'id'` | |

0 commit comments

Comments
 (0)