Skip to content

Commit 8778401

Browse files
authored
Merge pull request #787 from wechat-miniprogram/fix/apiv2
Fix/apiv2
2 parents b4615ae + a1e8478 commit 8778401

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

Demo/API_V2/Assets/API/Render/Render/Render.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ private void Start()
1414
// 测试 API
1515
protected override void TestAPI(string[] args)
1616
{
17-
setPreferredFramesPerSecond();
17+
setFPS();
1818
}
1919

20-
public void setPreferredFramesPerSecond()
20+
public void setFPS()
2121
{
22-
WX.SetPreferredFramesPerSecond(50);
22+
Application.targetFrameRate = 30;
2323
}
2424

2525
public void loadFont()
@@ -30,6 +30,6 @@ public void loadFont()
3030

3131
public void Destroy()
3232
{
33-
WX.SetPreferredFramesPerSecond(60);
33+
Application.targetFrameRate = 60;
3434
}
3535
}

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)