
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@web-unity-bridge/core
Advanced tools
@web-unity-bridge/core is a JavaScript library designed to integrate Unity games and experiences seamlessly into web environments. This library provides a structured way to load and interact with Unity instances within a web page, handling script loading,
@web-unity-bridge/core is a JavaScript library designed to integrate Unity games and experiences seamlessly into web environments. This library provides a structured way to load and interact with Unity instances within a web page, handling script loading, canvas rendering, and event management.
This project was inspired by the react-unity-webgl library, which facilitates the integration of Unity with React applications. We have adapted and extended its principles to create a more tailored solution for our specific use cases in web environments.
npm install @web-unity-bridge/core
To use @web-unity-bridge/core, follow these steps:
Create a configuration object for your Unity instance specifying necessary parameters like the path to the Unity build.
const unityConfig = {
loaderUrl: "Build/unity.loader.js",
dataUrl: "Build/unity.data",
frameworkUrl: "Build/unity.framework.js",
codeUrl: "Build/unity.wasm",
};
Instantiate UnityMethod with a target HTML element and the Unity configuration.
import BridgeCore from '@web-unity-bridge/core';
const unityContainer = document.getElementById("unity-div");
const bridgeCore = new BridgeCore(unityContainer, unityConfig);
Add event listeners to handle custom events or loading progress.
bridgeCore.statusAddEventListener("loaded", () => {
console.log("Unity loaded successfully!");
});
bridgeCore.statusAddEventListener("progress", (progress) => {
console.log(`Loading progress: ${progress}%`);
});
Use the provided methods to interact with the Unity instance as needed.
// Example method to start a game
function startGame() {
bridgeCore.unityInstance.SendMessage('GameManager', 'Start');
}
To dispatch events, the module provides a global function called dispatchUnityWebGLEvent
. This function accepts the event name and parameters as arguments, and it will dispatch the event to the appropriate Unity context.
bridgeCore.addEventListener('SetScore', (score) => {
console.log(score)
});
Example: Dispatching an event from a JSLib
mergeInto(LibraryManager.library, {
SetScore: function (score) {
try {
window.dispatchUnityWebGLEvent("SetScore", score);
} catch (e) {
console.warn("Failed to dispatch event");
}
},
});
Contributions are welcome! Feel free to open issues or submit pull requests on our GitHub repository.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
@web-unity-bridge/core is a JavaScript library designed to integrate Unity games and experiences seamlessly into web environments. This library provides a structured way to load and interact with Unity instances within a web page, handling script loading,
The npm package @web-unity-bridge/core receives a total of 147 weekly downloads. As such, @web-unity-bridge/core popularity was classified as not popular.
We found that @web-unity-bridge/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.