File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 自定义SDK调用
2
+ 微信SDK提供了` WX.CallJSFunction ` 与` WX.CallJSFunctionWithReturn ` 接口实现了简单的第三方SDK调用,支持可序列化为JSON的** 任意数量的参数** 与** 返回值** 。
3
+
4
+ 其中,JS侧的实际调用逻辑为` GameGlobal.sdkName.functionName(args) ` ,所以在调用之前需要保证SDK位于` GameGlobal ` 下且SDK中含有该名称的function。
5
+
6
+ 在` WX.CallJSFunctionWithReturn ` 中,会将函数返回值转换为JSON后传回,若无返回值则传回` "" ` 。
7
+
8
+ 如需更加复杂的调用,可参考[ WebGL:与浏览器脚本交互] ( https://docs.unity3d.com/cn/2018.4/Manual/webgl-interactingwithbrowserscripting.html ) 进行自定义定制。
9
+
10
+ ## 版本要求
11
+ ` 转换插件 >= 202406062127 `
12
+
13
+ ## 代码示例
14
+
15
+ 示例中的"sdk"、"testFunction"、TestFunctionOption仅作为演示,实际使用中请自行更改。
16
+
17
+ ``` csharp
18
+ WeChatWASM .WX .CallJSFunction (" sdk" , " testFunction" , new TestFunctionOption
19
+ {
20
+ type = " text" ,
21
+ text = " 反馈" ,
22
+ style = new OptionStyle ()
23
+ {
24
+ left = 10 ,
25
+ top = 10 ,
26
+ width = 100 ,
27
+ height = 100 ,
28
+ backgroundColor = " #ff0000" ,
29
+ color = " #ffffff" ,
30
+ textAlign = " center" ,
31
+ fontSize = 20 ,
32
+ borderRadius = 10 ,
33
+ lineHeight = 100 ,
34
+ }
35
+ });
36
+ ```
37
+
38
+ 另外,在js侧代码中合适位置添加以下代码,可配合[ 构建模版能力] ( https://wechat-miniprogram.github.io/minigame-unity-webgl-transform/Design/BuildTemplate.html ) 使用。
39
+
40
+ ``` js
41
+ GameGlobal[" sdk" ] = sdk;
42
+ ```
43
+
44
+
45
+
You can’t perform that action at this time.
0 commit comments