
Product
A Fresh Look for the Socket Dashboard
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
unity-webgl
Advanced tools
Unity WebGL provides an easy solution for embedding Unity WebGL builds in your webApp or Vue.js project, with two-way communication between your webApp and Unity application with advanced API's.
UnityWebGL.js 提供了一种简单的解决方案,用于在 webApp 或 Vue.js 项目中嵌入 Unity WebGL,并通过API在 webApp 和 Unity 之间进行双向通信。
based on react-unity-webgl
npm install unity-webgl
browser
https://cdn.jsdelivr.net/npm/unity-webgl/dist/UnityWebgl.min.js
in example.html:
<canvas id="canvas" style="width: 100%; height: 100%"></canvas>
<button onclick="onDestroy()">Destroy</button>
<button onclick="onLoad()">Reload</button>
<button onclick="onFullscreen()">Fullscreen</button>
<script>
var Unity = new UnityWebgl.default('#canvas', {
loaderUrl: 'Build/OUT_BIM.loader.js',
dataUrl: "Build/OUT_BIM.data",
frameworkUrl: "Build/OUT_BIM.framework.js",
codeUrl: "Build/OUT_BIM.wasm",
streamingAssetsUrl: "StreamingAssets",
companyName: "DefaultCompany",
productName: "BIM",
productVersion: "0.1",
})
Unity
.on('progress', percent => console.log('Unity progress: ', percent))
.on('loaded', () => console.log('Unity loaded: success.'))
.on('created', () => console.log('Unity Instance: created.'))
.on('destroyed', () => console.log('Unity Instance: Destroyed.'))
function postMessage() {
Unity.send('objectName', 'methodName', {
id: 'B0001',
name: 'Building#1',
location: [150, 75]
})
}
function onDestroy() {
Unity.destroy()
}
function onLoad() {
Unity.create('#canvas')
}
function onFullscreen() {
Unity.setFullscreen(true)
}
</script>
You can also:
var Unity = new UnityWebgl.default({
loaderUrl: 'Build/OUT_BIM.loader.js',
dataUrl: "Build/OUT_BIM.data",
frameworkUrl: "Build/OUT_BIM.framework.js",
codeUrl: "Build/OUT_BIM.wasm",
streamingAssetsUrl: "StreamingAssets",
companyName: "DefaultCompany",
productName: "BIM",
productVersion: "0.1",
})
Unity.create(document.querySelector('#canvas'))
in example.vue
<template>
<Unity :unity="unityContext" width="800px" heighht="600px" />
</template>
<script>
import UnityWebgl, { VueUnity } from 'unity-webgl'
const Unity = new UnityWebgl({
loaderUrl: 'Build/OUT_BIM.loader.js',
dataUrl: "Build/OUT_BIM.data",
frameworkUrl: "Build/OUT_BIM.framework.js",
codeUrl: "Build/OUT_BIM.wasm",
streamingAssetsUrl: "StreamingAssets",
companyName: "DefaultCompany",
productName: "BIM",
productVersion: "0.1",
})
export default {
name: 'Unity',
component: {
Unity: VueUnity
},
data() {
return {
unityContext: Unity
}
}
}
</script>
events:
on(eventName: string, eventListener: function)
once(eventName: string, eventListener: function)
off(eventName: string)
clear()
dispatch(eventName: string)
instance:
create(canvasElement: HTMLCanvasElement | string)
send(objectName: string, methodName: string, params: any)
setFullscreen()
destroy()
progress(value: number)
: loading progress.loaded()
: loading complete.created()
: Unity instance is created.destroyed()
: Quits the Unity Instance and clears it from memory.const Unity = new UnityWebgl.default()
// Register functions
Unity.on('showDialog', (data: any) => {
console.log(data)
$('#dialog').show()
})
// call function.
Unity.dispatch('showDialog', data)
// or
window[Unity.global_name].showDialog(data) // ⚠️ Unity.global_name = __UnityLib__
// call function in unity application
__UnityLib__.showDialog(data)
/**
* Sends a message to the UnityInstance to invoke a public method.
* @param {string} objectName Unity scene name.
* @param {string} methodName public method name.
* @param {any} params an optional method parameter.
*/
Unity.send(objectName, methodName, params)
FAQs
Unity-WebGL provides an easy solution for embedding Unity WebGL builds in your web projects, with two-way communication between your webApp and Unity application with advanced API's.
The npm package unity-webgl receives a total of 913 weekly downloads. As such, unity-webgl popularity was classified as not popular.
We found that unity-webgl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
Industry Insights
Terry O’Daniel, Head of Security at Amplitude, shares insights on building high-impact security teams, aligning with engineering, and why AI gives defenders a fighting chance.
Security News
MCP spec updated with structured tool output, stronger OAuth 2.1 security, resource indicators, and protocol cleanups for safer, more reliable AI workflows.