-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add HTML, Vue2, and Vue3 examples for UnityWebgl (#38)
* docs: Update demo links in READMEs * feat: Add HTML, Vue2, and Vue3 examples for UnityWebgl
- Loading branch information
Showing
21 changed files
with
4,766 additions
and
2,365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<html lang="zh-CN"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1" /> | ||
<meta name="renderer" content="webkit" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="format-detection" content="telphone=no" /> | ||
<title><title>unity-webgl demo</title></title> | ||
<meta name="description" content="" /> | ||
<meta name="keywords" content="" /> | ||
</head> | ||
<body> | ||
<div> | ||
<canvas id="canvas" style="width: 800px; height: 600px"></canvas> | ||
|
||
<div> | ||
<button onclick="sendMessage()">postMessage</button> | ||
<button onclick="onFullscreen()">Fullscreen</button> | ||
</div> | ||
</div> | ||
</body> | ||
<script src="main.js" type="module"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import UnityWebgl from 'unity-webgl' | ||
|
||
const unityContext = new UnityWebgl('#canvas', { | ||
loaderUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.loader.js', | ||
dataUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.data', | ||
frameworkUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.framework.js', | ||
codeUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.wasm', | ||
}) | ||
|
||
unityContext | ||
.on('progress', (p) => console.log('loading :', p)) | ||
.on('mounted', () => console.log('unity mounted ...')) | ||
.on('debug', (msg) => console.log('unity debug', msg)) | ||
|
||
unityContext.addUnityListener('gameStart', (msg) => { | ||
alert(msg) | ||
console.log('gameStart : ', msg) | ||
}) | ||
|
||
window.sendMessage = function sendMessage() { | ||
unityContext.sendMessage('GameUI', 'ReceiveRole', 'Tanya') | ||
} | ||
|
||
window.onFullscreen = function () { | ||
unityContext.setFullscreen(true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "html", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite" | ||
}, | ||
"devDependencies": { | ||
"vite": "^6.0.5" | ||
}, | ||
"dependencies": { | ||
"unity-webgl": "workspace:^" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
server: { | ||
port: 3010, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<script> | ||
import UnityWebgl from 'unity-webgl' | ||
import VueUnity from 'unity-webgl/vue' | ||
const unityContext = new UnityWebgl({ | ||
loaderUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.loader.js', | ||
dataUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.data', | ||
frameworkUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.framework.js', | ||
codeUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.wasm', | ||
}); | ||
unityContext | ||
.on('progress', (p) => console.log('loading :', p)) | ||
.on('mounted', () => console.log('unity mounted ...')) | ||
.on('debug', (msg) => console.log('unity debug', msg)); | ||
unityContext.addUnityListener('gameStart', (msg) => { | ||
alert(msg); | ||
console.log('gameStart : ', msg); | ||
}); | ||
export default { | ||
name: 'App', | ||
components: { | ||
VueUnity | ||
}, | ||
data() { | ||
return { | ||
unityContext | ||
} | ||
}, | ||
methods: { | ||
onSendMessage() { | ||
unityContext.sendMessage('GameUI', 'ReceiveRole', 'Tanya') | ||
}, | ||
onFullscreen() { | ||
unityContext.setFullscreen(true) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<VueUnity :unity="unityContext" width="800px" height="600px" tabindex="0" /> | ||
<div> | ||
<button @click="onSendMessage">SendMessage</button> | ||
<button @click="onFullscreen">Fullscreen</button> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!doctype html> | ||
<html lang="zh-CN"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1" /> | ||
<meta name="renderer" content="webkit" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="format-detection" content="telphone=no" /> | ||
<title>unity-webgl vue2 demo</title> | ||
<meta name="description" content="" /> | ||
<meta name="keywords" content="" /> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script src="/main.js" type="module"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Vue from 'vue' | ||
import App from './App.vue' | ||
|
||
new Vue({ | ||
render: (h) => h(App), | ||
}).$mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "vue2", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-legacy": "^6.0.0", | ||
"@vitejs/plugin-vue2": "^2.3.3", | ||
"vite": "^6.0.5" | ||
}, | ||
"dependencies": { | ||
"unity-webgl": "^4.0.1", | ||
"vue": "2.7.16" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'vite' | ||
import legacy from '@vitejs/plugin-legacy' | ||
import vue from '@vitejs/plugin-vue2' | ||
|
||
export default defineConfig({ | ||
plugins: [vue(), legacy()], | ||
server: { | ||
port: 3020, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<script setup> | ||
import { ref, onMounted } from 'vue' | ||
import UnityWebgl from 'unity-webgl' | ||
import VueUnity from 'unity-webgl/vue' | ||
const unityContext = new UnityWebgl({ | ||
loaderUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.loader.js', | ||
dataUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.data', | ||
frameworkUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.framework.js', | ||
codeUrl: | ||
'https://static-huariot-com.oss-cn-hangzhou.aliyuncs.com/uploads/17343457791501843/demo.wasm', | ||
}); | ||
unityContext | ||
.on('progress', (p) => console.log('loading :', p)) | ||
.on('mounted', () => console.log('unity mounted ...')) | ||
.on('debug', (msg) => console.log('unity debug', msg)); | ||
unityContext.addUnityListener('gameStart', (msg) => { | ||
alert(msg); | ||
console.log('gameStart : ', msg); | ||
}); | ||
function onSendMessage() { | ||
unityContext.sendMessage('GameUI', 'ReceiveRole', 'Tanya') | ||
} | ||
function onFullscreen() { | ||
unityContext.setFullscreen(true) | ||
} | ||
</script> | ||
|
||
<template> | ||
<VueUnity :unity="unityContext" width="800px" height="600px" tabindex="0" /> | ||
<div> | ||
<button @click="onSendMessage">SendMessage</button> | ||
<button @click="onFullscreen">Fullscreen</button> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!doctype html> | ||
<html lang="zh-CN"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1" /> | ||
<meta name="renderer" content="webkit" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="format-detection" content="telphone=no" /> | ||
<title>unity-webgl vue3 demo</title> | ||
<meta name="description" content="" /> | ||
<meta name="keywords" content="" /> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
<script src="/main.js" type="module"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Vue from 'vue' | ||
import App from './App.vue' | ||
|
||
new Vue({ | ||
render: (h) => h(App), | ||
}).$mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "vue3", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-vue": "^5.2.1", | ||
"vite": "^6.0.5" | ||
}, | ||
"dependencies": { | ||
"unity-webgl": "workspace:^", | ||
"vue": "3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
plugins: [vue()], | ||
server: { | ||
port: 3021, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.