Skip to content

Commit f693c58

Browse files
Added disabled canvas events api to documentation
1 parent 76ed5a2 commit f693c58

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Disabled Canvas Events
2+
3+
Overwrites the default disabled canvas events.
4+
5+
## Type Definition
6+
7+
```tsx title="Type Definition"
8+
<Unity disabledCanvasEvents={string[]} />
9+
```
10+
11+
## Implementation
12+
13+
> By default Unity disables the `contextmenu` and `dragstart` events on the canvas element. This is done to prevent the user from right clicking on the canvas and dragging the page while interacting with the Unity Application. Note that by setting the `disabledCanvasEvents` property you'll override the default values. If you don't want this to happen, you'll need to add events these to the array.
14+
15+
## Example Usage​
16+
17+
A basic implementation could look something like this. In the following example overwrite the default values and disable the `dragstart` and `scroll` events. This will also allow the user to right click on the canvas to open the context menu.
18+
19+
```jsx {10-21} showLineNumbers title="App.jsx"
20+
import React from "react";
21+
import { Unity, useUnityContext } from "react-unity-webgl";
22+
23+
function App() {
24+
const { unityProvider } = useUnityContext({
25+
loaderUrl: "build/myunityapp.loader.js",
26+
dataUrl: "build/myunityapp.data",
27+
frameworkUrl: "build/myunityapp.framework.js",
28+
codeUrl: "build/myunityapp.wasm",
29+
});
30+
31+
return (
32+
<Unity
33+
unityProvider={unityProvider}
34+
disabledCanvasEvents={["dragstart", "scroll"]}
35+
/>
36+
);
37+
}
38+
```

documentation/sidebars.json

+4
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@
169169
"type": "doc",
170170
"id": "api/webgl-rendering-context"
171171
},
172+
{
173+
"type": "doc",
174+
"id": "api/disabled-canvas-events"
175+
},
172176
{
173177
"type": "doc",
174178
"id": "api/meta-data"

0 commit comments

Comments
 (0)