WeChat Mini Game JS Interaction Mode:
There is a problem with the WeChat mini-game mechanism. Index.html will not be loaded in the WeChat mini-game, so the functions written in index.html will not be called
1. calljs.js
Add definitions to the self-created file, and the file will be overwritten every time it is compiled
export const CallJS={
test:function(){
console.log("test");
}
}
2. game.js
Introduced in
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调用代码
Mounted GameGlobal
on the object, under line 32
GameGlobal.managerConfig = managerConfig;
GameGlobal.CallJS = CallJS; // 挂载
3. Call case, the mini game side does not need to be implemented, it is defined in the glue layer of Unity
Unity's custom glue layer code will be compiled
webgl.wasm.framework.unityweb.js
into
_Buy
Click the button to call the function through the glue layer in Unity
JS interaction method of WebGL:
1. Use the same import method as in the WeChat mini-game, define GameGlobal
and mount CallJS
the object yourself, and keep the same definition method as in the mini-game. It is called uniformly in the glue layer, and no distinction is made.
Calljs update method suggestion:
It is recommended to use calljs as a template in unity, without modifying index.html and game.js every time. Just replace the calljs.js file.
WebGL template modification WXTemplate
or WXTemplate2020
mini game template modificationWX-WASM-SDK\wechat-default