-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cs
94 lines (84 loc) · 2.83 KB
/
Menu.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using LitJson;
using UnityEngine;
using WeChatWASM;
public class Menu : Details
{
private bool isMenuStyleDark = false;
private bool isStatusBarStyleBlack = false;
private void Start()
{
// 绑定额外的按钮操作
GameManager.Instance.detailsController.BindExtraButtonAction(
0,
getMenuButtonBoundingClientRect
);
GameManager.Instance.detailsController.BindExtraButtonAction(1, setStatusBarStyle);
}
// 测试 API
protected override void TestAPI(string[] args)
{
setMenuStyle();
}
public void setMenuStyle()
{
string style = isMenuStyleDark ? "light" : "dark";
string toastMessage = $"设置{(isMenuStyleDark ? "浅色" : "深色")}菜单样式完成";
WX.SetMenuStyle(
new SetMenuStyleOption
{
style = style,
success = (res) =>
{
WX.ShowToast(new ShowToastOption { title = toastMessage, icon = "none"});
},
fail = (res) =>
{
Debug.Log("fail:" + res.errMsg);
},
complete = (res) =>
{
Debug.Log("complete!");
}
}
);
isMenuStyleDark = !isMenuStyleDark;
GameManager.Instance.detailsController.ChangeInitialButtonText(
isMenuStyleDark ? "设置菜单栏浅色" : "设置菜单栏深色"
);
}
public void getMenuButtonBoundingClientRect()
{
var res = WX.GetMenuButtonBoundingClientRect();
// 访问成功,显示结果
WX.ShowModal(
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 = style,
success = (res) =>
{
WX.ShowToast(new ShowToastOption { title = toastMessage, icon = "none"});
},
fail = (res) =>
{
Debug.Log("fail:" + res.errMsg);
},
complete = (res) =>
{
Debug.Log("complete!");
}
}
);
isStatusBarStyleBlack = !isStatusBarStyleBlack;
GameManager.Instance.detailsController.ChangeExtraButtonText(1,
!isStatusBarStyleBlack ? "设置状态栏深色" : "设置状态栏白色" // 修改逻辑
);
}
}