Skip to content

update Menu #978

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 3 commits into from
Mar 27, 2025
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
32 changes: 24 additions & 8 deletions Demo/API_V2/Assets/API/GUI/Menu/Menu.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using LitJson;
using UnityEngine;
using WeChatWASM;

public class Menu : Details
{
private bool isMenuStyleDark = false;
private bool isStatusBarStyleBlack = false;
private void Start()
{
// 绑定额外的按钮操作
Expand All @@ -24,13 +24,16 @@ protected override void TestAPI(string[] args)

public void setMenuStyle()
{
string style = isMenuStyleDark ? "light" : "dark";
string toastMessage = $"设置{(isMenuStyleDark ? "浅色" : "深色")}菜单样式完成";

WX.SetMenuStyle(
new SetMenuStyleOption
{
style = "light",
style = style,
success = (res) =>
{
WX.ShowToast(new ShowToastOption { title = "设置成功" });
WX.ShowToast(new ShowToastOption { title = toastMessage, icon = "none"});
},
fail = (res) =>
{
Expand All @@ -42,6 +45,11 @@ public void setMenuStyle()
}
}
);

isMenuStyleDark = !isMenuStyleDark;
GameManager.Instance.detailsController.ChangeInitialButtonText(
isMenuStyleDark ? "设置菜单栏浅色" : "设置菜单栏深色"
);
}

public void getMenuButtonBoundingClientRect()
Expand All @@ -50,19 +58,22 @@ public void getMenuButtonBoundingClientRect()

// 访问成功,显示结果
WX.ShowModal(
new ShowModalOption() { content = "Access Success, Result: " + JsonMapper.ToJson(res) }
new ShowModalOption() { content = "GetMenuButtonBoundingClientRect Success, Result: " + JsonMapper.ToJson(res) }
);
}

public void setStatusBarStyle()
{
string style = !isStatusBarStyleBlack ? "black" : "white"; // 修改逻辑
string toastMessage = $"设置状态栏{(!isStatusBarStyleBlack ? "深色" : "白色")}样式完成"; // 修改逻辑

WX.SetStatusBarStyle(
new SetStatusBarStyleOption
{
style = "black",
style = style,
success = (res) =>
{
WX.ShowToast(new ShowToastOption { title = "设置成功" });
WX.ShowToast(new ShowToastOption { title = toastMessage, icon = "none"});
},
fail = (res) =>
{
Expand All @@ -74,5 +85,10 @@ public void setStatusBarStyle()
}
}
);

isStatusBarStyleBlack = !isStatusBarStyleBlack;
GameManager.Instance.detailsController.ChangeExtraButtonText(1,
!isStatusBarStyleBlack ? "设置状态栏深色" : "设置状态栏白色" // 修改逻辑
);
}
}
}
14 changes: 8 additions & 6 deletions Demo/API_V2/Assets/API/GUI/Menu/MenuSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ MonoBehaviour:
m_EditorClassIdentifier:
entryScriptTypeName: Menu
entryName: "\u83DC\u5355\u548C\u72B6\u6001\u680F"
entryAPI: 'setMenuStyle
entryAPI: 'SetMenuStyle

getMenuButtonBoundingClientRect
GetMenuButtonBoundingClientRect

setStatusBarStyle
SetStatusBarStyle

'
entryDescription: "\u4F7F\u7528setStatusBarStyle\uFF0C\u9700\u8981\u5728json\u91CC\u6DFB\u52A0showStatusBar"
entryDescription: "\u4F7F\u7528setStatusBarStyle\uFF0C\u9700\u8981\u5728game.json\u91CC\u6DFB\u52A0\n\"showStatusBar\":
true"
optionList: []
initialButtonText: "\u8BBE\u7F6E\u83DC\u5355\u6837\u5F0F"
initialButtonText: "\u8BBE\u7F6E\u83DC\u5355\u6837\u5F0F\u6DF1\u8272"
extraButtonList:
- buttonText: "\u83B7\u53D6\u83DC\u5355\u6309\u94AE\u5E03\u5C40\u4F4D\u7F6E\u4FE1\u606F"
- buttonText: "\u8BBE\u7F6E\u72B6\u6001\u680F\u6837\u5F0F"
- buttonText: "\u8BBE\u7F6E\u72B6\u6001\u680F\u6DF1\u8272"
initialResultList: []
entryOrder: 0
Loading