Skip to content

Fix/apiv2 #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
```



Loading