Skip to content

Commit 75a80ee

Browse files
author
uhu
committed
feat: update sdk
1 parent 79a977c commit 75a80ee

File tree

1 file changed

+75
-54
lines changed

1 file changed

+75
-54
lines changed

Design/WX_SDK.md

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,96 @@
1-
# SDK 调用微信API
2-
将 WX-WASM-SDK 这个目录拷贝至unity工程 Assets目录下,在主入口初始化,回调后再执行你的主逻辑
1+
# SDK 调用微信 API
2+
3+
将 WX-WASM-SDK 这个目录拷贝至 unity 工程 Assets 目录下,在主入口初始化,回调后再执行你的主逻辑
4+
35
```
46
WX.InitSDK((int code)=> {
57
// 你的主逻辑
6-
});
7-
```
8+
});
9+
```
810

9-
API可以直接看`WX.cs`这个文件,里面有`详细注释说明`
11+
API 可以直接看`WX.cs`这个文件,里面有`详细注释说明`
12+
13+
本 Unity 的 SDK 的 API 大体与[官网 API 文档](https://developers.weixin.qq.com/minigame/dev/api/)的 JS 版本 API 类似,使用时可以参考之。
14+
如 JS 版的 banner 广告的调用如下:
1015

11-
本Unity的SDK的API大体与[官网](https://developers.weixin.qq.com/minigame/dev/guide/)的JS版本API类似,使用时可以参考之。
12-
如JS版的banner广告的调用如下:
1316
```js
14-
var bannerAd = wx.createBannerAd({
15-
adUnitId: "xxxx",
16-
adIntervals: 30,
17-
style: {
18-
left: 0,
19-
top: 0,
20-
width: 600,
21-
height:200
22-
}
23-
});
24-
bannerAd.onLoad(() => {
25-
bannerAd.show();
26-
});
27-
bannerAd.onError((res)=>{
28-
console.log(res);
29-
});
17+
var bannerAd = wx.createBannerAd({
18+
adUnitId: "xxxx",
19+
adIntervals: 30,
20+
style: {
21+
left: 0,
22+
top: 0,
23+
width: 600,
24+
height: 200,
25+
},
26+
});
27+
bannerAd.onLoad(() => {
28+
bannerAd.show();
29+
});
30+
bannerAd.onError((res) => {
31+
console.log(res);
32+
});
3033
```
31-
而对于Unity版的调用如下:
32-
```csharp
3334

34-
var bannerAd = WX.CreateBannerAd(new WXCreateBannerAdParam()
35-
{
36-
adUnitId = "xxxx",
37-
adIntervals = 30,
38-
style = new Style()
39-
{
40-
left = 0,
41-
top = 0,
42-
width = 600,
43-
height = 200
44-
}
45-
});
46-
47-
bannerAd.OnLoad(()=> {
48-
bannerAd.Show();
49-
});
50-
bannerAd.OnError((WXADErrorResponse res)=>
35+
而对于 Unity 版的调用如下:
36+
37+
```csharp
38+
var bannerAd = WX.CreateBannerAd(new WXCreateBannerAdParam()
39+
{
40+
adUnitId = "xxxx",
41+
adIntervals = 30,
42+
style = new Style()
5143
{
52-
Debug.Log(res.errCode);
53-
});
54-
44+
left = 0,
45+
top = 0,
46+
width = 600,
47+
height = 200
48+
}
49+
});
50+
51+
bannerAd.OnLoad(()=> {
52+
bannerAd.Show();
53+
});
54+
bannerAd.OnError((WXADErrorResponse res)=>
55+
{
56+
Debug.Log(res.errCode);
57+
});
5558
```
56-
大体是将JS版中的`wx`替换为Unity版的`WX`,然后对应方法名首字母由小写改为大写,如`createBannerAd`就变为`CreateBannerAd`
59+
60+
大体是将 JS 版中的`wx`替换为 Unity 版的`WX`,然后对应方法名首字母由小写改为大写,如`createBannerAd`就变为`CreateBannerAd`
61+
62+
## 基础库
63+
64+
- [基础库介绍](https://developers.weixin.qq.com/miniprogram/dev/framework/client-lib/)
65+
- [基础库版本分布](https://developers.weixin.qq.com/miniprogram/dev/framework/client-lib/version.html)
66+
67+
### 在 Unity 中兼容低版本基础库
68+
69+
使用`WX.CanIUse`可以判断当前版本是否支持该 API(仅支持 wx),例如想要判断当前环境`WX.ReportScene`是否可用,可以用`WX.CanIUse("ReportScene")`来判断
5770

5871
## 开发建议
59-
### Demo API示例
60-
使用示例我们会逐渐补充到[Demo](https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/tree/main/Demo), 其中API项目为常见到使用范例,请优先查阅用法。
72+
73+
### Demo API 示例
74+
75+
使用示例我们会逐渐补充到[Demo](https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/tree/main/Demo), 其中 API 项目为常见到使用范例,请优先查阅用法。
6176

6277
### 联调效率
63-
如果开发者有简单的JS代码经验,建议先以JS方式直接修改minigame的JS代码进行调试,完成之后再使用C# SDK修改Unity工程:
64-
1. 只保留game.js前面import部分,其余删除,即不运行游戏逻辑。
78+
79+
如果开发者有简单的 JS 代码经验,建议先以 JS 方式直接修改 minigame 的 JS 代码进行调试,完成之后再使用 C# SDK 修改 Unity 工程:
80+
81+
1. 只保留 game.js 前面 import 部分,其余删除,即不运行游戏逻辑。
6582
2. 增加以下代码:
6683

6784
```js
68-
const gl = GameGlobal.canvas.getContext('webgl')
69-
gl.clear(gl.COLOR_BUFFER_BIT);
85+
const gl = GameGlobal.canvas.getContext("webgl");
86+
gl.clear(gl.COLOR_BUFFER_BIT);
7087
```
71-
3. 使用JS编写需要调试的API
88+
89+
3. 使用 JS 编写需要调试的 API
7290

7391
## 注意事项
92+
7493
1. 广告接口是否需要上线后才能调试
75-
- 是的,需要上线并累计UV>1000才可以开通广告主
94+
95+
- 是的,需要上线并累计 UV>1000 才可以开通广告主
96+

0 commit comments

Comments
 (0)