@@ -33,6 +33,8 @@ void Start()
33
33
txtUserInfo . text = $ "nickName:{ userInfoButonRet . userInfo . nickName } , avartar:{ userInfoButonRet . userInfo . avatarUrl } ";
34
34
} ) ;
35
35
Debug . Log ( "infoButton Created" ) ;
36
+
37
+ this . AddMenuRectMask ( ) ;
36
38
37
39
// fallbackFont作为旧版本微信或者无法获得系统字体文件时的备选CDN URL
38
40
var fallbackFont = Application . streamingAssetsPath + "/Fz.ttf" ;
@@ -46,6 +48,48 @@ void Start()
46
48
} ) ;
47
49
}
48
50
51
+ public void AddMenuRectMask ( ) {
52
+ var systemInfo = WX . GetSystemInfoSync ( ) ;
53
+
54
+ // 获取Canvas组件
55
+ Canvas canvas = GetComponent < Canvas > ( ) ;
56
+
57
+ // 如果没有找到Canvas组件,打印错误并返回
58
+ if ( canvas == null )
59
+ {
60
+ Debug . LogError ( "Canvas component not found." ) ;
61
+ return ;
62
+ }
63
+
64
+ // 获取Canvas的宽度
65
+ float canvasWidth = canvas . GetComponent < RectTransform > ( ) . rect . width ;
66
+
67
+ // 创建一个新的Image对象
68
+ GameObject blackSquare = new GameObject ( "BlackSquare" , typeof ( Image ) ) ;
69
+
70
+ // 设置Image对象的父对象为Canvas
71
+ blackSquare . transform . SetParent ( canvas . transform , false ) ;
72
+
73
+ // 获取Image对象的RectTransform组件
74
+ RectTransform rectTransform = blackSquare . GetComponent < RectTransform > ( ) ;
75
+
76
+ // 获取小游戏系统按钮的位置
77
+ var menuRect = WX . GetMenuButtonBoundingClientRect ( ) ;
78
+
79
+ // 转换成当前场景屏幕比例的高度
80
+ var safeButtom = ( int ) ( menuRect . bottom * 1080f / systemInfo . screenWidth ) ;
81
+
82
+ // 设置RectTransform的属性
83
+ rectTransform . anchorMin = new Vector2 ( 0 , 1 ) ;
84
+ rectTransform . anchorMax = new Vector2 ( 0 , 1 ) ;
85
+ rectTransform . pivot = new Vector2 ( 0 , 1 ) ;
86
+ rectTransform . sizeDelta = new Vector2 ( canvasWidth , safeButtom ) ;
87
+
88
+ // 设置Image组件的颜色为黑色
89
+ Image image = blackSquare . GetComponent < Image > ( ) ;
90
+ image . color = Color . black ;
91
+ }
92
+
49
93
public void OnEnterOptionsClick ( )
50
94
{
51
95
var options = WX . GetEnterOptionsSync ( ) ;
0 commit comments