Skip to content

Commit 9410d4d

Browse files
authored
refactor(types): Refactor some type definitions for better organization (#44)
* refactor(types): Refactor some type definitions for better organization - Move UnityArguments, UnityInstance, and UnityConfig types to separate files - Update import paths in global.d.ts and other files - Add new type files to package.json * docs: Update documentation - Add `workerUrl` configuration option for Unity web worker files - Add `autoSyncPersistentDataPath` option to enable/disable persistent data path synchronization - Add `disabledCanvasEvents` option to overwrite default disabled canvas events - Add `cacheControl` option for cache control API
1 parent 031e647 commit 9410d4d

File tree

11 files changed

+386
-288
lines changed

11 files changed

+386
-288
lines changed

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,25 @@ unityContext.render(canvas: HTMLCanvasElement | string)
118118

119119
Initializes the Unity application's configuration items.
120120

121-
| Property | Type | Description | Required |
122-
| ------------------------ | ------- | -------------------------------------------------------------------------------------------------- | -------- |
123-
| `loaderUrl` | string | Unity resource loader file ||
124-
| `dataUrl` | string | File containing resource data and scenes ||
125-
| `frameworkUrl` | string | File with runtime and plugin code ||
126-
| `codeUrl` | string | WebAssembly binary file with native code ||
127-
| `streamingAssetsUrl` | string | URL for streaming resources | Optional |
128-
| `memoryUrl` | string | URL for generated framework files | Optional |
129-
| `symbolsUrl` | string | URL for generated Unity code files | Optional |
130-
| `companyName` | string | Metadata: Company name | Optional |
131-
| `productName` | string | Metadata: Product name | Optional |
132-
| `productVersion` | string | Metadata: Product version | Optional |
133-
| `devicePixelRatio` | number | Canvas device pixel ratio. @see[devicePixelRatio][devicePixelRatio-url] | Optional |
134-
| `matchWebGLToCanvasSize` | boolean | Disable automatic WebGL canvas size sync. @see[matchWebGLToCanvasSize][matchWebGLToCanvasSize-url] | Optional |
135-
| `webglContextAttributes` | object | WebGL rendering context options. @see[WebGLRenderingContext][webglContextAttributes-url] | Optional |
121+
| Property | Type | Description | Required |
122+
| ---------------------------- | ----------------- | -------------------------------------------------------------------------------------------------- | -------- |
123+
| `loaderUrl` | string | Unity resource loader file ||
124+
| `dataUrl` | string | File containing resource data and scenes ||
125+
| `frameworkUrl` | string | File with runtime and plugin code ||
126+
| `codeUrl` | string | WebAssembly binary file with native code ||
127+
| `streamingAssetsUrl` | string | URL for streaming resources | Optional |
128+
| `memoryUrl` | string | URL for generated framework files | Optional |
129+
| `symbolsUrl` | string | URL for generated Unity code files | Optional |
130+
| `workerUrl` | string | URL for generated Unity web worker files | Optional |
131+
| `companyName` | string | Metadata: Company name | Optional |
132+
| `productName` | string | Metadata: Product name | Optional |
133+
| `productVersion` | string | Metadata: Product version | Optional |
134+
| `webglContextAttributes` | object | WebGL rendering context options. @see[WebGLRenderingContext][webglContextAttributes-url] | Optional |
135+
| `devicePixelRatio` | number | Canvas device pixel ratio. @see[devicePixelRatio][devicePixelRatio-url] | Optional |
136+
| `matchWebGLToCanvasSize` | boolean | Disable automatic WebGL canvas size sync. @see[matchWebGLToCanvasSize][matchWebGLToCanvasSize-url] | Optional |
137+
| `autoSyncPersistentDataPath` | boolean | Enables or disables auto synchronization of the persistent data path. | 可选 |
138+
| `disabledCanvasEvents` | string[] | Overwrites the default disabled canvas events. | 可选 |
139+
| `cacheControl` | `(url) => string` | The Cache Control API | 可选 |
136140

137141
[devicePixelRatio-url]: https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
138142
[matchWebGLToCanvasSize-url]: https://issuetracker.unity3d.com/issues/webgl-builds-dont-allow-separate-control-on-canvas-render-buffer-size
@@ -217,7 +221,7 @@ unityContext.off('progress', listener)
217221

218222
**Unity Communication methods :**
219223

220-
#### `addUnityListener(name: string, listener: EventListener, options?: { once?: boolean }): this;`
224+
#### ⭐️ `addUnityListener(name: string, listener: EventListener, options?: { once?: boolean }): this;`
221225

222226
Register a specific listener for Unity to call.
223227

@@ -238,7 +242,7 @@ Remove registered listeners.
238242
unityContext.removeUnityListener('GameStarted', listener)
239243
```
240244

241-
### `window.dispatchUnityEvent(name: string, ...args: any[])`
245+
### ⭐️ `window.dispatchUnityEvent(name: string, ...args: any[])`
242246

243247
The way to dispatch a registered listener on the Unity side. (Calling JS methods in unity)
244248

README.zh_CN.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,25 @@ unityContext.render(canvas: HTMLCanvasElement | string)
118118

119119
初始化 Unity 应用程序的配置项。
120120

121-
| Property | Type | Description | Required |
122-
| ------------------------ | ------- | ------------------------------------------------------------------------------------- | -------- |
123-
| `loaderUrl` | string | Unity 资源加载器文件 ||
124-
| `dataUrl` | string | 包含资源数据和场景的文件 ||
125-
| `frameworkUrl` | string | 包含运行时和插件代码的文件 ||
126-
| `codeUrl` | string | 包含原生代码的 WebAssembly 二进制文件 ||
127-
| `streamingAssetsUrl` | string | 流媒体资源的 URL | 可选 |
128-
| `memoryUrl` | string | 生成的框架文件的 URL | 可选 |
129-
| `symbolsUrl` | string | 生成的 Unity 代码文件的 URL | 可选 |
130-
| `companyName` | string | 元数据:公司名称 | 可选 |
131-
| `productName` | string | 元数据:产品名称 | 可选 |
132-
| `productVersion` | string | 元数据:产品版本 | 可选 |
133-
| `devicePixelRatio` | number | 画布设备像素比率. @see[devicePixelRatio][devicePixelRatio-url] | 可选 |
134-
| `matchWebGLToCanvasSize` | boolean | 禁用 WebGL 画布大小自动同步. @see[matchWebGLToCanvasSize][matchWebGLToCanvasSize-url] | 可选 |
135-
| `webglContextAttributes` | object | WebGL 渲染上下文选项. @see[WebGLRenderingContext][webglContextAttributes-url] | 可选 |
121+
| Property | Type | Description | Required |
122+
| ---------------------------- | ----------------- | --------------------------------------------------------------------------------------- | -------- |
123+
| `loaderUrl` | string | Unity 资源加载器文件 ||
124+
| `dataUrl` | string | 包含资源数据和场景的文件 ||
125+
| `frameworkUrl` | string | 包含运行时和插件代码的文件 ||
126+
| `codeUrl` | string | 包含原生代码的 WebAssembly 二进制文件 ||
127+
| `streamingAssetsUrl` | string | 流媒体资源的 URL | 可选 |
128+
| `memoryUrl` | string | Unity生成的框架文件的 URL | 可选 |
129+
| `symbolsUrl` | string | Unity生成的代码文件 URL | 可选 |
130+
| `workerUrl` | string | Unity生成的web worker文件URL | 可选 |
131+
| `companyName` | string | 元数据 | 可选 |
132+
| `productName` | string | 元数据 | 可选 |
133+
| `productVersion` | string | 元数据 | 可选 |
134+
| `webglContextAttributes` | object | WebGL 渲染上下文选项. @see[WebGLRenderingContext][webglContextAttributes-url] | 可选 |
135+
| `devicePixelRatio` | number | canvas设备像素比率. @see[devicePixelRatio][devicePixelRatio-url] | 可选 |
136+
| `matchWebGLToCanvasSize` | boolean | 禁用 WebGL canvas大小自动同步. @see[matchWebGLToCanvasSize][matchWebGLToCanvasSize-url] | 可选 |
137+
| `autoSyncPersistentDataPath` | boolean | 启用/禁用持久数据自动同步 | 可选 |
138+
| `disabledCanvasEvents` | string[] | 禁用一些默认canvas事件 | 可选 |
139+
| `cacheControl` | `(url) => string` | 缓存控制 API | 可选 |
136140

137141
[devicePixelRatio-url]: https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
138142
[matchWebGLToCanvasSize-url]: https://issuetracker.unity3d.com/issues/webgl-builds-dont-allow-separate-control-on-canvas-render-buffer-size
@@ -144,9 +148,9 @@ unityContext.render(canvas: HTMLCanvasElement | string)
144148

145149
#### ⭐️ `render(canvas: HTMLCanvasElement | string): void;`
146150

147-
在指定画布上渲染 Unity WebGL 实例资源。
151+
在指定canvas上渲染 Unity WebGL 实例资源。
148152

149-
- `canvas` : canvas画布元素
153+
- `canvas` : canvas元素
150154

151155
```javascript
152156
await unityContext.render('#canvas')
@@ -174,11 +178,11 @@ unityContext.sendMessage('GameObject', 'gameStart', { role: 'Tanya' })
174178

175179
#### `requestPointerLock(): void;`
176180

177-
请求锁定 Unity 画布的指针
181+
请求锁定 Unity canvas的指针
178182

179183
#### `takeScreenshot(dataType?: string, quality?: any): string | undefined;`
180184

181-
对 Unity 画布进行屏幕截图并返回包含图像数据的数据 URL。
185+
对 Unity canvas进行屏幕截图并返回包含图像数据的数据 URL。
182186

183187
- `dataType`: 图像数据的类型
184188
- `quality`: 图像的质量
@@ -217,9 +221,9 @@ unityContext.off('progress', listener)
217221

218222
**Unity Communication methods :**
219223

220-
#### `addUnityListener(name: string, listener: EventListener, options?: { once?: boolean }): this;`
224+
#### ⭐️ `addUnityListener(name: string, listener: EventListener, options?: { once?: boolean }): this;`
221225

222-
注册特定监听器供 Unity 端调用。
226+
注册监听器供 Unity 端调用。
223227

224228
```javascript
225229
unityContext.addUnityListener('GameStarted', (level) => {
@@ -232,15 +236,15 @@ window.dispatchUnityEvent('GameStarted', 3)
232236

233237
#### `removeUnityListener(name: string, listener?: EventListener): this;`
234238

235-
移除注册的监听器
239+
移除供Unity端注册的监听器
236240

237241
```javascript
238242
unityContext.removeUnityListener('GameStarted', listener)
239243
```
240244

241-
### `window.dispatchUnityEvent(name: string, ...args: any[])`
245+
### ⭐️ `window.dispatchUnityEvent(name: string, ...args: any[])`
242246

243-
在 Unity 端派发注册的监听器的方式。(在 unity 中调用 JS 的方法)
247+
在 Unity 端触发注册的监听器的方式。(在 unity 中调用 JS 的方法)
244248

245249
```javascript
246250
window.dispatchUnityEvent('GameStarted', 3)

0 commit comments

Comments
 (0)