예제 #1
0
        // Callback to be called from Android native side with UnitySendMessage
        private void OnAndroidRatingDialogCallback(string userAction)
        {
            int index = Convert.ToInt16(userAction);

            // Always go through the default callback first.
            DefaultCallback(ConvertToUserAction(index));

            // Destroy the used object
            Instance = null;
            Destroy(gameObject);
        }
예제 #2
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
        }