npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@web-unity-bridge/core

v1.0.9

Published

@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,

Downloads

4

Readme

@web-unity-bridge/core

@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.

Features

  • Script Loading: Dynamically load and manage Unity scripts.
  • Canvas Rendering: Automate the setup of a canvas for - Unity rendering.
  • Event Management: Facilitate adding and removing event listeners.
  • Progress Tracking: Monitor and report loading progression of the Unity instance.

Install

npm install @web-unity-bridge/core

Usage

To use @web-unity-bridge/core, follow these steps:

1. Set Up Configuration

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",
};

2. Initialize UnityMethod

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);

3. Event Handling

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}%`);
});

4. Interacting with Unity

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');
}

5. Communication from Unity to Javascript

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");
    }
  },
});

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests on our GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.