示例#1
0
        /// <summary>
        /// Shows an alert dialog with 2 buttons.
        /// </summary>
        /// <returns>The two buttons alert.</returns>
        /// <param name="title">Title.</param>
        /// <param name="message">Message.</param>
        /// <param name="button1">Button1.</param>
        /// <param name="button2">Button2.</param>
        internal static MobileNativeAlert ShowTwoButtonAlert(string title, string message, string button1, string button2)
        {
            #if UNITY_EDITOR
            Debug.Log("Show 2-button alert with message: " + message);
            return(null);
            #elif UNITY_IOS
            if (Instance != null)
            {
                return(null);    // only allow one alert at a time
            }
            // Create a Unity game object to receive messages from native side
            Instance = new GameObject(ALERT_GAMEOBJECT).AddComponent <MobileNativeAlert>();

            // Show iOS 2-button alert
            iOSNativeAlert.ShowTwoButtonsAlert(title, message, button1, button2);

            return(Instance);
            #elif UNITY_ANDROID
            if (Instance != null)
            {
                return(null); // only allow one alert at a time
            }
            // Create a Unity game object to receive messages from native side
            Instance = new GameObject(ALERT_GAMEOBJECT).AddComponent <MobileNativeAlert>();

            // Show Android 2-button alert
            AndroidNativeAlert.ShowTwoButtonsAlert(title, message, button1, button2);

            return(Instance);
            #else
            Debug.Log("Native alert is not supported on this platform.");
            return(null);
            #endif
        }
        /// <summary>
        /// Shows an alert dialog with 2 buttons.
        /// </summary>
        /// <returns>The two buttons alert.</returns>
        /// <param name="title">Title.</param>
        /// <param name="message">Message.</param>
        /// <param name="button1">Button1.</param>
        /// <param name="button2">Button2.</param>
        internal static MobileNativeAlert ShowTwoButtonAlert(string title, string message, string button1, string button2)
        {
            #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
            if (Instance != null)
            {
                return(null);    // only allow one alert at a time
            }
            // Create a Unity game object to receive messages from native side
            Instance = new GameObject(ALERT_GAMEOBJECT).AddComponent <MobileNativeAlert>();

            // Show the native platform-specific alert
            #if UNITY_IOS
            iOSNativeAlert.ShowTwoButtonsAlert(title, message, button1, button2);
            #elif UNITY_ANDROID
            AndroidNativeAlert.ShowTwoButtonsAlert(title, message, button1, button2);
            #endif

            return(Instance);
            #else
            // Platform not supported
            if (Debug.isDebugBuild)
            {
                Debug.Log("Show 2-button alert with message: " + message);
            }

            return(null);
            #endif
        }
        // Alert callback to be called from native side with UnitySendMessage
        private void OnNativeAlertCallback(string buttonIndex)
        {
            int bIndex = Convert.ToInt16(buttonIndex);

            // Fire event
            OnComplete(bIndex);

            // Destroy the used object
            Instance = null;
            Destroy(gameObject);
        }
示例#4
0
        // Alert callback to be called from native side with UnitySendMessage
        private void OnNativeAlertCallback(string buttonIndex)
        {
            // Release the singleton instance so a new alert can be created.
            Instance = null;

            // Fire event
            OnComplete(Convert.ToInt16(buttonIndex));

            // Destroy the used object
            Destroy(gameObject);
        }
示例#5
0
        private static void DoRequestRating(RatingDialogContent content, Action <UserAction> callback)
        {
            if (!CanRequestRating())
            {
                Debug.Log("Could not display the rating request popup because it was disabled, " +
                          "or one or more display constraints are not satisfied.");
                return;
            }

            // If no custom content was provided, use the default one.
            if (content == null)
            {
                content = EM_Settings.RatingRequest.DefaultRatingDialogContent;
            }

            // Callback register
            customBehaviour = callback;

            #if UNITY_EDITOR
            Debug.Log("Request review is only available on iOS and Android devices.");
            #elif UNITY_IOS
            if (iOSNativeUtility.CanUseBuiltinRequestReview())
            {
                // iOS 10.3+.
                iOSNativeUtility.RequestReview();
            }
            else
            {
                // iOS before 10.3.
                MobileNativeAlert alert = MobileNativeAlert.ShowThreeButtonAlert(
                    content.Title.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName),
                    content.Message.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName),
                    content.RefuseButtonText,
                    content.PostponeButtonText,
                    content.RateButtonText
                    );

                if (alert != null)
                {
                    alert.OnComplete += OnIosRatingDialogCallback;
                }
            }

            if (!IsDisplayConstraintIgnored())
            {
                // Increment the number of requests used this year.
                SetAnnualUsedRequests(DateTime.Now.Year, GetAnnualUsedRequests(DateTime.Now.Year) + 1);

                // Store the request timestamp
                Helper.StoreTime(LAST_REQUEST_TIMESTAMP_PPKEY, DateTime.Now);
            }
            #elif UNITY_ANDROID
            if (Instance != null)
            {
                return;    // only allow one alert at a time
            }
            // Create a Unity game object to receive messages from native side
            Instance = new GameObject(RATING_DIALOG_GAMEOBJECT).AddComponent <MobileNativeRatingRequest>();

            // Replace placeholder texts if any.
            var texts = new RatingDialogContent(
                content.Title.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName),
                content.Message.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName),
                content.LowRatingMessage.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName),
                content.HighRatingMessage.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName),
                content.PostponeButtonText,
                content.RefuseButtonText,
                content.RateButtonText,
                content.CancelButtonText,
                content.FeedbackButtonText
                );

            // Show the Android rating request
            AndroidNativeUtility.RequestRating(texts, EM_Settings.RatingRequest);

            if (!IsDisplayConstraintIgnored())
            {
                // Increment the number of requests used this year.
                SetAnnualUsedRequests(DateTime.Now.Year, GetAnnualUsedRequests(DateTime.Now.Year) + 1);

                // Store the request timestamp
                Helper.StoreTime(LAST_REQUEST_TIMESTAMP_PPKEY, DateTime.Now);
            }
            #else
            Debug.Log("Request review is not supported on this platform.");
            #endif
        }
示例#6
0
 /// <summary>
 /// Shows a toast message (Android only).
 /// </summary>
 /// <param name="message">Message.</param>
 /// <param name="isLongToast">If set to <c>true</c> use long-length toast, otherwise use short-length toast.</param>
 public static void ShowToast(string message, bool isLongToast = false)
 {
     MobileNativeAlert.ShowToast(message, isLongToast);
 }
示例#7
0
 /// <summary>
 /// Shows a one-button alert with the default "OK" button.
 /// </summary>
 /// <returns>The alert.</returns>
 /// <param name="title">Title.</param>
 /// <param name="message">Message.</param>
 public static MobileNativeAlert Alert(string title, string message)
 {
     return(MobileNativeAlert.Alert(title, message));
 }
示例#8
0
 /// <summary>
 /// Shows a one-button alert with a custom button label.
 /// </summary>
 /// <returns>The one button alert.</returns>
 /// <param name="title">Title.</param>
 /// <param name="message">Message.</param>
 /// <param name="button">Button.</param>
 public static MobileNativeAlert Alert(string title, string message, string button)
 {
     return(MobileNativeAlert.ShowOneButtonAlert(title, message, button));
 }
示例#9
0
 /// <summary>
 /// Shows an alert with 2 buttons.
 /// </summary>
 /// <returns>The two buttons alert.</returns>
 /// <param name="title">Title.</param>
 /// <param name="message">Message.</param>
 /// <param name="button1">Button1.</param>
 /// <param name="button2">Button2.</param>
 public static MobileNativeAlert ShowTwoButtonAlert(string title, string message, string button1, string button2)
 {
     return(MobileNativeAlert.ShowTwoButtonAlert(title, message, button1, button2));
 }
 /// <summary>
 /// Shows a toast message (Android only).
 /// </summary>
 /// <param name="message">Message.</param>
 public static void ShowToast(string message)
 {
     MobileNativeAlert.ShowToast(message);
 }