Skip to content

feat:游戏圈和意见反馈贴合Unity按钮 #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void Start()
{
Debug.Log("GameRecorder start");
});

_gameRecorder.On("pause", (res) =>
{
Debug.Log("GameRecorder pause");
Expand All @@ -41,7 +42,7 @@ void Start()
{
Debug.Log("GameRecorder error:" + JsonUtility.ToJson(res));
});

GameManager.Instance.detailsController.BindExtraButtonAction(0, PauseRecorder);
GameManager.Instance.detailsController.BindExtraButtonAction(1, ResumeRecorder);
GameManager.Instance.detailsController.BindExtraButtonAction(2, StopRecorder);
Expand All @@ -53,7 +54,7 @@ protected override void TestAPI(string[] args)
{
_gameRecorder.Start(new GameRecorderStartOption()
{
hookBgm = false,
// hookBgm = false,
});
}

Expand All @@ -68,7 +69,7 @@ private void ResumeRecorder()
{
_gameRecorder.Resume();
}

// 停止
private void StopRecorder()
{
Expand Down Expand Up @@ -99,8 +100,9 @@ public void OffEvent()
_gameRecorder.Off("resume");
}

private void OnDestroy()
public void Destroy()
{
OffEvent();
_gameRecorder.Stop();
}
}
143 changes: 76 additions & 67 deletions Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEngine;
using WeChatWASM;

using System.Collections;
using System.Threading;
public class SystemButton : Details
{
private WXFeedbackButton _feedbackButton;
Expand All @@ -12,8 +14,8 @@ private void Start()
var result = WX.GetLaunchOptionsSync();
Debug.Log(JsonUtility.ToJson(result));

CreateGameClubButton();
CreateFeedbackButton();
StartCoroutine(CreateGameClubButton(1.0f));
StartCoroutine(CreateFeedbackButton(1.0f));

WX.GetSetting(new GetSettingOption()
{
Expand All @@ -36,53 +38,54 @@ private void Start()
Debug.Log("GetSetting fail" + JsonUtility.ToJson(res));
}
});

GameManager.Instance.detailsController.BindExtraButtonAction(0, GameClubButtonSwitch);
GameManager.Instance.detailsController.BindExtraButtonAction(1, FeedbackButtonSwitch);
GameManager.Instance.detailsController.BindExtraButtonAction(2, RequestSubscribeSystemMessage);
GameManager.Instance.detailsController.BindExtraButtonAction(3, OpenCustomerServiceChat);
}
private void CreateGameClubButton()

IEnumerator CreateGameClubButton(float delay)
{
var screenWidth = (int)GameManager.Instance.systemInfo.screenWidth;
yield return new WaitForSeconds(delay);

Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(0);
var systemInfo = WX.GetSystemInfoSync();
_gameClubButton = WX.CreateGameClubButton(new WXCreateGameClubButtonParam()
{
type = GameClubButtonType.image,
text = "游戏圈",
icon = GameClubButtonIcon.green,
type = GameClubButtonType.text,
style = new GameClubButtonStyle()
{
left = screenWidth - 40 - 10,
top = 260,
width = 40,
height = 40,
left = Math.Abs((int)(position.x / systemInfo.pixelRatio)),
top = Math.Abs((int)(position.y / systemInfo.pixelRatio)),
width = (int)(size.x * systemInfo.screenWidth / 1080f),
height = (int)(size.y * systemInfo.screenWidth / 1080f),
}
});
}
private void CreateFeedbackButton()

IEnumerator CreateFeedbackButton(float delay)
{
yield return new WaitForSeconds(delay);

Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(1);
var systemInfo = WX.GetSystemInfoSync();
_feedbackButton = WX.CreateFeedbackButton(new CreateOpenSettingButtonOption()
{
type = "text",
text = "打开意见反馈页面",
text = "",
style = new OptionStyle()
{
left = 10,
top = 260,
width = 200,
height = 40,
lineHeight = 40,
backgroundColor = "#ff0000",
color = "#ffffff",
textAlign = "center",
fontSize = 16,
borderRadius = 4,
left = Math.Abs((int)(position.x / systemInfo.pixelRatio)),
top = Math.Abs((int)(position.y / systemInfo.pixelRatio)),
width = (int)(size.x * systemInfo.screenWidth / 1080f),
height = (int)(size.y * systemInfo.screenWidth / 1080f),
}
});
}

// 进入客服会话
protected override void TestAPI(string[] args)
{
Expand All @@ -95,43 +98,43 @@ protected override void TestAPI(string[] args)
}

private bool _isGameClubShow = false;

// 切换游戏圈按钮显示/隐藏
private void GameClubButtonSwitch()
{
if (_isGameClubShow)
{
// 显示游戏圈按钮
_gameClubButton.Show();
GameManager.Instance.detailsController.ChangeExtraButtonText(0, "隐藏游戏圈按钮");
}
else
{
// 隐藏游戏圈按钮
_gameClubButton.Hide();
GameManager.Instance.detailsController.ChangeExtraButtonText(0, "显示游戏圈按钮");
}
_isGameClubShow = !_isGameClubShow;
// if (_isGameClubShow)
// {
// // 显示游戏圈按钮
// _gameClubButton.Show();
// GameManager.Instance.detailsController.ChangeExtraButtonText(0, "隐藏游戏圈按钮");
// }
// else
// {
// // 隐藏游戏圈按钮
// _gameClubButton.Hide();
// GameManager.Instance.detailsController.ChangeExtraButtonText(0, "显示游戏圈按钮");
// }
// _isGameClubShow = !_isGameClubShow;
}

private bool _isFeedbackShow = true;

// 切换意见反馈按钮显示/隐藏
private void FeedbackButtonSwitch()
{
if (_isFeedbackShow)
{
// 隐藏意见反馈按钮
_feedbackButton.Hide();
GameManager.Instance.detailsController.ChangeExtraButtonText(1, "显示意见反馈按钮");
}
else
{
// 显示意见反馈按钮
_feedbackButton.Show();
GameManager.Instance.detailsController.ChangeExtraButtonText(1, "隐藏意见反馈按钮");
}
_isFeedbackShow = !_isFeedbackShow;
// if (_isFeedbackShow)
// {
// // 隐藏意见反馈按钮
// _feedbackButton.Hide();
// GameManager.Instance.detailsController.ChangeExtraButtonText(1, "显示意见反馈按钮");
// }
// else
// {
// // 显示意见反馈按钮
// _feedbackButton.Show();
// GameManager.Instance.detailsController.ChangeExtraButtonText(1, "隐藏意见反馈按钮");
// }
// _isFeedbackShow = !_isFeedbackShow;
}

// 调起小游戏系统订阅消息界面
Expand All @@ -140,10 +143,12 @@ private void RequestSubscribeSystemMessage()
WX.RequestSubscribeSystemMessage(new RequestSubscribeSystemMessageOption()
{
msgTypeList = new string[] { "SYS_MSG_TYPE_INTERACTIVE" },
success = (res) => {
success = (res) =>
{
Debug.Log(res);
},
fail = (res) => {
fail = (res) =>
{
Debug.Log(JsonUtility.ToJson(res));
}
});
Expand All @@ -161,7 +166,7 @@ private void OpenCustomerServiceChat()
corpId = "123",
});
}


private void FeedbackButtonOnTap()
{
Expand All @@ -180,27 +185,31 @@ private void FeedbackButtonChangeText()
{
_feedbackButton.text = "跳转到意见反馈页面";
}


private void GameClubButtonDestroy()
{
Debug.Log("gameclub destroy");
_gameClubButton.Destroy();
}

private void FeedbackButtonDestroy()
{
Debug.Log("feedback destroy");
_feedbackButton.Destroy();
}

public void Destroy()
{
if (_gameClubButton != null) {
if (_gameClubButton != null)
{
_gameClubButton.Hide();
GameClubButtonDestroy();
_gameClubButton = null;
}
if (_feedbackButton != null) {
if (_feedbackButton != null)
{
_feedbackButton.Hide();
FeedbackButtonDestroy();
_feedbackButton = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ MonoBehaviour:
optionList: []
initialButtonText: "\u8FDB\u5165\u5BA2\u670D\u4F1A\u8BDD"
extraButtonList:
- buttonText: "\u9690\u85CF\u6E38\u620F\u5708\u6309\u94AE"
- buttonText: "\u9690\u85CF\u610F\u89C1\u53CD\u9988\u6309\u94AE"
- buttonText: "\u8FDB\u5165\u6E38\u620F\u5708"
- buttonText: "\u6253\u5F00\u610F\u89C1\u53CD\u9988\u9875\u9762"
- buttonText: "\u8C03\u8D77\u5C0F\u6E38\u620F\u7CFB\u7EDF\u8BA2\u9605\u6D88\u606F\u754C\u9762"
- buttonText: "\u6253\u5F00\u5FAE\u4FE1\u5BA2\u670D"
initialResultList: []
42 changes: 25 additions & 17 deletions Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class UserInfo : Details
{
private WXUserInfoButton _button;

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

IEnumerator SetTimeout(float delay)
IEnumerator SetTimeout(float delay)
{
yield return new WaitForSeconds(delay);

Vector2 size = GameManager.Instance.detailsController.GetInitialButtonSize();
Vector2 position = GameManager.Instance.detailsController.GetInitialButtonPosition();
Vector2 position = GameManager.Instance.detailsController.GetButtonPosition(-1);
Debug.Log(position);
Debug.Log(size);
var systemInfo = WX.GetSystemInfoSync();
var canvasWidth = (int)(systemInfo.screenWidth * systemInfo.pixelRatio);
var canvasHeight = (int)(systemInfo.screenHeight * systemInfo.pixelRatio);
_button = WX.CreateUserInfoButton(Math.Abs((int)position.x),
Math.Abs((int)position.y),
(int)(size.x * canvasWidth / 1080f),
(int)(size.y * canvasWidth / 1080f),
"en",
_button = WX.CreateUserInfoButton(Math.Abs((int)position.x),
Math.Abs((int)position.y),
(int)(size.x * canvasWidth / 1080f),
(int)(size.y * canvasWidth / 1080f),
"en",
true);
_button.OnTap(_onTap);
}


// 测试 API
protected override void TestAPI(string[] args){}
protected override void TestAPI(string[] args) { }

// 微信小游戏示例 demo
public void getUserInfo() {
WX.GetSetting(new GetSettingOption
{
success = (res) => {
public void getUserInfo()
{
WX.GetSetting(new GetSettingOption
{
success = (res) =>
{
Debug.Log("GetSetting\n" + JsonMapper.ToJson(res));
if (res.authSetting["scope.userInfo"]) {
if (res.authSetting["scope.userInfo"])
{
WX.GetUserInfo(new GetUserInfoOption
{
success = (res) => {
success = (res) =>
{
Debug.Log("getuserinfo\n" + JsonMapper.ToJson(res));
}
});
} else {
}
else
{
// 参数依次为 x, y, width, height, lang, withCredentials
WXUserInfoButton button = WX.CreateUserInfoButton(20, 20, 400, 200, "en", true);
button.OnTap(_onTap);
}
}
});
});
}

private void OnDestroy()
{
_button.Hide();
_button.Destroy();
}
}
Loading
Loading