Skip to content

Commit a4496e0

Browse files
committed
Api基础部分demo
1 parent 1be1d5d commit a4496e0

33 files changed

+2895
-194
lines changed

Demo/API_V2/Assets/API/Base/BaseSO.asset

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ MonoBehaviour:
1515
categoryName: "\u57FA\u7840"
1616
categorySprite: {fileID: 0}
1717
entryList:
18+
- {fileID: 11400000, guid: d21307f6da1da4d7bb1322558c508822, type: 2}
1819
- {fileID: 11400000, guid: fc015bc2bdd084428ab1dc7cf5b87fba, type: 2}
20+
- {fileID: 11400000, guid: 29b8eb105fe9d400f9a79bdb140e85c9, type: 2}
21+
- {fileID: 11400000, guid: 3996b93c3d76d47088845abcebf960fb, type: 2}
22+
- {fileID: 11400000, guid: 9d4267fc1b8274349a253ca28e0340d7, type: 2}
23+
- {fileID: 11400000, guid: e535490610e214b1cabe9378cb46ea5a, type: 2}

Demo/API_V2/Assets/API/Base/GetEnterOptionsSync.meta renamed to Demo/API_V2/Assets/API/Base/Error.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using LitJson;
3+
using UnityEngine;
4+
using WeChatWASM;
5+
public class Error : Details
6+
{
7+
8+
private bool _isListening = false;
9+
10+
private readonly Action<OnUnhandledRejectionListenerResult> _onUnhandledRejection = (res) => {
11+
var result = "onUnhandledRejection\n" + JsonMapper.ToJson(res);
12+
GameManager.Instance.detailsController.AddResult(new ResultData()
13+
{
14+
initialContentText = result
15+
});
16+
};
17+
18+
private readonly Action<WeChatWASM.Error> _onError = (res) => {
19+
var result = "onError\n" + JsonMapper.ToJson(res);
20+
GameManager.Instance.detailsController.AddResult(new ResultData()
21+
{
22+
initialContentText = result
23+
});
24+
};
25+
26+
private readonly Action<GeneralCallbackResult> _onAudioInterruptionEnd = (res) => {
27+
var result = "onAudioInterruptionEnd\n" + JsonMapper.ToJson(res);
28+
GameManager.Instance.detailsController.AddResult(new ResultData()
29+
{
30+
initialContentText = result
31+
});
32+
};
33+
34+
private readonly Action<GeneralCallbackResult> _onAudioInterruptionBegin = (res) => {
35+
var result = "onAudioInterruptionBegin\n" + JsonMapper.ToJson(res);
36+
GameManager.Instance.detailsController.AddResult(new ResultData()
37+
{
38+
initialContentText = result
39+
});
40+
};
41+
42+
// 测试 API
43+
protected override void TestAPI(string[] args)
44+
{
45+
if (!_isListening) {
46+
WX.OnUnhandledRejection(_onUnhandledRejection);
47+
WX.OnError(_onError);
48+
WX.OnAudioInterruptionEnd(_onAudioInterruptionEnd);
49+
WX.OnAudioInterruptionBegin(_onAudioInterruptionBegin);
50+
} else {
51+
WX.OffUnhandledRejection(_onUnhandledRejection);
52+
WX.OffError(_onError);
53+
WX.OffAudioInterruptionEnd(_onAudioInterruptionEnd);
54+
WX.OffAudioInterruptionBegin(_onAudioInterruptionBegin);
55+
}
56+
_isListening = !_isListening;
57+
GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听" : "开始监听");
58+
}
59+
}
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: ErrorSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: Error
16+
entryName: "\u5E94\u7528\u7EA7\u4E8B\u6545"
17+
entryAPI: "off/ onUnhandledRejection \uFF5C off/ onError\noff/ onAudioInterruptionEnd
18+
| off/ onAudioInterruptionBegin"
19+
entryDescription: "\u6CA1\u6709\u53EF\u89C1\u6548\u679C\uFF0C\u4EC5\u4F5C\u4E3Ademo"
20+
optionList: []
21+
initialButtonText: "\u5F00\u59CB\u76D1\u542C"
22+
extraButtonList: []
23+
initialResultList: []

Demo/API_V2/Assets/API/Base/Error/ErrorSO.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/Base/Get.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
public class GetInfo : Details
7+
{
8+
private void Start()
9+
{
10+
// 绑定额外的按钮操作
11+
GameManager.Instance.detailsController.BindExtraButtonAction(0, getSystemSetting);
12+
GameManager.Instance.detailsController.BindExtraButtonAction(1, getSystemInfoSync);
13+
GameManager.Instance.detailsController.BindExtraButtonAction(2, getSystemInfoAsync);
14+
GameManager.Instance.detailsController.BindExtraButtonAction(3, getSystemInfo);
15+
GameManager.Instance.detailsController.BindExtraButtonAction(4, getDeviceInfo);
16+
GameManager.Instance.detailsController.BindExtraButtonAction(5, getAppBaseInfo);
17+
GameManager.Instance.detailsController.BindExtraButtonAction(6, getAppAuthorizeSetting);
18+
GameManager.Instance.detailsController.BindExtraButtonAction(7, getLaunchOptionsSync);
19+
GameManager.Instance.detailsController.BindExtraButtonAction(8, getEnterOptionsSync);
20+
}
21+
// 测试 API
22+
protected override void TestAPI(string[] args)
23+
{
24+
getWindowInfo();
25+
}
26+
27+
public void getWindowInfo()
28+
{
29+
var res = WX.GetWindowInfo();
30+
31+
// 访问成功,显示结果
32+
WX.ShowModal(new ShowModalOption()
33+
{
34+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
35+
});
36+
}
37+
38+
public void getSystemSetting()
39+
{
40+
var res = WX.GetSystemSetting();
41+
42+
// 访问成功,显示结果
43+
WX.ShowModal(new ShowModalOption()
44+
{
45+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
46+
});
47+
}
48+
49+
public void getSystemInfoSync()
50+
{
51+
var res = WX.GetSystemInfoSync();
52+
53+
// 访问成功,显示结果
54+
WX.ShowModal(new ShowModalOption()
55+
{
56+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
57+
});
58+
}
59+
60+
public void getSystemInfoAsync() {
61+
WX.GetSystemInfoAsync(new GetSystemInfoAsyncOption
62+
{
63+
success = (res) =>
64+
{
65+
WX.ShowModal(new ShowModalOption()
66+
{
67+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
68+
});
69+
},
70+
fail = (res) =>
71+
{
72+
Debug.Log("fail:" + res.errMsg);
73+
},
74+
complete = (res) =>
75+
{
76+
Debug.Log("complete!");
77+
}
78+
}
79+
);
80+
}
81+
82+
public void getSystemInfo()
83+
{
84+
WX.GetSystemInfo(new GetSystemInfoOption
85+
{
86+
success = (res) =>
87+
{
88+
WX.ShowModal(new ShowModalOption()
89+
{
90+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
91+
});
92+
},
93+
fail = (res) =>
94+
{
95+
Debug.Log("fail:" + res.errMsg);
96+
},
97+
complete = (res) =>
98+
{
99+
Debug.Log("complete!");
100+
}
101+
}
102+
);
103+
}
104+
105+
public void getDeviceInfo()
106+
{
107+
var res = WX.GetDeviceInfo();
108+
109+
// 访问成功,显示结果
110+
WX.ShowModal(new ShowModalOption()
111+
{
112+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
113+
});
114+
}
115+
116+
public void getAppBaseInfo()
117+
{
118+
var res = WX.GetAppBaseInfo();
119+
120+
// 访问成功,显示结果
121+
WX.ShowModal(new ShowModalOption()
122+
{
123+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
124+
});
125+
}
126+
127+
public void getAppAuthorizeSetting()
128+
{
129+
var res = WX.GetAppAuthorizeSetting();
130+
131+
// 访问成功,显示结果
132+
WX.ShowModal(new ShowModalOption()
133+
{
134+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
135+
});
136+
}
137+
138+
public void getEnterOptionsSync()
139+
{
140+
var res = WX.GetEnterOptionsSync();
141+
142+
// 访问成功,显示结果
143+
WX.ShowModal(new ShowModalOption()
144+
{
145+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
146+
});
147+
}
148+
149+
public void getLaunchOptionsSync()
150+
{
151+
var res = WX.GetLaunchOptionsSync();
152+
153+
// 访问成功,显示结果
154+
WX.ShowModal(new ShowModalOption()
155+
{
156+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
157+
});
158+
}
159+
}

Demo/API_V2/Assets/API/Base/Get/GetInfo.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: GetInfoSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: GetInfo
16+
entryName: "\u83B7\u53D6\u7CFB\u7EDF\u548C\u8BBE\u5907\u4FE1\u606F"
17+
entryAPI: "getWindowInfo\uFF5CgetSystemSetting\ngetSystemInfoSync \uFF5CgetSystemInfoAsync\ngetSystemInfo
18+
\uFF5CgetDeviceInfo\ngetAppBaseInfo \uFF5CgetAppAuthorizeSetting\ngetEnterOptionsSync
19+
\uFF5C getLaunchOptionsSync"
20+
entryDescription:
21+
optionList: []
22+
initialButtonText: "\u83B7\u53D6\u7A97\u53E3\u4FE1\u606F"
23+
extraButtonList:
24+
- buttonText: "\u83B7\u53D6\u8BBE\u5907\u8BBE\u7F6E "
25+
- buttonText: "\u83B7\u53D6\u7CFB\u7EDF\u4FE1\u606F-\u540C\u6B65"
26+
- buttonText: "\u83B7\u53D6\u7CFB\u7EDF\u4FE1\u606F-\u5F02\u6B65"
27+
- buttonText: "\u83B7\u53D6\u7CFB\u7EDF\u4FE1\u606F"
28+
- buttonText: "\u83B7\u53D6\u8BBE\u5907\u57FA\u7840\u4FE1\u606F"
29+
- buttonText: "\u83B7\u53D6\u5FAE\u4FE1APP\u57FA\u7840\u4FE1\u606F"
30+
- buttonText: "\u83B7\u53D6\u5FAE\u4FE1APP\u6388\u6743\u8BBE\u7F6E"
31+
- buttonText: "\u83B7\u53D6\u5C0F\u6E38\u620F\u51B7\u542F\u52A8\u65F6\u7684\u53C2\u6570"
32+
- buttonText: "\u83B7\u53D6\u5C0F\u6E38\u620F\u6253\u5F00\u7684\u53C2\u6570"
33+
initialResultList: []

0 commit comments

Comments
 (0)