Skip to content

Commit e89bd18

Browse files
committed
设备api-demo
1 parent 43ecdf9 commit e89bd18

File tree

15 files changed

+263
-0
lines changed

15 files changed

+263
-0
lines changed

Demo/API_V2/Assets/API/Facility/FacilitySO.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ MonoBehaviour:
2121
- {fileID: 11400000, guid: e92d94924be504167a342e42e1162f21, type: 2}
2222
- {fileID: 11400000, guid: 8b80b0ecb1eb545fc9e1d3e78be71c1c, type: 2}
2323
- {fileID: 11400000, guid: 8d65ca57ec29f4e0181f0a9eea07242c, type: 2}
24+
- {fileID: 11400000, guid: c7f9bca80c38c4fe5ac4668ac717aabd, type: 2}
2425
- {fileID: 11400000, guid: 4cf8b37be958f454fb84e1af3578b3ef, type: 2}
2526
- {fileID: 11400000, guid: 4bf09276222714a97880851f19636612, type: 2}

Demo/API_V2/Assets/API/Facility/Other.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: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
public class Other : Details
7+
{
8+
9+
private bool _isListening = false;
10+
11+
private readonly Action<OnMemoryWarningListenerResult> _onMemoryWarning = (res) => {
12+
var result = "onMemoryWarning\n" + JsonMapper.ToJson(res);
13+
GameManager.Instance.detailsController.AddResult(new ResultData()
14+
{
15+
initialContentText = result
16+
});
17+
};
18+
19+
20+
private void Start()
21+
{
22+
GameManager.Instance.detailsController.BindExtraButtonAction(0, scanCode);
23+
GameManager.Instance.detailsController.BindExtraButtonAction(1, vibrateShort);
24+
GameManager.Instance.detailsController.BindExtraButtonAction(2, vibrateLong);
25+
}
26+
27+
// 测试 API
28+
protected override void TestAPI(string[] args)
29+
{
30+
memoryWarning();
31+
}
32+
33+
public void memoryWarning() {
34+
if (!_isListening) {
35+
WX.OnMemoryWarning(_onMemoryWarning);
36+
} else {
37+
WX.OffMemoryWarning(_onMemoryWarning);
38+
}
39+
_isListening = !_isListening;
40+
GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消监听内存告警" : "开始监听内存告警");
41+
}
42+
43+
public void scanCode() {
44+
WX.ScanCode(new ScanCodeOption
45+
{
46+
onlyFromCamera = false,
47+
scanType = new string[] {"barCode", "qrcode"},
48+
success = (res) => {
49+
Debug.Log("success " + JsonMapper.ToJson(res));
50+
},
51+
fail = (res) => {
52+
Debug.Log("fail" + res.errMsg);
53+
},
54+
complete = (res) => {
55+
Debug.Log("complete");
56+
}
57+
});
58+
}
59+
60+
public void vibrateShort() {
61+
WX.VibrateShort(new VibrateShortOption
62+
{
63+
type = "heavy",
64+
success = (res) => {
65+
Debug.Log("success ");
66+
},
67+
fail = (res) => {
68+
Debug.Log("fail" + res.errMsg);
69+
},
70+
complete = (res) => {
71+
Debug.Log("complete");
72+
}
73+
});
74+
}
75+
76+
public void vibrateLong() {
77+
WX.VibrateLong(new VibrateLongOption
78+
{
79+
success = (res) => {
80+
Debug.Log("success ");
81+
},
82+
fail = (res) => {
83+
Debug.Log("fail" + res.errMsg);
84+
},
85+
complete = (res) => {
86+
Debug.Log("complete");
87+
}
88+
});
89+
}
90+
}
91+

Demo/API_V2/Assets/API/Facility/Other/Other.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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: OtherSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: Other
16+
entryName: "\u5176\u5B83"
17+
entryAPI: "\u5185\u5B58\uFF0C\u626B\u7801\u548C\u632F\u52A8\u76F8\u5173API"
18+
entryDescription:
19+
optionList: []
20+
initialButtonText: "\u5F00\u59CB\u76D1\u542C\u5185\u5B58\u544A\u8B66"
21+
extraButtonList:
22+
- buttonText: "\u626B\u7801"
23+
- buttonText: "\u77ED\u632F\u52A8"
24+
- buttonText: "\u957F\u632F\u52A8"
25+
initialResultList: []

Demo/API_V2/Assets/API/Facility/Other/OtherSO.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/Location.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/Location/Location.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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
public class Location : Details
7+
{
8+
// 测试 API
9+
protected override void TestAPI(string[] args)
10+
{
11+
getFuzzyLocation();
12+
}
13+
14+
public void getFuzzyLocation() {
15+
WX.GetFuzzyLocation(new GetFuzzyLocationOption
16+
{
17+
type = "wgs84",
18+
success = (res) =>
19+
{
20+
WX.ShowModal(new ShowModalOption()
21+
{
22+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
23+
});
24+
},
25+
fail = (res) =>
26+
{
27+
Debug.Log("fail:" + res.errMsg);
28+
},
29+
complete = (res) =>
30+
{
31+
Debug.Log("complete!");
32+
}
33+
});
34+
}
35+
}

Demo/API_V2/Assets/API/Location/Location/Location.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.

0 commit comments

Comments
 (0)