Skip to content

Commit 147fc2c

Browse files
committed
Create CustomSDK.md
1 parent 781362a commit 147fc2c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Design/CustomSDK.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+

0 commit comments

Comments
 (0)