Helper scripts for Unity WebGL builds to facilitate JavaScript and Unity method calls.
- Easy integration of JavaScript libraries in Unity WebGL builds
- Simple method calls from JavaScript to Unity and vice versa
Clone this repository and integrate the scripts into your Unity project.
- Place the JavaScript files in your project's WebGLTemplates folder.
- Include the C# scripts in your Unity project.
// example.js
function UnityCallExample() {
SendMessage('GameObjectName', 'MethodName', 'Message from JavaScript');
}
// ExampleUnityScript.cs
using UnityEngine;
public class ExampleUnityScript : MonoBehaviour
{
void MethodName(string message)
{
Debug.Log("Message from JavaScript: " + message);
}
}
This repository includes a helper for downloading images in WebGL builds.
The JavaScript library (ImageDownloaderPlugin.jslib
) includes a function to download images
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using sleeplessDev;
public class WebGLImageDownloadExample : MonoBehaviour
{
public DownloadingImage imageDownloader;
void Start()
{
string imageUrl = "https://example.com/path/to/your/image.jpg"; // Replace with the actual URL of the image
string fileName = "downloadedImage.jpg";
imageDownloader = gameObject.AddComponent<DownloadingImage>();
imageDownloader.DownloadImage(imageUrl, fileName);
}
}
This repository includes a plugin to check if the current device is an iOS device. The plugin utilizes JavaScript to perform the check and provides a C# interface for easy usage within Unity.
This repository includes a plugin to find an array of microphones, and alows for local streaming after getting mic permission in unity webGL.
This repository includes custom Unity editor extensions to facilitate the creation and management of JavaScript libraries for WebGL builds.
You can create a new .jslib
file with a template by following these steps:
- In the Unity Editor, right-click in the
Project
window. - Select
Create
>JS Script-Template
.
This will create a new .jslib
file with a basic template to get you started.
Feel free to open issues or submit pull requests.
This project is licensed under the MIT License.