赞
踩
将unity导出的webgl文件包放至vue项目的public下面
附上代码:
- var unityInstanceV;
- function ReportReady() {//初始化
- window.parent.postMessage({ guid: "", event: "ReportReady" }, "*");
- }
- function TestSend(data)//unity发消息给vue
- {
- window.parent.postMessage(JSON.parse(data), "*");
- }
- /**
- * GameManager:unity中绑定方法的物体
- * receiveMsgFromVue:unity中的方法
- * */
- function sendMsgToUnity(obj) { //vue发消息给unity
- unityInstanceV.SendMessage('GameManager', 'receiveMsgFromVue', JSON.stringify(obj))
- }
this.$refs.unityIframe.contentWindow.sendMsgToUnity(data);
- mounted() {
- window.addEventListener("message", this.getUnityData); //监听unity给vue发消息
- }
-
-
- getUnityData(e){
- if (e.data.eventName == "初始化" || e.data.eventName == "请求数据") {
- //通过eventName判断事件名称
- }
- },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。