当前位置:网站首页>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
边栏推荐
- C语言数组的深度分析
- Attention based ASR(LAS)
- a:自我介绍
- Cholesterol-PEG-NHS NHS-PEG-CLS cholesterol-polyethylene glycol-active ester can modify small molecular materials
- mobaxterm 编码问题解决
- 企业级 DevOps 究竟是什么?
- About iframe
- Tensorflow相关list
- Fluorescein-PEG-DSPE Phospholipid-Polyethylene Glycol-Fluorescein Fluorescent Phospholipid PEG Derivatives
- 力扣刷题.快乐数
猜你喜欢
随机推荐
链表理论基础
Tensorflow——演示
Pytorch Daily Practice - Predicting Surviving Passengers on the Titanic
Virtual machine view port number process
Wangeditor rich text editor to upload pictures and solve cross-domain problems
多线程截取视频为每帧
Tensorflow边用边踩坑
Pytorch learning notes 09 - multiple classification problem
IDEA概述和安装及调试
力扣.有效的字母异位词
钉钉H5微应用免登鉴权
【Rhapsody学习笔记】4:Relations
Hyperparameter Optimization - Excerpt
Remote file xxx is mapped to the local path xxx and can't be found. You can continue debugging....
IDEA overview and installation and debugging
Embedding cutting-edge understanding
DSPE-PEG-Thiol DSPE-PEG-SH 磷脂-聚乙二醇-巯基脂质体制备用
解决background-size:cover时图片铺满但显示不完整?
2022年SQL大厂高频实战面试题(详细解析)
mobaxterm 编码问题解决









