vuenity
Version:
A Vue.js wrapper with communications for WebGL Unity games.
73 lines (54 loc) • 1.6 kB
Markdown
A Vue.js wrapper component for Unity WebGL player based on [react-unity-webgl](https://www.npmjs.com/package/react-unity-webgl), with in and out communications.
Supports typescript;
`npm install --save vuenity`
```html
<template>
<vuenity :unity-content="unityContent"></vuenity>
<p>{{ message }}</p>
</template>
<script>
import Vuenity from "vuenity";
export default {
components: { Vuenity },
data() {
return {
unityContent: new UnityContent(
"Build/your_unity_project.json",
"Build/UnityLoader.js"
),
message: undefined
};
},
mounted() {
this.unityContent.on("NiceWords", message => {
this.message = message;
});
this.unityContent.message("HelloWorld", "Some nice words");
}
};
</script>
```
`Build` folder should be in your `public` folder.
In your Unity project, under `Assets/Plugins/WebGL/` (or anywhere else in assets) create a `VuePlugin.jslib` with:
```js
mergeInto(LibraryManager.library,
NiceWords: function(message) {
VueUnityWebGL.NiceWords(message);
}
});
```
And finally, in one of your `C
```cs
using UnityEngine;
using System.Runtime.InteropServices;
public class GameController : MonoBehaviour {
[]
private static extern void NiceWords(string message);
public void NiceWords (string message) {
NiceWords(message);
}
}
```