Skip to content

Commit 317519d

Browse files
authored
Merge pull request #749 from wumeibanfa/feat/demo-test
feat:游戏圈和意见反馈贴合Unity按钮
2 parents b6d8aaf + 389cdfd commit 317519d

File tree

5 files changed

+112
-94
lines changed

5 files changed

+112
-94
lines changed

Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ void Start()
2424
{
2525
Debug.Log("GameRecorder start");
2626
});
27+
2728
_gameRecorder.On("pause", (res) =>
2829
{
2930
Debug.Log("GameRecorder pause");
@@ -41,7 +42,7 @@ void Start()
4142
{
4243
Debug.Log("GameRecorder error:" + JsonUtility.ToJson(res));
4344
});
44-
45+
4546
GameManager.Instance.detailsController.BindExtraButtonAction(0, PauseRecorder);
4647
GameManager.Instance.detailsController.BindExtraButtonAction(1, ResumeRecorder);
4748
GameManager.Instance.detailsController.BindExtraButtonAction(2, StopRecorder);
@@ -53,7 +54,7 @@ protected override void TestAPI(string[] args)
5354
{
5455
_gameRecorder.Start(new GameRecorderStartOption()
5556
{
56-
hookBgm = false,
57+
// hookBgm = false,
5758
});
5859
}
5960

@@ -68,7 +69,7 @@ private void ResumeRecorder()
6869
{
6970
_gameRecorder.Resume();
7071
}
71-
72+
7273
// 停止
7374
private void StopRecorder()
7475
{
@@ -99,8 +100,9 @@ public void OffEvent()
99100
_gameRecorder.Off("resume");
100101
}
101102

102-
private void OnDestroy()
103+
public void Destroy()
103104
{
105+
OffEvent();
104106
_gameRecorder.Stop();
105107
}
106108
}

Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs

+76-67
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using UnityEngine;
34
using WeChatWASM;
4-
5+
using System.Collections;
6+
using System.Threading;
57
public class SystemButton : Details
68
{
79
private WXFeedbackButton _feedbackButton;
@@ -12,8 +14,8 @@ private void Start()
1214
var result = WX.GetLaunchOptionsSync();
1315
Debug.Log(JsonUtility.ToJson(result));
1416

15-
CreateGameClubButton();
16-
CreateFeedbackButton();
17+
StartCoroutine(CreateGameClubButton(1.0f));
18+
StartCoroutine(CreateFeedbackButton(1.0f));
1719

1820
WX.GetSetting(new GetSettingOption()
1921
{
@@ -36,53 +38,54 @@ private void Start()
3638
Debug.Log("GetSetting fail" + JsonUtility.ToJson(res));
3739
}
3840
});
39-
41+
4042
GameManager.Instance.detailsController.BindExtraButtonAction(0, GameClubButtonSwitch);
4143
GameManager.Instance.detailsController.BindExtraButtonAction(1, FeedbackButtonSwitch);
4244
GameManager.Instance.detailsController.BindExtraButtonAction(2, RequestSubscribeSystemMessage);
4345
GameManager.Instance.detailsController.BindExtraButtonAction(3, OpenCustomerServiceChat);
4446
}
45-
46-
private void CreateGameClubButton()
47+
48+
IEnumerator CreateGameClubButton(float delay)
4749
{
48-
var screenWidth = (int)GameManager.Instance.systemInfo.screenWidth;
50+
yield return new WaitForSeconds(delay);
51+
52+
Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
53+
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(0);
54+
var systemInfo = WX.GetSystemInfoSync();
4955
_gameClubButton = WX.CreateGameClubButton(new WXCreateGameClubButtonParam()
5056
{
51-
type = GameClubButtonType.image,
52-
text = "游戏圈",
53-
icon = GameClubButtonIcon.green,
57+
type = GameClubButtonType.text,
5458
style = new GameClubButtonStyle()
5559
{
56-
left = screenWidth - 40 - 10,
57-
top = 260,
58-
width = 40,
59-
height = 40,
60+
left = Math.Abs((int)(position.x / systemInfo.pixelRatio)),
61+
top = Math.Abs((int)(position.y / systemInfo.pixelRatio)),
62+
width = (int)(size.x * systemInfo.screenWidth / 1080f),
63+
height = (int)(size.y * systemInfo.screenWidth / 1080f),
6064
}
6165
});
6266
}
63-
64-
private void CreateFeedbackButton()
67+
68+
IEnumerator CreateFeedbackButton(float delay)
6569
{
70+
yield return new WaitForSeconds(delay);
71+
72+
Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
73+
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(1);
74+
var systemInfo = WX.GetSystemInfoSync();
6675
_feedbackButton = WX.CreateFeedbackButton(new CreateOpenSettingButtonOption()
6776
{
6877
type = "text",
69-
text = "打开意见反馈页面",
78+
text = "",
7079
style = new OptionStyle()
7180
{
72-
left = 10,
73-
top = 260,
74-
width = 200,
75-
height = 40,
76-
lineHeight = 40,
77-
backgroundColor = "#ff0000",
78-
color = "#ffffff",
79-
textAlign = "center",
80-
fontSize = 16,
81-
borderRadius = 4,
81+
left = Math.Abs((int)(position.x / systemInfo.pixelRatio)),
82+
top = Math.Abs((int)(position.y / systemInfo.pixelRatio)),
83+
width = (int)(size.x * systemInfo.screenWidth / 1080f),
84+
height = (int)(size.y * systemInfo.screenWidth / 1080f),
8285
}
8386
});
8487
}
85-
88+
8689
// 进入客服会话
8790
protected override void TestAPI(string[] args)
8891
{
@@ -95,43 +98,43 @@ protected override void TestAPI(string[] args)
9598
}
9699

97100
private bool _isGameClubShow = false;
98-
101+
99102
// 切换游戏圈按钮显示/隐藏
100103
private void GameClubButtonSwitch()
101104
{
102-
if (_isGameClubShow)
103-
{
104-
// 显示游戏圈按钮
105-
_gameClubButton.Show();
106-
GameManager.Instance.detailsController.ChangeExtraButtonText(0, "隐藏游戏圈按钮");
107-
}
108-
else
109-
{
110-
// 隐藏游戏圈按钮
111-
_gameClubButton.Hide();
112-
GameManager.Instance.detailsController.ChangeExtraButtonText(0, "显示游戏圈按钮");
113-
}
114-
_isGameClubShow = !_isGameClubShow;
105+
// if (_isGameClubShow)
106+
// {
107+
// // 显示游戏圈按钮
108+
// _gameClubButton.Show();
109+
// GameManager.Instance.detailsController.ChangeExtraButtonText(0, "隐藏游戏圈按钮");
110+
// }
111+
// else
112+
// {
113+
// // 隐藏游戏圈按钮
114+
// _gameClubButton.Hide();
115+
// GameManager.Instance.detailsController.ChangeExtraButtonText(0, "显示游戏圈按钮");
116+
// }
117+
// _isGameClubShow = !_isGameClubShow;
115118
}
116-
119+
117120
private bool _isFeedbackShow = true;
118-
121+
119122
// 切换意见反馈按钮显示/隐藏
120123
private void FeedbackButtonSwitch()
121124
{
122-
if (_isFeedbackShow)
123-
{
124-
// 隐藏意见反馈按钮
125-
_feedbackButton.Hide();
126-
GameManager.Instance.detailsController.ChangeExtraButtonText(1, "显示意见反馈按钮");
127-
}
128-
else
129-
{
130-
// 显示意见反馈按钮
131-
_feedbackButton.Show();
132-
GameManager.Instance.detailsController.ChangeExtraButtonText(1, "隐藏意见反馈按钮");
133-
}
134-
_isFeedbackShow = !_isFeedbackShow;
125+
// if (_isFeedbackShow)
126+
// {
127+
// // 隐藏意见反馈按钮
128+
// _feedbackButton.Hide();
129+
// GameManager.Instance.detailsController.ChangeExtraButtonText(1, "显示意见反馈按钮");
130+
// }
131+
// else
132+
// {
133+
// // 显示意见反馈按钮
134+
// _feedbackButton.Show();
135+
// GameManager.Instance.detailsController.ChangeExtraButtonText(1, "隐藏意见反馈按钮");
136+
// }
137+
// _isFeedbackShow = !_isFeedbackShow;
135138
}
136139

137140
// 调起小游戏系统订阅消息界面
@@ -140,10 +143,12 @@ private void RequestSubscribeSystemMessage()
140143
WX.RequestSubscribeSystemMessage(new RequestSubscribeSystemMessageOption()
141144
{
142145
msgTypeList = new string[] { "SYS_MSG_TYPE_INTERACTIVE" },
143-
success = (res) => {
146+
success = (res) =>
147+
{
144148
Debug.Log(res);
145149
},
146-
fail = (res) => {
150+
fail = (res) =>
151+
{
147152
Debug.Log(JsonUtility.ToJson(res));
148153
}
149154
});
@@ -161,7 +166,7 @@ private void OpenCustomerServiceChat()
161166
corpId = "123",
162167
});
163168
}
164-
169+
165170

166171
private void FeedbackButtonOnTap()
167172
{
@@ -180,27 +185,31 @@ private void FeedbackButtonChangeText()
180185
{
181186
_feedbackButton.text = "跳转到意见反馈页面";
182187
}
183-
184-
188+
189+
185190
private void GameClubButtonDestroy()
186191
{
187192
Debug.Log("gameclub destroy");
188193
_gameClubButton.Destroy();
189194
}
190-
195+
191196
private void FeedbackButtonDestroy()
192197
{
193198
Debug.Log("feedback destroy");
194199
_feedbackButton.Destroy();
195200
}
196-
201+
197202
public void Destroy()
198203
{
199-
if (_gameClubButton != null) {
204+
if (_gameClubButton != null)
205+
{
206+
_gameClubButton.Hide();
200207
GameClubButtonDestroy();
201208
_gameClubButton = null;
202209
}
203-
if (_feedbackButton != null) {
210+
if (_feedbackButton != null)
211+
{
212+
_feedbackButton.Hide();
204213
FeedbackButtonDestroy();
205214
_feedbackButton = null;
206215
}

Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButtonSO.asset

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ MonoBehaviour:
1919
optionList: []
2020
initialButtonText: "\u8FDB\u5165\u5BA2\u670D\u4F1A\u8BDD"
2121
extraButtonList:
22-
- buttonText: "\u9690\u85CF\u6E38\u620F\u5708\u6309\u94AE"
23-
- buttonText: "\u9690\u85CF\u610F\u89C1\u53CD\u9988\u6309\u94AE"
22+
- buttonText: "\u8FDB\u5165\u6E38\u620F\u5708"
23+
- buttonText: "\u6253\u5F00\u610F\u89C1\u53CD\u9988\u9875\u9762"
2424
- buttonText: "\u8C03\u8D77\u5C0F\u6E38\u620F\u7CFB\u7EDF\u8BA2\u9605\u6D88\u606F\u754C\u9762"
2525
- buttonText: "\u6253\u5F00\u5FAE\u4FE1\u5BA2\u670D"
2626
initialResultList: []

Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs

+25-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class UserInfo : Details
99
{
1010
private WXUserInfoButton _button;
1111

12-
private readonly Action<WXUserInfoResponse> _onTap = (res) => {
12+
private readonly Action<WXUserInfoResponse> _onTap = (res) =>
13+
{
1314
var result = "onTap\n" + JsonMapper.ToJson(res);
1415
GameManager.Instance.detailsController.AddResult(new ResultData()
1516
{
@@ -23,54 +24,61 @@ private void Start()
2324
StartCoroutine(SetTimeout(1.0f));
2425
}
2526

26-
IEnumerator SetTimeout(float delay)
27+
IEnumerator SetTimeout(float delay)
2728
{
2829
yield return new WaitForSeconds(delay);
2930

3031
Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
31-
Vector2 position = GameManager.Instance.detailsController.GetInitialButtonPosition();
32+
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(-1);
3233
Debug.Log(position);
3334
Debug.Log(size);
3435
var systemInfo = WX.GetSystemInfoSync();
3536
var canvasWidth = (int)(systemInfo.screenWidth * systemInfo.pixelRatio);
3637
var canvasHeight = (int)(systemInfo.screenHeight * systemInfo.pixelRatio);
37-
_button = WX.CreateUserInfoButton(Math.Abs((int)position.x),
38-
Math.Abs((int)position.y),
39-
(int)(size.x * canvasWidth / 1080f),
40-
(int)(size.y * canvasWidth / 1080f),
41-
"en",
38+
_button = WX.CreateUserInfoButton(Math.Abs((int)position.x),
39+
Math.Abs((int)position.y),
40+
(int)(size.x * canvasWidth / 1080f),
41+
(int)(size.y * canvasWidth / 1080f),
42+
"en",
4243
true);
4344
_button.OnTap(_onTap);
4445
}
4546

4647

4748
// 测试 API
48-
protected override void TestAPI(string[] args){}
49+
protected override void TestAPI(string[] args) { }
4950

5051
// 微信小游戏示例 demo
51-
public void getUserInfo() {
52-
WX.GetSetting(new GetSettingOption
53-
{
54-
success = (res) => {
52+
public void getUserInfo()
53+
{
54+
WX.GetSetting(new GetSettingOption
55+
{
56+
success = (res) =>
57+
{
5558
Debug.Log("GetSetting\n" + JsonMapper.ToJson(res));
56-
if (res.authSetting["scope.userInfo"]) {
59+
if (res.authSetting["scope.userInfo"])
60+
{
5761
WX.GetUserInfo(new GetUserInfoOption
5862
{
59-
success = (res) => {
63+
success = (res) =>
64+
{
6065
Debug.Log("getuserinfo\n" + JsonMapper.ToJson(res));
6166
}
6267
});
63-
} else {
68+
}
69+
else
70+
{
6471
// 参数依次为 x, y, width, height, lang, withCredentials
6572
WXUserInfoButton button = WX.CreateUserInfoButton(20, 20, 400, 200, "en", true);
6673
button.OnTap(_onTap);
6774
}
6875
}
69-
});
76+
});
7077
}
7178

7279
private void OnDestroy()
7380
{
81+
_button.Hide();
7482
_button.Destroy();
7583
}
7684
}

0 commit comments

Comments
 (0)