Skip to content

Commit

Permalink
Merge pull request #787 from wechat-miniprogram/fix/apiv2
Browse files Browse the repository at this point in the history
Fix/apiv2
  • Loading branch information
Oooocean authored Aug 21, 2024
2 parents b4615ae + a1e8478 commit 8778401
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Demo/API_V2/Assets/API/Render/Render/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ private void Start()
// 测试 API
protected override void TestAPI(string[] args)
{
setPreferredFramesPerSecond();
setFPS();
}

public void setPreferredFramesPerSecond()
public void setFPS()
{
WX.SetPreferredFramesPerSecond(50);
Application.targetFrameRate = 30;
}

public void loadFont()
Expand All @@ -30,6 +30,6 @@ public void loadFont()

public void Destroy()
{
WX.SetPreferredFramesPerSecond(60);
Application.targetFrameRate = 60;
}
}
45 changes: 45 additions & 0 deletions Design/CustomSDK.md
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;
```



0 comments on commit 8778401

Please sign in to comment.