当前位置:网站首页>Unity转微信小游戏与JS交互
Unity转微信小游戏与JS交互
2022-07-31 05:18:00 【周末的游戏之旅】
微信小游戏JS交互方式:
微信小游戏机制问题,在微信小游戏中不会加载index.html,所以写在index.html的函数均不会被调用到
1.自行创建calljs.js文件中添加定义,每次编译该文件都会被覆盖
export const CallJS={
test:function(){
console.log("test");
}
}
2.在game.js中引入
import './weapp-adapter'
import unityNamespace from './unity-namespace'
import './webgl.wasm.framework.unityweb'
import "./unity-sdk/index.js"
import checkVersion, {canUseCoverview} from './check-version'
import "texture-config.js";
import {launchEventType} from './plugin-config'
import {CallJS} from './calljs' // 引入自定义JS调用代码
挂载到GameGlobal对象上,第32行下
GameGlobal.managerConfig = managerConfig;
GameGlobal.CallJS = CallJS; // 挂载
3.调用案例,小游戏侧无需实现,在Unity的胶水层定义
Unity自定义的胶水层代码会被编译到
webgl.wasm.framework.unityweb.js中

点击按钮,在Unity中通过胶水层调用_Buy函数

WebGL的JS交互方式:
1.使用和微信小游戏中同样的引入方式,自行定义GameGlobal并挂载CallJS对象,保持和小游戏中相同的定义方式。在胶水层统一调用,不再做区分处理。


calljs更新方式建议:
建议在unity中将calljs做模板处理,不需要每次都修改index.html和game.js。只需要替换calljs.js文件即可。
WebGL模板修改WXTemplate或WXTemplate2020
小游戏模板修改WX-WASM-SDK\wechat-default
边栏推荐
- Research reagents Cholesterol-PEG-Maleimide, CLS-PEG-MAL, Cholesterol-PEG-Maleimide
- PyTorch Study Notes 08 - Loading Datasets
- wangeditor富文本编辑器上传图片以及跨域问题解决
- Tensorflow边用边踩坑
- IDEA控制台不能输入信息的解决方法
- Cholesterol-PEG-Amine CLS-PEG-NH2 Cholesterol-Polyethylene Glycol-Amino Research Use
- Redis-哈希
- MySQL 出现 The table is full 的解决方法
- Three methods of accessing image pixels in opencv
- UR3机器人运动学分析之正运动学分析
猜你喜欢

MW: 3400 4-Arm PEG-DSPE four-arm-polyethylene glycol-phospholipid a saturated 18-carbon phospholipid

【Rhapsody学习笔记】3:Dishwasher

Four common ways of POST to submit data

Phospholipids-Polyethylene Glycol-Active Esters for Scientific Research DSPE-PEG-NHS CAS: 1445723-73-8

DSPE-PEG-Biotin, CAS: 385437-57-0, phospholipid-polyethylene glycol-biotin prolongs circulating half-life

map和set

MySQL free installation download and configuration tutorial

浏览器中的画中画(Picture-in-Picture)API
![[Solved] ssh connection report: Bad owner or permissions on C:\\Users/XXX/.ssh/config](/img/53/8b5a12e7ed551dca52ada5dbb5d6b5.png)
[Solved] ssh connection report: Bad owner or permissions on C:\\Users/XXX/.ssh/config

四种常见的POST提交数据方式
随机推荐
WIN10,配置adb环境
钉钉企业内部-H5微应用开发
IDEA overview and installation and debugging
DingTalk Enterprise Internal-H5 Micro Application Development
DSPE-PEG-Thiol DSPE-PEG-SH 磷脂-聚乙二醇-巯基脂质体制备用
Natural language processing related list
虚拟机查看端口号进程
力扣.有效的字母异位词
TCP与UDP协议的区别,以及TCP的三次握手和四次挥手
box-shadow相关属性
ROS之service编程的学习和理解
Embedding前沿了解
DingTalk H5 micro-app login authentication
拒绝采样小记
Learn how to get a database connection with JDBC
opencv之访问图像像素的三种方法
CAS: 1403744-37-5 DSPE-PEG-FA Phospholipid-Polyethylene Glycol-Folic Acid for Scientific Research
Getting Started with MySQL: The Case Statement Works Well
可下载视频可下载图片的函数
[Solved] ssh connection report: Bad owner or permissions on C:\\Users/XXX/.ssh/config