Skip to content

Commit

Permalink
refactor: Rename create to render (#41)
Browse files Browse the repository at this point in the history
* refactor: Rename create to render

* docs: Update README
  • Loading branch information
Marinerer authored Feb 7, 2025
1 parent 786885f commit 0fadef3
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 88 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
`unity-webgl` provides an easy solution for embedding `Unity WebGL` builds in your web applications, with two-way communication and interaction between your webApp and Unity application with advanced API's.

> 🚨 Reminder
>
>
> `v4.x` has been updated significantly and the API is not compatible with `v3.x` and earlier versions. For upgrades, please refer to [Changelogs](https://github.com/Marinerer/unity-webgl/wiki/Major-changes-in-v4)
Based on [react-unity-webgl](https://github.com/jeffreylanters/react-unity-webgl)
Expand All @@ -22,7 +22,7 @@ Based on [react-unity-webgl](https://github.com/jeffreylanters/react-unity-webgl
- 📦 Easy integration, framework-agnostic
- 📩 Bidirectional communication between WebApp and Unity
- ⏰ Comprehensive event handling mechanism
- 🧲 Built-in Vue components (vue2/3)
- 🧲 Built-in Vue components (`vue2/3`)

## Installation

Expand All @@ -44,7 +44,7 @@ npm install unity-webgl
- [vue3 Demo](https://stackblitz.com/edit/unity-webgl-v4-vue3-demo)

> 🚨 **Important:**
> Communication and interaction with the web application are only possible after the Unity instance is successfully created (when the `mounted` event is triggered).
> Communication and interaction with the web application are only possible after the Unity instance is successfully rendered (when the `mounted` event is triggered).
> Recommended to include a loading progress bar when opening the page.
```javascript
Expand All @@ -60,7 +60,7 @@ const unityContext = new UnityWebgl('#canvas', {
unityContext
.on('progress', (progress) => console.log('Loaded: ', progress))
.on('mounted', () => {
// ⚠️ Unity instance created, ready for communication
// ⚠️ UnityInstance rendered, ready for communication
unityContext.sendMessage('GameObject', 'ReceiveRole', 'Tanya')
})

Expand Down Expand Up @@ -108,7 +108,7 @@ new UnityWebgl(canvas: HTMLCanvasElement | string, config?:UnityConfig)
// or

const unityContext = new UnityWebgl(config: UnityConfig)
unityContext.create(canvas: HTMLCanvasElement | string)
unityContext.render(canvas: HTMLCanvasElement | string)
```

- `canvas` : Render Unity canvas elements or selectors.
Expand All @@ -120,10 +120,10 @@ Initializes the Unity application's configuration items.

| Property | Type | Description | Required |
| ------------------------ | ------- | -------------------------------------------------------------------------------------------------- | -------- |
| `loaderUrl` | string | Unity resource loader file | |
| `dataUrl` | string | File containing resource data and scenes | |
| `frameworkUrl` | string | File with runtime and plugin code | |
| `codeUrl` | string | WebAssembly binary file with native code | |
| `loaderUrl` | string | Unity resource loader file ||
| `dataUrl` | string | File containing resource data and scenes ||
| `frameworkUrl` | string | File with runtime and plugin code ||
| `codeUrl` | string | WebAssembly binary file with native code ||
| `streamingAssetsUrl` | string | URL for streaming resources | Optional |
| `memoryUrl` | string | URL for generated framework files | Optional |
| `symbolsUrl` | string | URL for generated Unity code files | Optional |
Expand All @@ -142,14 +142,14 @@ Initializes the Unity application's configuration items.

**Instance methods :**

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

Create a Unity WebGL instance on the specified canvas.
Renders UnityInstance into target html canvas element.

- `canvas` : canvas element

```javascript
await unityContext.create('#canvas')
await unityContext.render('#canvas')
```

#### ⭐️ `unload(): Promise<void>;`
Expand Down Expand Up @@ -248,15 +248,15 @@ window.dispatchUnityEvent('GameStarted', 3)

### Events

| Event Name | Description |
| --------------- | ---------------------------------------- |
| `beforeMount` | Triggered before Unity instance creation |
| `mounted` | Triggered after Unity instance creation |
| `beforeUnmount` | Triggered before Unity instance unload |
| `unmounted` | Triggered after Unity instance unload |
| `progress` | Unity resource loading progress |
| `error` | Error events |
| `debug` | Debug messages from Unity |
| Event Name | Description |
| --------------- | ------------------------------------------------- |
| `beforeMount` | Before rendering UnityInstance to Canvas Element. |
| `mounted` | After rendering UnityInstance to Canvas Element. |
| `beforeUnmount` | Before UnityInstance unload |
| `unmounted` | After UnityInstance unload |
| `progress` | Unity resource loading progress |
| `error` | Error events |
| `debug` | Debug messages from Unity |

## Unity-JavaScript Communication

Expand Down
35 changes: 16 additions & 19 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
`unity-webgl` 提供了一个简单的解决方案,用于将 `Unity WebGL` 构建嵌入到 Web 应用程序中,同时为 Unity 和 WebApp 应用之间的双向通信和交互提供 API。

> 🚨 提醒
>
>
> `v4.x` 版本进行了较大更新,API 不兼容 `v3.x`及之前版本。升级请参考 [变更信息](https://github.com/Marinerer/unity-webgl/wiki/Major-changes-in-v4)

Based on [react-unity-webgl](https://github.com/jeffreylanters/react-unity-webgl)

## Features
Expand Down Expand Up @@ -45,7 +44,7 @@ https://cdn.jsdelivr.net/npm/unity-webgl/dist/index.min.js
- [vue3 Demo](https://stackblitz.com/edit/unity-webgl-v4-vue3-demo)

> 🚨 提醒:
> 仅在 `Unity` 实例成功创建后(触发 `mounted` 事件时)才能进行 Web 应用程序的通信和交互。
> 仅在 `UnityInstance` 渲染完成后(触发 `mounted` 事件时)才能进行 Web 应用程序的通信和交互。
> 建议在页面打开时添加加载进度条。
```javascript
Expand All @@ -61,7 +60,7 @@ const unityContext = new UnityWebgl('#canvas', {
unityContext
.on('progress', (progress) => console.log('Loaded: ', progress))
.on('mounted', () => {
// ⚠️ unity实例已创建,可与unity侧进行通信
// ⚠️ UnityInstance 已创建,可与unity侧进行通信
unityContext.sendMessage('GameObject', 'ReceiveRole', 'Tanya')
})

Expand Down Expand Up @@ -109,7 +108,7 @@ new UnityWebgl(canvas: HTMLCanvasElement | string, config?:UnityConfig)
// or

const unityContext = new UnityWebgl(config: UnityConfig)
unityContext.create(canvas: HTMLCanvasElement | string)
unityContext.render(canvas: HTMLCanvasElement | string)
```

- `canvas` : 渲染Unity的画布元素或选择器。
Expand All @@ -121,10 +120,10 @@ unityContext.create(canvas: HTMLCanvasElement | string)

| Property | Type | Description | Required |
| ------------------------ | ------- | ------------------------------------------------------------------------------------- | -------- |
| `loaderUrl` | string | Unity 资源加载器文件 | |
| `dataUrl` | string | 包含资源数据和场景的文件 | |
| `frameworkUrl` | string | 包含运行时和插件代码的文件 | |
| `codeUrl` | string | 包含原生代码的 WebAssembly 二进制文件 | |
| `loaderUrl` | string | Unity 资源加载器文件 ||
| `dataUrl` | string | 包含资源数据和场景的文件 ||
| `frameworkUrl` | string | 包含运行时和插件代码的文件 ||
| `codeUrl` | string | 包含原生代码的 WebAssembly 二进制文件 ||
| `streamingAssetsUrl` | string | 流媒体资源的 URL | 可选 |
| `memoryUrl` | string | 生成的框架文件的 URL | 可选 |
| `symbolsUrl` | string | 生成的 Unity 代码文件的 URL | 可选 |
Expand All @@ -143,14 +142,14 @@ unityContext.create(canvas: HTMLCanvasElement | string)

**Instance methods :**

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

在指定画布上创建 Unity WebGL 实例
在指定画布上渲染 Unity WebGL 实例资源

- `canvas` : canvas画布元素

```javascript
await unityContext.create('#canvas')
await unityContext.render('#canvas')
```

#### ⭐️ `unload(): Promise<void>;`
Expand Down Expand Up @@ -253,10 +252,10 @@ Unity 实例从创建到销毁过程中触发的事件。

| event name | description |
| ----------------------------- | ----------------------- |
| `beforeMount(unityContext)` | 创建 Unity 实例之前触发 |
| `mounted(unityContext)` | 创建 Unity 实例后触发 |
| `beforeUnmount(unityContext)` | 卸载 Unity 实例之前触发 |
| `unmounted()` | 卸载 Unity 实例后触发 |
| `beforeMount(unityContext)` | 渲染 Unity 实例资源之前 |
| `mounted(unityContext)` | 渲染 Unity 实例资源之后 |
| `beforeUnmount(unityContext)` | 卸载 Unity 实例资源之前 |
| `unmounted()` | 卸载 Unity 实例资源之后 |
| `progress(val: number)` | unity 资源加载进度更新 |
| `error(err: Event\|string)` | 发生错误 |
| `debug(msg: string)` | 来自 Unity 的调试消息 |
Expand Down Expand Up @@ -332,11 +331,9 @@ public class WebGLPluginJS : MonoBehaviour
- [调试 WebGL 构建并排除故障](https://docs.unity3d.com/cn/2023.2/Manual/webgl-debugging.html)
- [WebGL 性能考虑因素](https://docs.unity3d.com/cn/2023.2/Manual/webgl-performance.html)



## License

MIT License
Apache-2.0 License

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion lib/components/src/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default defineComponent({

onMounted(() => {
if (canvas.value) {
props.unity?.create(canvas.value)
props.unity?.render(canvas.value)
}
})
onBeforeUnmount(() => {
Expand Down
42 changes: 21 additions & 21 deletions lib/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
`unity-webgl` provides an easy solution for embedding `Unity WebGL` builds in your web applications, with two-way communication and interaction between your webApp and Unity application with advanced API's.

> 🚨 Reminder
>
>
> `v4.x` has been updated significantly and the API is not compatible with `v3.x` and earlier versions. For upgrades, please refer to [Changelogs](https://github.com/Marinerer/unity-webgl/wiki/Major-changes-in-v4)
Based on [react-unity-webgl](https://github.com/jeffreylanters/react-unity-webgl)
Expand All @@ -22,7 +22,7 @@ Based on [react-unity-webgl](https://github.com/jeffreylanters/react-unity-webgl
- 📦 Easy integration, framework-agnostic
- 📩 Bidirectional communication between WebApp and Unity
- ⏰ Comprehensive event handling mechanism
- 🧲 Built-in Vue components (vue2/3)
- 🧲 Built-in Vue components (`vue2/3`)

## Installation

Expand All @@ -44,7 +44,7 @@ npm install unity-webgl
- [vue3 Demo](https://stackblitz.com/edit/unity-webgl-v4-vue3-demo)

> 🚨 **Important:**
> Communication and interaction with the web application are only possible after the Unity instance is successfully created (when the `mounted` event is triggered).
> Communication and interaction with the web application are only possible after the Unity instance is successfully rendered (when the `mounted` event is triggered).
> Recommended to include a loading progress bar when opening the page.
```javascript
Expand All @@ -60,7 +60,7 @@ const unityContext = new UnityWebgl('#canvas', {
unityContext
.on('progress', (progress) => console.log('Loaded: ', progress))
.on('mounted', () => {
// ⚠️ Unity instance created, ready for communication
// ⚠️ UnityInstance rendered, ready for communication
unityContext.sendMessage('GameObject', 'ReceiveRole', 'Tanya')
})

Expand Down Expand Up @@ -108,7 +108,7 @@ new UnityWebgl(canvas: HTMLCanvasElement | string, config?:UnityConfig)
// or

const unityContext = new UnityWebgl(config: UnityConfig)
unityContext.create(canvas: HTMLCanvasElement | string)
unityContext.render(canvas: HTMLCanvasElement | string)
```

- `canvas` : Render Unity canvas elements or selectors.
Expand All @@ -120,10 +120,10 @@ Initializes the Unity application's configuration items.

| Property | Type | Description | Required |
| ------------------------ | ------- | -------------------------------------------------------------------------------------------------- | -------- |
| `loaderUrl` | string | Unity resource loader file | |
| `dataUrl` | string | File containing resource data and scenes | |
| `frameworkUrl` | string | File with runtime and plugin code | |
| `codeUrl` | string | WebAssembly binary file with native code | |
| `loaderUrl` | string | Unity resource loader file ||
| `dataUrl` | string | File containing resource data and scenes ||
| `frameworkUrl` | string | File with runtime and plugin code ||
| `codeUrl` | string | WebAssembly binary file with native code ||
| `streamingAssetsUrl` | string | URL for streaming resources | Optional |
| `memoryUrl` | string | URL for generated framework files | Optional |
| `symbolsUrl` | string | URL for generated Unity code files | Optional |
Expand All @@ -142,14 +142,14 @@ Initializes the Unity application's configuration items.

**Instance methods :**

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

Create a Unity WebGL instance on the specified canvas.
Renders UnityInstance into target html canvas element.

- `canvas` : canvas element

```javascript
await unityContext.create('#canvas')
await unityContext.render('#canvas')
```

#### ⭐️ `unload(): Promise<void>;`
Expand Down Expand Up @@ -248,15 +248,15 @@ window.dispatchUnityEvent('GameStarted', 3)

### Events

| Event Name | Description |
| --------------- | ---------------------------------------- |
| `beforeMount` | Triggered before Unity instance creation |
| `mounted` | Triggered after Unity instance creation |
| `beforeUnmount` | Triggered before Unity instance unload |
| `unmounted` | Triggered after Unity instance unload |
| `progress` | Unity resource loading progress |
| `error` | Error events |
| `debug` | Debug messages from Unity |
| Event Name | Description |
| --------------- | ------------------------------------------------- |
| `beforeMount` | Before rendering UnityInstance to Canvas Element. |
| `mounted` | After rendering UnityInstance to Canvas Element. |
| `beforeUnmount` | Before UnityInstance unload |
| `unmounted` | After UnityInstance unload |
| `progress` | Unity resource loading progress |
| `error` | Error events |
| `debug` | Debug messages from Unity |

## Unity-JavaScript Communication

Expand Down
Loading

0 comments on commit 0fadef3

Please sign in to comment.