Skip to content

NK-Studio/unity-mobile-dialog-popup-native

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create Mobile Native Popup Using Unity

Platform

  • iOS
  • Android

Feature

  • Ok, Yes/No, Neutral popup (Single, two, three action)

  • DatePicker, TimePicker

Unity에서 쉽게 액세스

iOS 및 Android의 네이티브 기능을 Unity에서 쉽게 액세스할 수 있도록 하는 Native Popups에 오신 것을 환영합니다! 이 플러그인은 Unity에서 iOS 및 Android의 네이티브 기능을 사용하여 팝업을 표시하는 데 사용됩니다.

    public void OnDialogInfo()
    {
        NativeDialog.OpenDialog("Info popup", "Welcome To Native Popup", "Ok", 
            ()=> {
                Debug.Log("OK Button pressed");
            });
    }

   

    public void OnDatePicker()
    {
        NativeDialog.OpenDatePicker(1992,5,10,
            (DateTime _date) =>
            {
                Debug.Log(_date.ToString());
            },
            (DateTime _date) =>
            {
                Debug.Log(_date.ToString());
            });        
    }

Open source

모든 java 및 objective c 소스를 제공했습니다. 작동 방식, 최적화 또는 기능 추가 방법을 알 수 있습니다.

Android studio

  • Unity call to static function
    AndroidJavaClass javaUnityClass = new AndroidJavaClass("com.pingak9.nativepopup.Bridge");
    javaUnityClass.CallStatic("ShowDialogInfo", title, message, ok);
  • Java show popup
    void ShowDialogInfo(String title, String message, String ok) {

        AlertDialog alertDialog = new AlertDialog.Builder(this).create(); //Read Update
        alertDialog.setTitle(title);
        alertDialog.setMessage(message);

        alertDialog.setButton(ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                UnityPlayer.UnitySendMessage("MobileDialogInfo", "OnOkCallBack", "0");
            }
        });

        alertDialog.show();
    }
  • 라이브러리 JAR 빌드 및 JAR 파일을 Plugins/Android 폴더에 복사

Objective C

  • Unity call to C
    [DllImport("__Internal")]
    private static extern void _TAG_ShowDialogInfo(string title, string message, string ok);
  • Objective C show popup
+(void)ShowDialogInfo: (NSString *) title message: (NSString*) msg okTitle:(NSString*) b1 {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:b1 style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [IOSNativePopUpsManager unregisterAllertView];
        UnitySendMessage("MobileDialogInfo", "OnOkCallBack",  [DataConvertor NSIntToChar:0]);
    }];
    [alertController addAction:okAction];
    
    
    [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alertController animated:YES completion:nil];
    _currentAllert = alertController;
}
  • Objective C 파일을 Plugins/iOS 폴더에 복사

좋은 코딩 되세요!

About

심플 버전

Resources

License