Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kmturley/angular-unity
Example Angular and Unity integration
https://github.com/kmturley/angular-unity
Last synced: 1 day ago
JSON representation
Example Angular and Unity integration
- Host: GitHub
- URL: https://github.com/kmturley/angular-unity
- Owner: kmturley
- Created: 2018-10-18T20:04:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-31T23:53:44.000Z (over 3 years ago)
- Last Synced: 2024-05-02T00:59:41.796Z (7 months ago)
- Language: C#
- Homepage: https://kimturley.co.uk/angular-unity/dist/index.html
- Size: 108 MB
- Stars: 11
- Watchers: 2
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# angular-unity
Example Angular and Unity integration using:
* Unity 2019.3.14f1
* Angular 12.0.x## Installation
npm install
## Usage
npm start
Then view the site at:
http://localhost:4200/
## Creating a compatible Unity project
To communicate between JavaScript and Unity you need a few things:
1) Create a Unity Project with GameObject > Controller.cs:
```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;public class Controller : MonoBehaviour {
[DllImport("__Internal")]
private static extern void SendMessageToWeb(string msg);public void ReceiveMessageFromWeb(string msg) {
Debug.Log("Controller.ReceiveMessageFromWeb: " + msg);
}// Use this for initialization
void Start() {
SendMessageToWeb("Hello from Unity");
}// Update is called once per frame
void Update() {}
}
```2) Add a file to the Unity project at: /Assets/Plugins/WebInterface.jslib containing:
```
mergeInto(LibraryManager.library, {
SendMessageToWeb: function (str) {
window.receiveMessageFromUnity(str);
},
});
```3) Build the project as WebGL so that it creates the files:
- demo.data.unityweb
- demo.json
- demo.wasm.code.unityweb
- demo.wasm.framework.unityweb4) Copy the generated files to this project folder:
/src/assets
5) Embed your generated files using the reusable Angular component:
## Updating Unity
If you update Unity then you'll also needs to update the Unity JavaScript files to match. Publish a WebGL project and copy the new JavaScript files into the angular src folder here:
./src/assets/UnityLoader.js
./src/assets/UnityProgress.js## Directory structure
src/ --> Frontend sources files
unity-src/ --> Unity script examples## Contact
For more information please contact kmturley