Skip to content

Commit 5c93f2d

Browse files
committed
设备部分api-demo
1 parent 27d74f6 commit 5c93f2d

27 files changed

+2923
-167
lines changed

Demo/API_V2/Assets/API/Facility/BatteryAndClipboard.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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
public class BatteryAndClipboard : Details
7+
{
8+
9+
private void Start()
10+
{
11+
GameManager.Instance.detailsController.BindExtraButtonAction(0, getBatteryInfo);
12+
GameManager.Instance.detailsController.BindExtraButtonAction(1, getClipboardData);
13+
GameManager.Instance.detailsController.BindExtraButtonAction(2, setClipboardData);
14+
}
15+
16+
// 测试 API
17+
protected override void TestAPI(string[] args)
18+
{
19+
getBatteryInfoSync();
20+
}
21+
22+
public void getBatteryInfoSync() {
23+
var res = WX.GetBatteryInfoSync();
24+
25+
WX.ShowModal(new ShowModalOption()
26+
{
27+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
28+
});
29+
}
30+
31+
public void getBatteryInfo() {
32+
WX.GetBatteryInfo(new GetBatteryInfoOption
33+
{
34+
success = (res) => {
35+
Debug.Log("success" + res);
36+
},
37+
fail = (res) => {
38+
Debug.Log("fail" + res.errMsg);
39+
},
40+
complete = (res) => {
41+
Debug.Log("complete");
42+
}
43+
});
44+
}
45+
46+
public void getClipboardData() {
47+
WX.GetClipboardData(new GetClipboardDataOption
48+
{
49+
success = (res) => {
50+
WX.ShowModal(new ShowModalOption()
51+
{
52+
content = "Access Success, Result: " + JsonMapper.ToJson(res)
53+
});
54+
},
55+
fail = (res) => {
56+
Debug.Log("fail" + res.errMsg);
57+
},
58+
complete = (res) => {
59+
Debug.Log("complete");
60+
}
61+
});
62+
}
63+
64+
public void setClipboardData() {
65+
WX.SetClipboardData(new SetClipboardDataOption
66+
{
67+
data = "123",
68+
success = (res) => {
69+
Debug.Log("success" + res);
70+
},
71+
fail = (res) => {
72+
Debug.Log("fail" + res.errMsg);
73+
},
74+
complete = (res) => {
75+
Debug.Log("complete");
76+
}
77+
});
78+
}
79+
}
80+

Demo/API_V2/Assets/API/Facility/BatteryAndClipboard/BatteryAndClipboard.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: BatteryAndClipboardSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: BatteryAndClipboard
16+
entryName: "\u7535\u91CF\u548C\u526A\u5207\u677F"
17+
entryAPI: "\u7535\u91CF\u548C\u526A\u5207\u677F\u76F8\u5173API"
18+
entryDescription:
19+
optionList: []
20+
initialButtonText: "\u83B7\u53D6\u8BBE\u5907\u7535\u91CF-\u540C\u6B65"
21+
extraButtonList:
22+
- buttonText: "\u83B7\u53D6\u8BBE\u5907\u7535\u91CF-\u5F02\u6B65"
23+
- buttonText: "\u83B7\u53D6\u7CFB\u7EDF\u526A\u8D34\u677F\u7684\u5185\u5BB9"
24+
- buttonText: "\u8BBE\u7F6E\u7CFB\u7EDF\u526A\u8D34\u677F\u7684\u5185\u5BB9"
25+
initialResultList: []

Demo/API_V2/Assets/API/Facility/BatteryAndClipboard/BatteryAndClipboardSO.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/Facility/Beacon.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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
public class Beacon : Details
7+
{
8+
9+
private bool _isListening = false;
10+
11+
private readonly Action<OnBeaconUpdateListenerResult> _onBeaconUpdate = (res) => {
12+
var result = "onBeaconUpdate\n" + JsonMapper.ToJson(res);
13+
GameManager.Instance.detailsController.AddResult(new ResultData()
14+
{
15+
initialContentText = result
16+
});
17+
};
18+
19+
private readonly Action<OnBeaconServiceChangeListenerResult> _onBeaconServiceChange = (res) => {
20+
var result = "onBeaconServiceChange\n" + JsonMapper.ToJson(res);
21+
GameManager.Instance.detailsController.AddResult(new ResultData()
22+
{
23+
initialContentText = result
24+
});
25+
};
26+
27+
private void Start()
28+
{
29+
GameManager.Instance.detailsController.BindExtraButtonAction(0, getBeacons);
30+
}
31+
32+
// 测试 API
33+
protected override void TestAPI(string[] args)
34+
{
35+
if (!_isListening) {
36+
startBeaconDiscovery();
37+
WX.OnBeaconUpdate(_onBeaconUpdate);
38+
WX.OnBeaconServiceChange(_onBeaconServiceChange);
39+
} else {
40+
stopBeaconDiscovery();
41+
WX.OffBeaconUpdate(_onBeaconUpdate);
42+
WX.OffBeaconServiceChange(_onBeaconServiceChange);
43+
}
44+
_isListening = !_isListening;
45+
GameManager.Instance.detailsController.ChangeInitialButtonText(_isListening ? "取消搜索" : "开始搜索");
46+
}
47+
48+
public void startBeaconDiscovery() {
49+
//需要更改uuids才能监测到蓝牙-信标
50+
WX.StartBeaconDiscovery(new StartBeaconDiscoveryOption
51+
{
52+
uuids = new string[] {"xxxxxxxxxx"},
53+
success = (res) => {
54+
Debug.Log(res);
55+
},
56+
fail = (res) => {
57+
Debug.Log("fail" + res.errMsg);
58+
},
59+
complete = (res) => {
60+
Debug.Log("complete");
61+
}
62+
});
63+
}
64+
65+
public void stopBeaconDiscovery() {
66+
WX.StopBeaconDiscovery(new StopBeaconDiscoveryOption
67+
{
68+
success = (res) => {
69+
Debug.Log(res);
70+
},
71+
fail = (res) => {
72+
Debug.Log("fail" + res.errMsg);
73+
},
74+
complete = (res) => {
75+
Debug.Log("complete");
76+
}
77+
});
78+
}
79+
80+
public void getBeacons() {
81+
WX.GetBeacons(new GetBeaconsOption
82+
{
83+
success = (res) => {
84+
Debug.Log(res);
85+
},
86+
fail = (res) => {
87+
Debug.Log("fail" + res.errMsg);
88+
},
89+
complete = (res) => {
90+
Debug.Log("complete");
91+
}
92+
});
93+
}
94+
}
95+

Demo/API_V2/Assets/API/Facility/Beacon/Beacon.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: 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: BeaconSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: Beacon
16+
entryName: "\u84DD\u7259-\u4FE1\u6807"
17+
entryAPI: "\u84DD\u7259-\u4FE1\u6807\u76F8\u5173API"
18+
entryDescription: "\u9700\u8981\u66F4\u6539uuids\u624D\u80FD\u76D1\u6D4B\u5230\u84DD\u7259-\u4FE1\u6807"
19+
optionList: []
20+
initialButtonText: "\u5F00\u59CB\u641C\u7D22"
21+
extraButtonList:
22+
- buttonText: "\u83B7\u53D6\u6240\u6709\u5DF2\u641C\u7D22\u5230\u7684 Beacon \u8BBE\u5907"
23+
initialResultList: []

Demo/API_V2/Assets/API/Facility/Beacon/BeaconSO.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.

0 commit comments

Comments
 (0)