Exemple #1
0
    void Update()
    {
        // Exit on Android Back button
        #if UNITY_ANDROID && EASY_MOBILE
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            MobileNativeAlert alert = MobileNativeUI.ShowTwoButtonAlert(
                "Exit Game",
                "Are you sure you want to exit?",
                "Yes",
                "No");

            if (alert != null)
            {
                alert.OnComplete += (int button) =>
                {
                    switch (button)
                    {
                    case 0:     // Yes
                        Application.Quit();
                        break;

                    case 1:     // No
                        break;
                    }
                };
            }
        }
        #endif
    }
        public void ReportScore()
        {
            if (!GameServiceManager.IsInitialized())
            {
                MobileNativeUI.Alert("Alert", "You need to initialize the module first.");
                return;
            }

            if (selectedLeaderboard == null)
            {
                MobileNativeUI.Alert("Alert", "Please select a leaderboard to report score to.");
            }
            else
            {
                if (string.IsNullOrEmpty(scoreInput.text))
                {
                    MobileNativeUI.Alert("Alert", "Please enter a score to report.");
                }
                else
                {
                    int score = System.Convert.ToInt32(scoreInput.text);
                    GameServiceManager.ReportScore(score, selectedLeaderboard.Name);
                    MobileNativeUI.Alert("Alert", "Reported score " + score + " to leaderboard \"" + selectedLeaderboard.Name + "\".");
                }
            }
        }
    void Update()
    {
        // Exit on Android Back button
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            MobileNativeAlert alert = MobileNativeUI.ShowTwoButtonAlert(
                title,
                message,
                yesButton,
                noButton
                );

            if (alert != null)
            {
                alert.OnComplete += (int button) =>
                {
                    switch (button)
                    {
                    case 0:     // Yes
                        Application.Quit();
                        break;

                    case 1:     // No
                        break;
                    }
                };
            }
        }
    }
        IEnumerator CRSaveScreenshot()
        {
            yield return(new WaitForEndOfFrame());

            TwoStepScreenshotPath = MobileNativeShare.SaveScreenshot(TwoStepScreenshotName);

            MobileNativeUI.Alert("Alert", "A new screenshot was saved at " + TwoStepScreenshotPath);
        }
 public void ShowToast()
 {
     #if UNITY_ANDROID
     MobileNativeUI.ShowToast("This is a sample Android toast");
     #else
     MobileNativeUI.Alert("Alert", "Toasts are available on Android only.");
     #endif
 }
Exemple #6
0
        /// <summary>
        /// Loads the rewarded ad.
        /// </summary>
        public void LoadRewardedAd()
        {
            if (AdManager.IsAutoLoadDefaultAds())
            {
                MobileNativeUI.Alert("Alert", "autoLoadDefaultAds is currently enabled. Ads will be loaded automatically in background without you having to do anything.");
            }

            AdManager.LoadRewardedAd();
        }
        public void ShowTwoButtonsAlert()
        {
            MobileNativeAlert alert = MobileNativeUI.ShowTwoButtonAlert("Sample Alert", "This is a 2-button alert.", "Button 1", "Button 2");

            if (alert != null)
            {
                alert.OnComplete += OnAlertComplete;
            }
        }
        public void ShowOneButtonAlert()
        {
            MobileNativeAlert alert = MobileNativeUI.Alert("Sample Alert", "This is a simple (1-button) alert.");

            if (alert != null)
            {
                alert.OnComplete += OnAlertComplete;
            }
        }
        void IAPManager_PurchaseCompleted(IAPProduct product)
        {
            if (!ownedProducts.Contains(product))
            {
                ownedProducts.Add(product);
            }

            MobileNativeUI.Alert("Purchased Completed", "The purchase of product " + product.Name + " has completed successfully. This is when you should grant the buyer digital goods.");
        }
Exemple #10
0
 /// <summary>
 /// Shows the default banner ad at the bottom of the screen.
 /// </summary>
 public void ShowBannerAd()
 {
     if (AdManager.IsAdRemoved())
     {
         MobileNativeUI.Alert("Alert", "Ads were removed.");
         return;
     }
     AdManager.ShowBannerAd(BannerAdPosition.Bottom);
 }
        public void LoadFriends()
        {
            if (!GameServiceManager.IsInitialized())
            {
                MobileNativeUI.Alert("Alert", "You need to initialize the module first.");
                return;
            }

            GameServiceManager.LoadFriends(OnFriendsLoaded);
        }
Exemple #12
0
 /// <summary>
 /// Shows the rewarded ad.
 /// </summary>
 public void ShowRewardedAd()
 {
     if (AdManager.IsRewardedAdReady())
     {
         AdManager.ShowRewardedAd();
     }
     else
     {
         MobileNativeUI.Alert("Alert", "Rewarded ad is not loaded.");
     }
 }
 public void Init()
 {
     if (GameServiceManager.IsInitialized())
     {
         MobileNativeUI.Alert("Alert", "The module is already initialized.");
     }
     else
     {
         GameServiceManager.Init();
     }
 }
 // Buy an IAP product using its name
 public void Purchase(string productName)
 {
     if (IAPManager.IsInitialized())
     {
         IAPManager.Purchase(productName);
     }
     else
     {
         MobileNativeUI.Alert("Service Unavailable", "Please check your internet connection.");
     }
 }
 void OnLocalUserScoreLoaded(string leaderboardName, IScore score)
 {
     if (score != null)
     {
         MobileNativeUI.Alert("Local User Score Loaded", "Your score on leaderboard \"" + leaderboardName + "\" is " + score.value);
     }
     else
     {
         MobileNativeUI.Alert("Local User Score Load Failed", "You don't have any score reported to leaderboard \"" + leaderboardName + "\".");
     }
 }
 // Restore purchase
 public void RestorePurchase()
 {
     if (IAPManager.IsInitialized())
     {
         IAPManager.RestorePurchases();
     }
     else
     {
         MobileNativeUI.Alert("Service Unavailable", "Please check your internet connection.");
     }
 }
 public void ShareScreenshot()
 {
     if (!string.IsNullOrEmpty(TwoStepScreenshotPath))
     {
         MobileNativeShare.ShareImage(TwoStepScreenshotPath, sampleMessage);
     }
     else
     {
         MobileNativeUI.Alert("Alert", "Please save a screenshot first.");
     }
 }
Exemple #18
0
        void Update()
        {
            #if UNITY_ANDROID
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                // Ask if user wants to exit
                MobileNativeAlert alert = MobileNativeUI.ShowTwoButtonAlert("Exit App",
                                                                            "Do you want to exit?",
                                                                            "Yes",
                                                                            "No");

                if (alert != null)
                {
                    alert.OnComplete += delegate(int button)
                    {
                        if (button == 0)
                        {
                            Application.Quit();
                        }
                    }
                }
                ;
            }
            #endif
        }

        // Push notification opened handler
        void NotificationManager_NotificationOpened(string message, string actionID, Dictionary <string, object> additionalData, bool isAppInFocus)
        {
            Debug.Log("Push notification received!");
            Debug.Log("Message: " + message);
            Debug.Log("isAppInFocus: " + isAppInFocus.ToString());

            if (additionalData != null)
            {
                Debug.Log("AdditionalData:");
                foreach (KeyValuePair <string, object> item in additionalData)
                {
                    Debug.Log("Key: " + item.Key + " - Value: " + item.Value.ToString());
                }

                if (additionalData.ContainsKey("newUpdate"))
                {
                    if (!isAppInFocus)
                    {
                        Debug.Log("New update available! Should open the update page now.");
                    }
                }
            }
        }
    }
Exemple #19
0
        /// <summary>
        /// Shows the interstitial ad.
        /// </summary>
        public void ShowInterstitialAd()
        {
            if (AdManager.IsAdRemoved())
            {
                MobileNativeUI.Alert("Alert", "Ads were removed.");
                return;
            }

            if (AdManager.IsInterstitialAdReady())
            {
                AdManager.ShowInterstitialAd();
            }
            else
            {
                MobileNativeUI.Alert("Alert", "Interstitial ad is not loaded.");
            }
        }
Exemple #20
0
 public void ShowLeaderboardUI()
 {
     #if EASY_MOBILE
     if (GameServiceManager.IsInitialized())
     {
         GameServiceManager.ShowLeaderboardUI();
     }
     else
     {
         #if UNITY_IOS
         MobileNativeUI.Alert("Service Unavailable", "The user is not logged in to Game Center.");
         #elif UNITY_ANDROID
         GameServiceManager.Init();
         #endif
     }
     #endif
 }
        public void UnlockAchievement()
        {
            if (!GameServiceManager.IsInitialized())
            {
                MobileNativeUI.Alert("Alert", "You need to initialize the module first.");
                return;
            }

            if (selectedAchievement != null)
            {
                GameServiceManager.UnlockAchievement(selectedAchievement.Name);
            }
            else
            {
                MobileNativeUI.Alert("Alert", "Please select an achievement to unlock.");
            }
        }
        public void LoadLocalUserScore()
        {
            if (!GameServiceManager.IsInitialized())
            {
                MobileNativeUI.Alert("Alert", "You need to initialize the module first.");
                return;
            }

            if (selectedLeaderboard == null)
            {
                MobileNativeUI.Alert("Alert", "Please select a leaderboard to load score from.");
            }
            else
            {
                GameServiceManager.LoadLocalUserScore(selectedLeaderboard.Name, OnLocalUserScoreLoaded);
            }
        }
 public void ShowAchievementUI()
 {
     if (GameServiceManager.IsInitialized())
     {
         GameServiceManager.ShowAchievementsUI();
     }
     else
     {
         #if UNITY_ANDROID
         GameServiceManager.Init();
         #elif UNITY_IOS
         MobileNativeUI.Alert("Service Unavailable", "The user is not logged in.");
         #else
         Debug.Log("Cannot show achievements: platform not supported.");
         #endif
     }
 }
        public void Purchase()
        {
            if (selectedProduct != null)
            {
                IAPManager.Purchase(selectedProduct.Name);

                // You can also do
                //IAPManager.Purchase(selectedProduct);

                // The advantage of method Purchase() that uses product name is you can use it with the constant product names
                // in the generated EM_IAPConstants class for compile-time error detecting.
            }
            else
            {
                MobileNativeUI.Alert("Alert", "Please select a product.");
            }
        }
        void OnFriendsLoaded(IUserProfile[] friends)
        {
            if (friends.Length > 0)
            {
                var items = new Dictionary <string, string>();

                foreach (IUserProfile user in friends)
                {
                    items.Add(user.userName, user.id);
                }

                ScrollableList.Create(scrollableListPrefab, "FRIEND LIST", items);
            }
            else
            {
                MobileNativeUI.Alert("Load Friends Result", "Couldn't find any friend.");
            }
        }
Exemple #26
0
 public void ShowAchievementsUI()
 {
     #if EASY_MOBILE
     if (GameServiceManager.IsInitialized())
     {
         GameServiceManager.ShowAchievementsUI();
     }
     else
     {
     #if UNITY_IOS
         MobileNativeUI.Alert("Service Unavailable", "The user is not logged in to Game Center.");
     #elif UNITY_ANDROID
         GameServiceManager.Init();
     #endif
     }
     #else
     Debug.Log("This feature requires EasyMobile plugin.");
     #endif
 }
        public void SelectLeaderboard()
        {
            var leaderboards = EM_Settings.GameService.Leaderboards;

            if (leaderboards == null || leaderboards.Length == 0)
            {
                MobileNativeUI.Alert("Alert", "You haven't added any leaderboard. Please go to Window > Easy Mobile > Settings and add some.");
                selectedAchievement = null;
                return;
            }

            var items = new Dictionary <string, string>();

            foreach (Leaderboard ldb in leaderboards)
            {
                items.Add(ldb.Name, ldb.Id);
            }

            var scrollableList = ScrollableList.Create(scrollableListPrefab, "LEADERBOARDS", items);

            scrollableList.ItemSelected += OnLeaderboardSelected;
        }
        public void SelectAchievement()
        {
            var achievements = EM_Settings.GameService.Achievements;

            if (achievements == null || achievements.Length == 0)
            {
                MobileNativeUI.Alert("Alert", "You haven't added any achievement. Please go to Window > Easy Mobile > Settings and add some.");
                selectedAchievement = null;
                return;
            }

            var items = new Dictionary <string, string>();

            foreach (Achievement acm in achievements)
            {
                items.Add(acm.Name, acm.Id);
            }

            var scrollableList = ScrollableList.Create(scrollableListPrefab, "ACHIEVEMENTS", items);

            scrollableList.ItemSelected += OnAchievementSelected;
        }
        public void SelectProduct()
        {
            var products = EM_Settings.InAppPurchasing.Products;

            if (products == null || products.Length == 0)
            {
                MobileNativeUI.Alert("Alert", "You don't have any IAP product. Please go to Window > Easy Mobile > Settings and add some.");
                selectedProduct = null;
                return;
            }

            var items = new Dictionary <string, string>();

            foreach (IAPProduct pd in products)
            {
                items.Add(pd.Name, pd.Type.ToString());
            }

            var scrollableList = ScrollableList.Create(scrollableListPrefab, "PRODUCTS", items);

            scrollableList.ItemSelected += OnItemSelected;
        }
 // Successful purchase restoration handler
 void OnRestoreCompleted()
 {
     MobileNativeUI.Alert("Restore Completed", "Your in-app purchases were restored successfully.");
 }