-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #787 from wechat-miniprogram/fix/apiv2
Fix/apiv2
- Loading branch information
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 自定义SDK调用 | ||
微信SDK提供了`WX.CallJSFunction`与`WX.CallJSFunctionWithReturn`接口实现了简单的第三方SDK调用,支持可序列化为JSON的**任意数量的参数**与**返回值**。 | ||
|
||
其中,JS侧的实际调用逻辑为`GameGlobal.sdkName.functionName(args)`,所以在调用之前需要保证SDK位于`GameGlobal`下且SDK中含有该名称的function。 | ||
|
||
在`WX.CallJSFunctionWithReturn`中,会将函数返回值转换为JSON后传回,若无返回值则传回`""`。 | ||
|
||
如需更加复杂的调用,可参考[WebGL:与浏览器脚本交互](https://docs.unity3d.com/cn/2018.4/Manual/webgl-interactingwithbrowserscripting.html)进行自定义定制。 | ||
|
||
## 版本要求 | ||
`转换插件 >= 202406062127` | ||
|
||
## 代码示例 | ||
|
||
示例中的"sdk"、"testFunction"、TestFunctionOption仅作为演示,实际使用中请自行更改。 | ||
|
||
```csharp | ||
WeChatWASM.WX.CallJSFunction("sdk", "testFunction", new TestFunctionOption | ||
{ | ||
type = "text", | ||
text = "反馈", | ||
style = new OptionStyle() | ||
{ | ||
left = 10, | ||
top = 10, | ||
width = 100, | ||
height = 100, | ||
backgroundColor = "#ff0000", | ||
color = "#ffffff", | ||
textAlign = "center", | ||
fontSize = 20, | ||
borderRadius = 10, | ||
lineHeight = 100, | ||
} | ||
}); | ||
``` | ||
|
||
另外,在js侧代码中合适位置添加以下代码,可配合[构建模版能力](https://wechat-miniprogram.github.io/minigame-unity-webgl-transform/Design/BuildTemplate.html)使用。 | ||
|
||
```js | ||
GameGlobal["sdk"] = sdk; | ||
``` | ||
|
||
|
||
|