From 389cdfdeca615f325efb9b279931f4b28c72cfb8 Mon Sep 17 00:00:00 2001 From: hollislu Date: Mon, 29 Apr 2024 14:41:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B8=B8=E6=88=8F=E5=9C=88=E5=92=8C?= =?UTF-8?q?=E6=84=8F=E8=A7=81=E5=8F=8D=E9=A6=88=E8=B4=B4=E5=90=88Unity?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameRecorder/GameRecorder/GameRecorder.cs | 10 +- .../SystemButton/SystemButton.cs | 143 ++++++++++-------- .../SystemButton/SystemButtonSO.asset | 4 +- .../API/OpenInterface/UserInfo/UserInfo.cs | 42 ++--- .../Assets/Scripts/DetailsController.cs | 7 +- 5 files changed, 112 insertions(+), 94 deletions(-) diff --git a/Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs b/Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs index 048eca02a..f6e189e50 100644 --- a/Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs +++ b/Demo/API_V2/Assets/API/GameRecorder/GameRecorder/GameRecorder.cs @@ -24,6 +24,7 @@ void Start() { Debug.Log("GameRecorder start"); }); + _gameRecorder.On("pause", (res) => { Debug.Log("GameRecorder pause"); @@ -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); @@ -53,7 +54,7 @@ protected override void TestAPI(string[] args) { _gameRecorder.Start(new GameRecorderStartOption() { - hookBgm = false, + // hookBgm = false, }); } @@ -68,7 +69,7 @@ private void ResumeRecorder() { _gameRecorder.Resume(); } - + // 停止 private void StopRecorder() { @@ -99,8 +100,9 @@ public void OffEvent() _gameRecorder.Off("resume"); } - private void OnDestroy() + public void Destroy() { + OffEvent(); _gameRecorder.Stop(); } } \ No newline at end of file diff --git a/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs b/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs index debfd1c8b..08325cffe 100644 --- a/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs +++ b/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButton.cs @@ -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; @@ -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() { @@ -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) { @@ -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; } // 调起小游戏系统订阅消息界面 @@ -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)); } }); @@ -161,7 +166,7 @@ private void OpenCustomerServiceChat() corpId = "123", }); } - + private void FeedbackButtonOnTap() { @@ -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; } diff --git a/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButtonSO.asset b/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButtonSO.asset index a1a418d8d..581be2e14 100644 --- a/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButtonSO.asset +++ b/Demo/API_V2/Assets/API/OpenInterface/SystemButton/SystemButtonSO.asset @@ -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: [] diff --git a/Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs b/Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs index 139d3f0e5..680b2900b 100644 --- a/Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs +++ b/Demo/API_V2/Assets/API/OpenInterface/UserInfo/UserInfo.cs @@ -9,7 +9,8 @@ public class UserInfo : Details { private WXUserInfoButton _button; - private readonly Action _onTap = (res) => { + private readonly Action _onTap = (res) => + { var result = "onTap\n" + JsonMapper.ToJson(res); GameManager.Instance.detailsController.AddResult(new ResultData() { @@ -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(); } } diff --git a/Demo/API_V2/Assets/Scripts/DetailsController.cs b/Demo/API_V2/Assets/Scripts/DetailsController.cs index 407c24e3d..659ebbc06 100644 --- a/Demo/API_V2/Assets/Scripts/DetailsController.cs +++ b/Demo/API_V2/Assets/Scripts/DetailsController.cs @@ -111,7 +111,6 @@ public void getGapBlock(GameObject parentGameObject) public void Init(EntrySO so) { ClearDetails(); - entrySO = so; titleText.text = so.entryName; @@ -190,10 +189,10 @@ public void BindExtraButtonAction(int index, UnityAction action) .AddButtonListener(action); } - // 获取初始按钮左上角距离画布左上角的相对距离 - public Vector2 GetInitialButtonPosition() + // 获取按钮左上角距离画布左上角的相对距离 + public Vector2 GetButtonPosition(int index) { - var button = initialButton; + var button = (index == -1) ? initialButton : extraButtonBlockObjects[index].GetComponentInChildren