Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
194 commits
Select commit Hold shift + click to select a range
a22b0b2
Use script.remove instead of removeChild for unity loader hook (#576)
alexqhj May 15, 2025
c0c58fe
Removed deprecated actions
jeffreylanters May 19, 2025
ade588e
Add autoSyncPersistentDataPath to ConfigurableUnityArguments type
jeffreylanters Jun 16, 2025
583ef34
Update RELEASE-NOTES.md to add support for autoSyncPersistentDataPath…
jeffreylanters Jun 16, 2025
31f37bd
Bump version to 9.9.0 in package.json and package-lock.json
jeffreylanters Jun 16, 2025
9e5ca18
Update cache action to v4 in workflow files
jeffreylanters Jun 16, 2025
1de5449
Started reworking module source
jeffreylanters Jul 15, 2025
af7320d
Initial Unity component
jeffreylanters Jul 15, 2025
21255e0
Removed unused exports
jeffreylanters Jul 15, 2025
2177d85
Updated packages
jeffreylanters Jul 15, 2025
49c3acd
Fix import path for UnityInstance in global type declarations
jeffreylanters Jul 15, 2025
c18e903
Remove unused type declarations for UnityBooleanLike, UnityInstance, …
jeffreylanters Jul 15, 2025
bd191de
Refactor Unity component to use forwardRef and improve type safety
jeffreylanters Jul 15, 2025
8ca63ab
Add useCanvasIdentifier hook to generate unique Unity canvas IDs
jeffreylanters Jul 15, 2025
f17d87f
Add useUnityLoader hook to manage Unity loader status in Unity component
jeffreylanters Jul 15, 2025
c0f7428
Add isBrowserEnvironment constant to check for browser environment
jeffreylanters Jul 15, 2025
6825b4f
Add useUnityContext hook to manage Unity configuration and provider
jeffreylanters Jul 15, 2025
56689c9
Add useUnityLoader hook to manage Unity loader script and status
jeffreylanters Jul 15, 2025
02bf8d9
Add type definition for ReactUnityEventParameter to support Unity eve…
jeffreylanters Jul 15, 2025
eb2dcf3
Add UnityArguments type definition to initialize Unity instance with …
jeffreylanters Jul 15, 2025
e7053a3
Add UnityBooleanLike type declaration to represent boolean values in …
jeffreylanters Jul 15, 2025
afefba7
Add UnityCacheControlMode type definition to manage caching behavior …
jeffreylanters Jul 15, 2025
f5d711b
Add UnityConfig type definition to specify Unity configuration options
jeffreylanters Jul 15, 2025
290a947
Add type definition for UnityContext to encapsulate Unity Provider in…
jeffreylanters Jul 15, 2025
1d0066a
Add type definition for UnityInstanceBannerType to represent banner m…
jeffreylanters Jul 15, 2025
e2575ae
Add type declaration for UnityInstance to define its methods and prop…
jeffreylanters Jul 15, 2025
0acc28e
Add type definition for UnityLoaderStatus to represent loader states
jeffreylanters Jul 15, 2025
b64ca0b
Add type declaration for UnityModule to define its methods and proper…
jeffreylanters Jul 15, 2025
0b336be
Add type declaration for UnityProps to define properties for Unity co…
jeffreylanters Jul 15, 2025
71e44ac
Add type declaration for UnityProvider to define properties for Unity…
jeffreylanters Jul 15, 2025
27edd9c
Export useUnityContext from the module for improved accessibility
jeffreylanters Jul 15, 2025
6847e38
Update TypeScript and @types/react to latest versions for improved co…
jeffreylanters Jul 15, 2025
7ca4496
Add Unity WebGL loader and WebAssembly binary
jeffreylanters Jul 15, 2025
abc20db
Refactor Application component to simplify Unity integration and remo…
jeffreylanters Jul 15, 2025
957a4ca
Remove react-unity-webgl dependency from package.json and package-loc…
jeffreylanters Jul 15, 2025
fb21ed7
Enhance Unity component to support dynamic initialization and cleanup…
jeffreylanters Jul 15, 2025
ae0237e
Fix canvas ID generation to prevent incrementing canvas count prematu…
jeffreylanters Jul 15, 2025
1bee99f
Refactor event parameter types to unify Unity event handling and remo…
jeffreylanters Jul 15, 2025
b5477c9
Pass loading progression callback to createUnityInstance for enhanced…
jeffreylanters Jul 15, 2025
b4918f2
Add loading progression state to useUnityContext for enhanced loading…
jeffreylanters Jul 15, 2025
f36f6b6
Add loading progression property to UnityContext type for improved lo…
jeffreylanters Jul 15, 2025
29b8d5c
Add setLoadingProgression method to UnityProvider type for loading fe…
jeffreylanters Jul 15, 2025
6bf610d
Update Application component to display loading progression and adjus…
jeffreylanters Jul 15, 2025
b236235
Implement loading progression callback in Unity component for enhance…
jeffreylanters Jul 15, 2025
5d0237f
Add isLoaded state to useUnityContext for tracking loading completion
jeffreylanters Jul 15, 2025
8d1ae0e
Add isLoaded property to UnityContext type for loading state tracking
jeffreylanters Jul 15, 2025
54b8c12
Add optional setIsLoaded method to UnityProvider type for loading sta…
jeffreylanters Jul 15, 2025
e422dc7
Export UnityEventParameter type from exports.ts for improved type acc…
jeffreylanters Jul 15, 2025
d900502
Enhance Application component with loading state tracking and console…
jeffreylanters Jul 15, 2025
a342974
Reset loading state and handle initialization errors in Unity component
jeffreylanters Jul 15, 2025
03c40bd
Add initialisationError state management to useUnityContext hook
jeffreylanters Jul 15, 2025
f305e14
Add initialisationError property to UnityContext type for error handling
jeffreylanters Jul 15, 2025
9315e2c
Make setIsLoaded property mandatory in UnityProvider type definition
jeffreylanters Jul 15, 2025
c4d67ad
Use nullish coalescing operator for initialisationError message display
jeffreylanters Jul 15, 2025
ad574e1
Add devicePixelRatio to Unity instance creation for improved rendering
jeffreylanters Jul 15, 2025
fd4ae0d
Refactor UnityProps type to include devicePixelRatio from UnityArguments
jeffreylanters Jul 15, 2025
874ce7d
Add devicePixelRatio to canvas for improved rendering quality
jeffreylanters Jul 15, 2025
22e7a67
Enhance documentation for useUnityContext hook and Unity component er…
jeffreylanters Jul 15, 2025
8e9dfc4
Enable requestFullscreen functionality in Application component
jeffreylanters Jul 15, 2025
b287415
Refactor UnityInstance type declaration to use Pick for improved clar…
jeffreylanters Jul 16, 2025
62b22fe
Refactor UnityInstance type declaration to include Quit method for im…
jeffreylanters Jul 16, 2025
0bbdda3
Refactor UnityModule type declaration to improve structure and add mi…
jeffreylanters Jul 16, 2025
fd2a891
Remove unused imports from UnityInstance type declaration for cleaner…
jeffreylanters Jul 16, 2025
a5acf4d
Enable requestFullscreen functionality and add missing properties in …
jeffreylanters Jul 16, 2025
eb16ebd
Refactor UnityProvider type declaration to include additional propert…
jeffreylanters Jul 16, 2025
c201786
Refactor UnityConfig type declaration to include additional propertie…
jeffreylanters Jul 16, 2025
93d9491
Refactor useUnityContext to include companyName, productName, and pro…
jeffreylanters Jul 16, 2025
1f0ebf5
Add companyName, productName, and productVersion to Unity instance cr…
jeffreylanters Jul 16, 2025
27030f3
Refactor UnityProvider type declaration to include setUnityInstance m…
jeffreylanters Jul 16, 2025
0c162ba
Refactor UnityContext type declaration to include requestFullscreen m…
jeffreylanters Jul 16, 2025
511c122
Refactor useUnityContext to include requestFullscreen method for impr…
jeffreylanters Jul 16, 2025
5f8f4c2
Refactor Unity instance management to ensure proper detachment and re…
jeffreylanters Jul 16, 2025
301066c
Refactor Application component to enable requestPointerLock and sendM…
jeffreylanters Jul 16, 2025
651de5f
Refactor UnityProvider type declaration to include additional Unity a…
jeffreylanters Jul 16, 2025
ca669be
Refactor UnityContext type declaration to include requestPointerLock …
jeffreylanters Jul 16, 2025
7ab2f9a
Refactor UnityConfig type declaration to include additional Unity ass…
jeffreylanters Jul 16, 2025
8092119
Refactor useUnityContext to include additional Unity asset properties…
jeffreylanters Jul 16, 2025
de54e23
Refactor Unity component to include additional Unity asset properties…
jeffreylanters Jul 16, 2025
04ae1f3
Refactor UnityContext type declaration to include sendMessage method …
jeffreylanters Jul 16, 2025
529a36e
Add sendMessage method to useUnityContext for invoking public methods…
jeffreylanters Jul 16, 2025
f511c49
Enable takeScreenshot functionality in Application component
jeffreylanters Jul 16, 2025
c6ca53d
Add takeScreenshot method to UnityContext for capturing screenshots
jeffreylanters Jul 16, 2025
35e3107
Add takeScreenshot method to useUnityContext for capturing screenshots
jeffreylanters Jul 16, 2025
f2057f7
Refactor comments in useUnityContext and update takeScreenshot parame…
jeffreylanters Jul 16, 2025
8ead86b
Enable webglContextAttributes in Application component for preserving…
jeffreylanters Jul 16, 2025
def3cce
Add webglContextAttributes to UnityProvider type definition
jeffreylanters Jul 16, 2025
21b7da8
Add webglContextAttributes to UnityConfig type definition
jeffreylanters Jul 16, 2025
dc58bd7
Add webglContextAttributes to Unity instance creation
jeffreylanters Jul 16, 2025
cb07eed
Enable unload functionality in Application component
jeffreylanters Jul 16, 2025
1711afa
Add unload method to UnityContext for resource cleanup
jeffreylanters Jul 16, 2025
22b119d
Add unload method to useUnityContext for resource cleanup
jeffreylanters Jul 16, 2025
22373a8
Enable cache control in Unity instance configuration
jeffreylanters Jul 16, 2025
7717fe9
Add cacheControl to UnityProvider type definition
jeffreylanters Jul 16, 2025
f24c83b
Add cacheControl to UnityConfig type definition
jeffreylanters Jul 16, 2025
e8dd549
Fix documentation and ensure cacheControl is included in UnityProvide…
jeffreylanters Jul 16, 2025
94e0c0d
Update Unity component to set loading state correctly and include cac…
jeffreylanters Jul 16, 2025
7a3a222
Refactor comments for unimplemented features and add TODOs for future…
jeffreylanters Jul 16, 2025
a83a496
Implement event listener functionality in Application component
jeffreylanters Jul 16, 2025
453c4f8
Import EventSystem to enhance UnityContext type definition
jeffreylanters Jul 16, 2025
ce56a88
Add EventSystem type definition for external React Unity events
jeffreylanters Jul 16, 2025
c063cc0
Add EventListener type definition for handling Unity events
jeffreylanters Jul 16, 2025
7f2f43c
Add event system integration to useUnityContext for managing Unity ev…
jeffreylanters Jul 16, 2025
e22d5ee
Implement useEventSystem hook for managing external React Unity events
jeffreylanters Jul 16, 2025
64c2403
Add Unity communication loader and WebAssembly binary
jeffreylanters Jul 16, 2025
8bb5f98
Update Unity build paths and enable autoSyncPersistentDataPath
jeffreylanters Jul 16, 2025
a8ee686
Add autoSyncPersistentDataPath to UnityProvider type definition
jeffreylanters Jul 16, 2025
1fb0083
Update UnityProps type to include matchWebGLToCanvasSize and disabled…
jeffreylanters Jul 16, 2025
a152267
Add autoSyncPersistentDataPath to UnityConfig type definition
jeffreylanters Jul 16, 2025
1d6a831
Add autoSyncPersistentDataPath to UnityProvider instance in useUnityC…
jeffreylanters Jul 16, 2025
49faffc
Add autoSyncPersistentDataPath, matchWebGLToCanvasSize, and disabledC…
jeffreylanters Jul 16, 2025
a3ab645
Add className and tabIndex properties to canvas element in Applicatio…
jeffreylanters Jul 16, 2025
fa5fc6d
Add className and tabIndex properties to UnityProps type definition
jeffreylanters Jul 16, 2025
5ecc124
Add className and tabIndex properties to Unity component
jeffreylanters Jul 16, 2025
53c4f53
Migrating documentation to version 10
jeffreylanters Jul 16, 2025
20bbf90
chore: update dependencies and version to 1.0.5
jeffreylanters Jul 16, 2025
d59cc11
docs: update unload documentation to reflect changes in React Unity W…
jeffreylanters Jul 16, 2025
398d9f7
fix: restore unload documentation in API sidebar
jeffreylanters Jul 16, 2025
337f92c
docs: update release notes for React Unity WebGL version 10.0.0
jeffreylanters Jul 16, 2025
3b474a5
Resolved documentation migration links
jeffreylanters Jul 16, 2025
105f57d
docs: update introduction and support pages to reflect new contact in…
jeffreylanters Jul 16, 2025
0e63a63
docs: add upgrading guide for version 9
jeffreylanters Jul 16, 2025
5879fdb
docs: add upgrading guide for version 10 and update sidebar reference
jeffreylanters Jul 16, 2025
29a1b5c
docs: update package dependencies for Unity modules and improve versi…
jeffreylanters Jul 16, 2025
7664832
docs: update EditorBuildSettings and ProjectVersion for new scene con…
jeffreylanters Jul 16, 2025
02c04db
Upgraded testing build to one from Unity 6
jeffreylanters Jul 16, 2025
a0c3926
feat: add SystemInfo type definition and integrate it into UnityModule
jeffreylanters Jul 16, 2025
a92c392
feat: add UnitySystemInfo type definition and update UnityModule inte…
jeffreylanters Jul 16, 2025
49f4da8
feat: add UnityMetricsInfo type definition and integrate it into Unit…
jeffreylanters Jul 16, 2025
492cf4f
feat: replace UnityInstanceBannerType with UnityBannerType in UnityAr…
jeffreylanters Jul 16, 2025
2e0c827
feat: add MetricsConfig type definition and update UnityInstance prop…
jeffreylanters Jul 16, 2025
a49185b
feat: integrate useUnityMetricsInfo to display FPS in Application com…
jeffreylanters Jul 16, 2025
ac1edf5
feat: export useUnityMetricsInfo from exports.ts
jeffreylanters Jul 16, 2025
b361396
feat: make all properties of UnityMetricsInfo optional
jeffreylanters Jul 16, 2025
6829e49
feat: add getMetricsInfo method to UnityContext for performance metrics
jeffreylanters Jul 16, 2025
0f349c1
docs: update MetricsConfig type definition to clarify default interva…
jeffreylanters Jul 16, 2025
6645575
feat: implement useUnityMetricsInfo hook for retrieving Unity metrics
jeffreylanters Jul 16, 2025
b1b7fc6
feat: add getMetricsInfo method to retrieve performance metrics from …
jeffreylanters Jul 16, 2025
2d2bc41
chore: update version to 10.1.0 in package.json and package-lock.json
jeffreylanters Jul 16, 2025
a03c1b7
docs: update example title for using the unload function in documenta…
jeffreylanters Jul 16, 2025
51b4b51
docs: update example usage to clarify stopping the Unity Application
jeffreylanters Jul 16, 2025
557c437
docs: add documentation for compressed builds and server configuratio…
jeffreylanters Jul 16, 2025
ecc12c8
fix: correct typo in ID for compression and server configuration docu…
jeffreylanters Jul 16, 2025
e137b4d
docs: add label for upgrading documentation section
jeffreylanters Jul 16, 2025
61779e1
docs: update unloading issue explanation in upgrading documentation
jeffreylanters Jul 16, 2025
a1276c1
docs: add metrics info documentation and update sidebar for debugging…
jeffreylanters Jul 16, 2025
5b4cd47
docs: update release notes to include Unity Metrics Info API and perf…
jeffreylanters Jul 16, 2025
9e6b6eb
Added profiling example to front-page
jeffreylanters Jul 16, 2025
f596ac2
docs: add tutorials for using Unity WebGL with React
jeffreylanters Jul 16, 2025
4119c14
docs: update announcement bar message and background color; add tutor…
jeffreylanters Jul 16, 2025
ed0c910
fix: use default cache control if not provided in Unity props
jeffreylanters Jul 16, 2025
d82dbb2
feat: add default cache control function for Unity WebGL builds
jeffreylanters Jul 16, 2025
2c07567
feat: add default WebGL context attributes constant
jeffreylanters Jul 16, 2025
624116e
feat: use default WebGL context attributes if not provided in Unity p…
jeffreylanters Jul 16, 2025
69b8544
chore: update version to 10.1.1 in package.json and package-lock.json
jeffreylanters Jul 16, 2025
1dcd8e5
fix: update release notes to reflect resolution of cache control and …
jeffreylanters Jul 16, 2025
24e13f0
feat: add demo link to the navigation bar in docusaurus config
jeffreylanters Jul 18, 2025
e38071e
fix: update version label to specify "Version 10 (Current)" in docusa…
jeffreylanters Jul 18, 2025
04145c9
refactor: remove default cache control and WebGL context attributes c…
jeffreylanters Jul 19, 2025
849e49a
update company name from in application configuration
jeffreylanters Jul 19, 2025
b0d2265
refactor: streamline UnityProps type definition by consolidating canv…
jeffreylanters Jul 19, 2025
b11fc83
fix: correct import statement for RefAttributes in Unity component
jeffreylanters Jul 19, 2025
2372def
refactor: enhance UnitySystemInfo type definition with additional com…
jeffreylanters Jul 19, 2025
0cfe842
refactor: reorganize UnityMetricsInfo type definition for improved re…
jeffreylanters Jul 19, 2025
facec05
refactor: enhance UnityBannerType definition with additional comments…
jeffreylanters Jul 19, 2025
0b52d19
refactor: format requestPointerLock function for improved readability
jeffreylanters Jul 19, 2025
8d65cb6
refactor: add onSuccess and onError parameters to createUnityInstance…
jeffreylanters Jul 21, 2025
c12c325
refactor: remove unnecessary console.log statement from Unity component
jeffreylanters Jul 21, 2025
558c964
refactor: enhance documentation for UnityProvider methods for clarity
jeffreylanters Jul 21, 2025
cafc343
refactor: improve documentation for UnityProvider interface for bette…
jeffreylanters Jul 21, 2025
367c47c
refactor: update cache control method in RELEASE-NOTES for improved c…
jeffreylanters Jul 21, 2025
5dad55c
chore: update version to 10.1.2 in package.json and package-lock.json
jeffreylanters Jul 21, 2025
60491db
fix: exporting internal types as the correct file types
jeffreylanters Jul 21, 2025
d9ce772
refactor: expand exported types in exports.ts for improved type acces…
jeffreylanters Jul 21, 2025
d249339
fix: add note about resolving internal type export issues in RELEASE-…
jeffreylanters Jul 21, 2025
f38760d
chore: update version to 10.1.3 in package.json and package-lock.json
jeffreylanters Jul 21, 2025
f351ba1
fix: remove outdated note about cache control method in RELEASE-NOTES
jeffreylanters Jul 21, 2025
0451325
fix: add UnityMessageParameter to exports for improved type accessibi…
jeffreylanters Jul 21, 2025
ce4b953
fix: update parameter type in SendMessage to UnityMessageParameter fo…
jeffreylanters Jul 21, 2025
621a7bf
feat: add UnityMessageParameter type declaration for flexible message…
jeffreylanters Jul 21, 2025
3abbecf
fix: revert UnityEventParameter type to 'any' for broader compatibility
jeffreylanters Jul 21, 2025
5d9d1c7
fix: update sendMessage parameter type to UnityMessageParameter for c…
jeffreylanters Jul 21, 2025
39b0572
fix: update parameter type in useUnityContext to UnityMessageParamete…
jeffreylanters Jul 21, 2025
2d1bab9
fix: update RELEASE-NOTES to clarify separation of Unity Message and …
jeffreylanters Jul 21, 2025
5f39e10
fix: bump version to 10.1.4 in package.json
jeffreylanters Jul 21, 2025
3ba6e8c
fix: update ReactUnityEventParameter type to 'any' for broader compat…
jeffreylanters Jul 21, 2025
cf89222
fix: update sendMessage parameter type to UnityMessageParameter for c…
jeffreylanters Jul 21, 2025
0f4a15b
fix: update dispatchReactUnityEvent parameter type to UnityEventParam…
jeffreylanters Jul 21, 2025
ed18026
Added vite build script
jeffreylanters Jul 29, 2025
14f7d76
fix: hide cleanup canvas element to prevent display issues
jeffreylanters Jul 30, 2025
afc9ba3
fix: update version to 10.1.5 in package.json and package-lock.json
jeffreylanters Jul 30, 2025
275a08b
fix: update release notes to reflect changes in cleanup canvas visibi…
jeffreylanters Jul 30, 2025
f5cb29b
fix: update typescript version to 5.9.3 in package.json and package-l…
jeffreylanters Oct 14, 2025
35599ca
fix: update version to 10.1.6 in package.json and package-lock.json
jeffreylanters Oct 14, 2025
19c8da3
fix: update release notes to reflect TypeScript version and package u…
jeffreylanters Oct 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
registry-url: https://registry.npmjs.org
# Cache Node Module Dependencies
- name: Cache Node Module Dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: "module/node_modules"
key: nodemodules-${{ runner.os }}-${{ hashFiles('module/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
registry-url: https://registry.npmjs.org
# Cache Node Module Dependencies
- name: Cache Node Module Dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: "documentation/node_modules"
key: nodemodules-${{ runner.os }}-${{ hashFiles('documentation/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
registry-url: https://registry.npmjs.org
# Cache Node Module Dependencies
- name: Cache Node Module Dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: "module/node_modules"
key: nodemodules-${{ runner.os }}-${{ hashFiles('module/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Add support for workerUrl (multithreading) [#575][#571]
- Updated TypeScript compiler version and bumped packages.
4 changes: 2 additions & 2 deletions documentation/docs/api/event-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ function removeEventListener(
```tsx title="Type Definition"
function dispatchReactUnityEvent(
eventName: string,
...parameters: ReactUnityEventParameterType[]
...parameters: UnityEventParameter[]
): void;
```

```tsx title="Type Definition"
type ReactUnityEventParameter = string | number | undefined;
type UnityEventParameter = any | undefined | void;
```

## Implementation
Expand Down
71 changes: 71 additions & 0 deletions documentation/docs/api/get-metrics-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Getting Metrics Info

The `getMetricsInfo` function is used to retrieve information about the Unity Application's metrics, such as memory usage and frame rate. This can be useful for debugging and performance analysis.

:::tip
Use the built-in [Unity Metrics Info hook](/docs/api/use-unity-metrics-info) for a more convenient way to access metrics information in your React components.
:::

## Type Definition

```tsx title="Type Definition"
function getMetricsInfo(): UnityMetricsInfo | undefined;
```

## Implementation

:::info
The getMetricsInfo function is only available in Unity Builds created with Unity 6000.1 or later.
:::

Web builds can get quite large, and it can be useful to know how much memory is being used by the Unity Application. The `getMetricsInfo` function provides a way to retrieve this information. It returns an object containing various metrics, such as memory usage, frame rate, and more.

To get started, destructure the getMetricsInfo function from the Unity Context.

```jsx showLineNumbers title="Example: Destructuring the unload function"
const { getMetricsInfo } = useUnityContext();
```

Next you'll be able to invoke the `getMetricsInfo` function to retrieve the metrics information. The function returns an object of type `UnityMetricsInfo`, which contains various properties related to the Unity Application's performance.

```jsx showLineNumbers title="Example: Using the get metrics info function"
async function handleClick() {
const metricsInfo = getMetricsInfo();
}

return <button onClick={handleClick}>Check metrics</button>;
```

## Example Usage

A basic implementation could look something like this. In the following example we'll display a button which allows us to check the current frames per second (FPS) of the Unity Application. When the button is clicked, it will log the FPS to the console.

```jsx showLineNumbers title="App.jsx"
import React, { Fragment } from "react";
import { Unity, useUnityContext } from "react-unity-webgl";

function App() {
const { unityProvider, getMetricsInfo } = useUnityContext({
loaderUrl: "build/myunityapp.loader.js",
dataUrl: "build/myunityapp.data",
frameworkUrl: "build/myunityapp.framework.js",
codeUrl: "build/myunityapp.wasm",
});

function handleClickCheckFps() {
const metricsInfo = getMetricsInfo();
if (metricsInfo) {
console.log("FPS:", metricsInfo.fps);
} else {
console.warn("Metrics info is not available.");
}
}

return (
<Fragment>
<Unity unityProvider={unityProvider} />
<button onClick={handleClickCheckFps}>Check FPS</button>
</Fragment>
);
}
```
6 changes: 3 additions & 3 deletions documentation/docs/api/send-message.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ The send message function lets you asynchronously invoke a method in the Unity g
function sendMessage(
gameObjectName: string,
methodName: string,
parameter?: ReactUnityEventParameterType
parameter?: UnityMessageParameter
): void;
```

```tsx title="Type Definition"
type ReactUnityEventParameter = string | number | undefined;
type UnityMessageParameter = string | number | undefined | void;
```

## Implementation
Expand All @@ -32,7 +32,7 @@ When invoking a C-Sharp method by sending a message, the name of the mono behavi
:::

:::warning
Make sure the parameter matches the actual existence and type of the C-Sharp method you're trying to invoke. Not
Make sure the parameter matches the actual existence and type of the C-Sharp method you're trying to invoke. Not
doing so may cause unintended behaviour or even a crash of the Unity Application.
:::

Expand Down
21 changes: 8 additions & 13 deletions documentation/docs/api/unload.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Requests the Unity Application to be unloaded from memory in order to be unmounted from the DOM.

:::warning
Since React Unity WebGL version 10, calling the unload function is no longer required to unmount the Unity Application. The Unity Application will automatically be unmounted when the component is removed from the DOM. However, if you want to unload the Unity Application manually, you can still use the unload function. But be aware that this is not necessary in most cases.
:::

## Type Definition

```tsx title="Type Definition"
Expand All @@ -14,14 +18,6 @@ function unload(): Promise<void> | undefined;
The unload function is only available in Unity Builds created with Unity 2020.1 or later.
:::

:::danger
In earlier versions of Unity, it was possible to unmount the Unity Application and its containing component immediately after invoking the unload function. However, due to a bug in newer Unity versions, this is no longer feasible when using builds made with Unity 2021.2 or later. While it is still possible to unload the Unity Application, the canvas must remain mounted until the associated promise is resolved.

As of this writing, the issue has not been resolved. However, it is possible to manually unmount the Unity Application by halting navigation to the next page. A ticket has been submitted, and the Unity team has acknowledged this as a known issue. For more details, refer to the [GitHub issue](https://github.com/jeffreylanters/react-unity-webgl/issues/250).

Alternatively, you can use the unsafe `detachAndUnloadImmediate` function to immediately unmount the Unity Application. However, this is not recommended unless you are an advanced user. For more information, refer to the [Unsafe Detach and Unload Immediate](/docs/api/unsafe-detach-unmount-immediate) documentation.
:::

When building a multi-page React Application, it is important to unload the Unity Application in order to completely unmount the component from the DOM to free up the memory taken by the Unity JavaScript heap, and without Unity throwing an error. Invoking the function will request the Unity Application to be unloaded from memory. The function will return a Promise that will be resolved when the Unity Application has been unloaded.

To get started, destructure the unload function from the Unity Context.
Expand All @@ -32,7 +28,7 @@ const { unload } = useUnityContext();

Next you'll be able to invoke the awaitable unload function to unload the Unity Application.

```jsx showLineNumbers title="Example: Using the take screenshot function"
```jsx showLineNumbers title="Example: Using the unload function"
async function handleClick() {
await unload();
}
Expand All @@ -42,7 +38,7 @@ return <button onClick={handleClick}>Unload</button>;

## Example Usage

A basic implementation could look something like this. In the following example we'll display a button which allows the user to navigate to another page, but before this happens, the Unity Application will be unloaded.
A basic implementation could look something like this. In the following example we'll display a button which allows the user to stop the Unity Application. When the button is clicked, it will invoke the unload function to unload the Unity Application from memory.

```jsx showLineNumbers title="App.jsx"
import React, { Fragment } from "react";
Expand All @@ -56,15 +52,14 @@ function App() {
codeUrl: "build/myunityapp.wasm",
});

async function handleClickBack() {
async function handleClickStop() {
await unload();
// Ready to navigate to another page.
}

return (
<Fragment>
<Unity unityProvider={unityProvider} />
<button onClick={handleClickBack}>Back</button>
<button onClick={handleClickStop}>Stop</button>
</Fragment>
);
}
Expand Down
73 changes: 73 additions & 0 deletions documentation/docs/api/use-unity-metrics-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Using Metrics Info

The `useUnityMetricsInfo` hook is a part of the `react-unity-webgl` library that allows you to access metrics information from your Unity application. This can be particularly useful for monitoring performance and resource usage in your Unity WebGL builds.

## Type Definition

```tsx title="Type Definition"
function useUnityMetricsInfo(
getMetricsInfo: () => UnityMetricsInfo | undefined,
metricsConfig: MetricsConfig
): UnityMetricsInfo;
```

## Implementation

:::info
The getMetricsInfo function is only available in Unity Builds created with Unity 6000.1 or later.
:::

Web builds can get quite large, and it can be useful to know how much memory is being used by the Unity Application. The `getMetricsInfo` function provides a way to retrieve this information. It returns an object containing various metrics, such as memory usage, frame rate, and more.

The `useUnityMetricsInfo` hook is a custom React hook that allows you to easily access the metrics information from your Unity application. It takes the `getMetricsInfo` function as an argument and returns the metrics data.

To get started, destructure the getMetricsInfo function from the Unity Context.

```jsx showLineNumbers title="Example: Destructuring the unload function"
const { getMetricsInfo } = useUnityContext();
```

Next you'll create a new hook that uses the `getMetricsInfo` function to retrieve the metrics information. This hook can be used to access the metrics data throughout your application.

```tsx showLineNumbers title="Example: Using the useUnityMetricsInfo hook"
const metricsInfo = useUnityMetricsInfo(getMetricsInfo);
```

:::tip
You can provide additional configuration options through the `metricsConfig` parameter, such as setting the interval for metrics updates.
:::

Finally, you can use the `metricsInfo` object to access the metrics data. This object will contain properties such as `fps`, `pageLoadTime`, and others, depending on what metrics are available in your Unity build.

```tsx showLineNumbers title="Example: Accessing metrics data"
<p>FPS: {metricsInfo.fps}</p>
```

## Example Usage

A basic implementation could look something like this. In the following example we'll display the FPS (frames per second) of the Unity application.

```jsx showLineNumbers title="App.jsx"
import React, { Fragment } from "react";
import { Unity, useUnityContext, useUnityMetricsInfo } from "react-unity-webgl";

function App() {
const { unityProvider, getMetricsInfo } = useUnityContext({
loaderUrl: "build/myunityapp.loader.js",
dataUrl: "build/myunityapp.data",
frameworkUrl: "build/myunityapp.framework.js",
codeUrl: "build/myunityapp.wasm",
});

const { fps } = useUnityMetricsInfo(getMetricsInfo, {
interval: 1000 / 60,
});

return (
<Fragment>
<Unity unityProvider={unityProvider} />
<p>FPS: {fps}</p>
</Fragment>
);
}
```
4 changes: 2 additions & 2 deletions documentation/docs/introduction.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Introduction

Welcome to the React Unity WebGL documentation! My name is [Jeffrey Lanters](https://twitter.com/jeffreylanters), and I'm here to help you bring your awesome games to the web! Everything you'll need to know from get started to creating complex interactive systems can be found in this documentation. If you'll need help, feel free to open a new [discussion](https://github.com/jeffreylanters/react-unity-webgl/discussions), when you want to contribute or think you've found a problem, feel free to open a new [issue](https://github.com/jeffreylanters/react-unity-webgl/issues). And if you like what you see, please consider [starring this repository](https://github.com/jeffreylanters/react-unity-webgl/stargazers) or by [suporting the project](https://react-unity-webgl.dev/support)!
Welcome to the React Unity WebGL documentation! My name is [Jeffrey Lanters](https://jeffreylanters.me), and I'm here to help you bring your awesome games to the web! Everything you'll need to know from get started to creating complex interactive systems can be found in this documentation. If you'll need help, feel free to open a new [discussion](https://github.com/jeffreylanters/react-unity-webgl/discussions), when you want to contribute or think you've found a problem, feel free to open a new [issue](https://github.com/jeffreylanters/react-unity-webgl/issues). And if you like what you see, please consider [starring this repository](https://github.com/jeffreylanters/react-unity-webgl/stargazers) or by [suporting the project](https://react-unity-webgl.dev/support)!

If you're stuck or need professional assistance and are looking for personal help over a video call, feel free to reach out to me on [Twitter](https://twitter.com/jeffreylanters) or send me an email to [support@jeffreylanters.me](mailto:support@jeffreylanters.me).
If you're stuck or need professional assistance and are looking for personal help over a video call, feel free to reach out to me on [GitHub](https://github.com/jeffreylanters) or send me an email to [support@jeffreylanters.me](mailto:support@jeffreylanters.me).

Happy coding! 🚀
7 changes: 7 additions & 0 deletions documentation/docs/upgrading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Upgrading from version 9

Version 10 is fully compatible with version 9, so you can upgrade without any issues. Version 10 introduces new features and improvements, but it does not break any existing functionality. However, there is one change you should be aware of:

The long-standing unloading issue Unity introduced in Unity 2021.2 has been resolved in React Unity WebGL version 10. This means that you no longer need to call the [unload](/docs/api/unload) function to unmount the Unity Application when using React Unity WebGL version 10.

Happy coding!
24 changes: 20 additions & 4 deletions documentation/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ const config = {
lastVersion: "current",
versions: {
current: {
label: "Current version",
label: "Version 10 (Current)",
banner: "none",
badge: true,
path: "",
},
"9.x.x": {
label: "Version 9 (Maintenance LTS)",
banner: "unmaintained",
badge: true,
path: "9.x.x",
},
"8.x.x": {
label: "Version 8 (Active LTS)",
label: "Version 8 (Maintenance LTS)",
banner: "unmaintained",
badge: true,
path: "8.x.x",
Expand Down Expand Up @@ -81,8 +87,8 @@ const config = {
announcementBar: {
id: "support_me",
content:
'The project is in financial need of support, if you use my module and are able, please considing <a href="/support">supporting</a> in any way you can. Thank you! ❤️',
backgroundColor: "#AB2329",
"Donations are helping me to keep this project maintained, if you find this project useful, please consider <a href='/support'>supporting</a> it. Thank you! ❤️",
backgroundColor: "#238babff",
textColor: "#ffffff",
isCloseable: false,
},
Expand All @@ -109,11 +115,21 @@ const config = {
position: "left",
label: "Made With",
},
{
to: "/tutorials",
position: "left",
label: "Tutorials",
},
{
to: "/support",
position: "left",
label: "Support",
},
{
to: "https://template.react-unity-webgl.dev",
position: "right",
label: "Demo",
},
{
type: "docsVersionDropdown",
position: "right",
Expand Down
Loading