@@ -22,6 +22,20 @@ public static class NativeUI
2222 [ DllImport ( "__Internal" ) ] static extern void NativeUI_SetStatusBarStyle ( int style , bool animated ) ;
2323 [ DllImport ( "__Internal" ) ] static extern void NativeUI_ShowDialog ( string title , string message , string [ ] actions , int count , int style , double posX , double posY , DialogSelectionCallback callback ) ;
2424
25+
26+ /// <summary>
27+ /// 获取游戏的iOS视图大小,用于与iOS原生UI进行交互、计算
28+ /// </summary>
29+ public static Vector2 UnityViewSize
30+ {
31+ get
32+ {
33+ double x = 0 , y = 0 ;
34+ NativeUI_GetUnityViewSize ( ref x , ref y ) ;
35+ return new Vector2 ( ( float ) x , ( float ) y ) ;
36+ }
37+ }
38+
2539 public static bool HideHomeIndicator
2640 {
2741 get
@@ -164,7 +178,7 @@ public static void ShowTempMessage(string alertString, int duration = 5)
164178 }
165179
166180
167-
181+
168182 /// <summary>
169183 /// 显示一个对话框,允许用户进行回应
170184 /// </summary>
@@ -174,6 +188,31 @@ public static void ShowTempMessage(string alertString, int duration = 5)
174188 /// <param name="style">对话框样式(UIAlertControllerStyle)</param>
175189 /// <param name="actions">(params数组)对话框选项(action)<para><b>注 - UIAlertActionStyle会影响最终呈现在玩家屏幕上的选项顺序,但不会影响回调中的index顺序</b></para></param>
176190 public static void ShowDialog ( string title , string message , Action < int > callback , UIAlertControllerStyle style , params UIAlertAction [ ] actions )
191+ {
192+ var pos = UnityViewSize ;
193+ pos . x /= 2 ; // 将对话框放置在屏幕底部中间位置
194+ ShowDialog ( title , message , callback , style , pos , actions ) ;
195+ }
196+
197+ public static void ShowAlert ( string title , string message , Action < int > callback , params UIAlertAction [ ] actions )
198+ {
199+ ShowDialog ( title , message , callback , UIAlertControllerStyle . Alert , Vector2 . zero , actions ) ;
200+ }
201+
202+ public static void ShowActionSheet ( string title , string message , Action < int > callback , params UIAlertAction [ ] actions )
203+ {
204+ var pos = UnityViewSize ;
205+ pos . x /= 2 ; // 将对话框放置在屏幕底部中间位置
206+ ShowActionSheet ( title , message , callback , pos , actions ) ;
207+ }
208+
209+
210+ public static void ShowActionSheet ( string title , string message , Action < int > callback , Vector2 pos , params UIAlertAction [ ] actions )
211+ {
212+ ShowDialog ( title , message , callback , UIAlertControllerStyle . ActionSheet , pos , actions ) ;
213+ }
214+
215+ static void ShowDialog ( string title , string message , Action < int > callback , UIAlertControllerStyle style , Vector2 pos , params UIAlertAction [ ] actions )
177216 {
178217 if ( actions == null || actions . Length <= 0 )
179218 return ;
@@ -185,7 +224,7 @@ public static void ShowDialog(string title, string message, Action<int> callback
185224 actionsArray [ i ] = actions [ i ] ;
186225 }
187226
188- NativeUI_ShowDialog ( title , message , actionsArray , actions . Length , ( int ) style , OnDialogSelectionCallback ) ;
227+ NativeUI_ShowDialog ( title , message , actionsArray , actions . Length , ( int ) style , pos . x , pos . y , OnDialogSelectionCallback ) ;
189228 ShowDialogCallback = callback ;
190229 }
191230
0 commit comments