void CheckNotificationsPermission() { int CountMainMenuColdStart = PreferencesFactory.GetInt(Constants.KeyCountMainMenuColdStart); DateTime now = UnbiasedTime.Instance.Now(); // not in first launch if (CountMainMenuColdStart > 0 && !Allowed()) { // the date when we detected that notifications are denied if (!PreferencesFactory.HasKey(Constants.KeyNoNotificationPermissionDeniedDate)) { PreferencesFactory.SetString(Constants.KeyNoNotificationPermissionDeniedDate, now.ToString(CultureInfo.InvariantCulture)); return; } DateTime dateOfDenying = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyNoNotificationPermissionDeniedDate, now.ToString(CultureInfo.InvariantCulture))); float minutes3days = 3 * 24 * 60; float minutes10days = 10 * 24 * 60; if (Debug.isDebugBuild) { minutes3days = 1f; // 30 sec minutes10days = 2f; // 1 min } // 3 days before show alert for first time if (now.Date < dateOfDenying.AddMinutes(minutes3days).Date) { return; } DateTime postponeDate = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyNoNotificationPermissionDate, now.ToString(CultureInfo.InvariantCulture))); // 10 days to show alert again if user postpone it if (PreferencesFactory.HasKey(Constants.KeyNoNotificationPermissionDate) && now.Date < postponeDate.AddMinutes(minutes10days).Date) { return; } PreferencesFactory.DeleteKey(Constants.KeyNoNotificationPermissionDate); string text = LocaliseText.Get("Notifications.DeniedText"); Alert alert = new Alert("", text) .SetPositiveButton(LocaliseText.Get("Notifications.AllowText"), () => { iSDK.Utils.OpenSettings(); }) .SetNeutralButton(LocaliseText.Get("Notifications.IgnoreText"), () => { PreferencesFactory.SetString(Constants.KeyNoNotificationPermissionDate, now.ToString(CultureInfo.InvariantCulture)); }) .AddOptions(new AlertIOSOptions() { PreferableButton = Alert.ButtonType.Positive }); alert.Show(); } }
// void BonusCoins() { int coins = PreferencesFactory.GetInt(Constants.KeyDailyLoginBonusCoins, 0); if (coins > 0) { PreferencesFactory.DeleteKey(Constants.KeyDailyLoginBonusCoins); GameObject animatedCoins = GameObject.Find("AddCoinsAnimated"); GameObject addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent); AddCoinsAnimated addCoins = addCoinsClone.GetComponent <AddCoinsAnimated>(); addCoins.AnimateCoinsAdding(coins); } }
// Use this for initialization void Start() { _scrollSnap = GameObjectHelper.GetChildComponentOnNamedGameObject <HorizontalScrollSnap>(gameObject, "ScrollView", true); _nextButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "NextButton", true); container = gameObject; // AddBanner(); GameManager.SafeAddListener <BannerLoadedMessage>(BannerLoadedHandler); GameManager.SafeAddListener <VideoAdShowingMessage>(VideoAdShowingHandler); StartCoroutine(CoRoutines.DelayedCallback(0.5f, BonusCoins)); ((CustomGameManager)GameManager.Instance).ResetDefaultSound(); if (!Debug.isDebugBuild) { FlurryIOS.LogPageView(); FlurryAndroid.OnPageView(); Fabric.Answers.Answers.LogContentView("Levels", "Screen"); } _rankSignGameObject = GameObjectHelper.GetChildNamedGameObject(packsContainer, "Sign", true); _rankSignText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(_rankSignGameObject, "RankName", true); _ranksVerticalScroll = GameObjectHelper.GetChildComponentOnNamedGameObject <CustomVerticalScrollSnap>(packsContainer, "ScrollView", true); PrepareRankForLevel(GameManager.Instance.Levels.Selected); _ranksVerticalScroll.StartingScreen = LevelController.Ranks().Items.Length - (_currentRank.Number - 1) - 1; if (PreferencesFactory.GetInt(Constants.KeyShowSelectedPack) > 0 && GameManager.Instance.Levels.Selected != null) { PreferencesFactory.DeleteKey(Constants.KeyShowSelectedPack); GoToLevel(GameManager.Instance.Levels.Selected); } #if !UNITY_EDITOR AdColonyManager.Instance.RequestAd(); // request ads to cache for CustomLevelButton.cs #endif }
public static void SetLanguage(SystemLanguage language) { if (language == Application.systemLanguage) { PreferencesFactory.DeleteKey(SettingsKeys.Language); } else { PreferencesFactory.SetString(SettingsKeys.Language, language.ToString()); } _initialized = false; if (OnLocalisationChanged != null) { OnLocalisationChanged(null, null); } }
public void RegisterAction(GameObject GO) { var mainTransform = GO.transform; var email = mainTransform.Find("EmailField").GetComponent <InputField> (); var username = mainTransform.Find("UsernameField").GetComponent <InputField> (); var password = mainTransform.Find("PasswordField").GetComponent <InputField> (); var repearPassword = mainTransform.Find("RepeatPasswordField").GetComponent <InputField> (); var emailString = email.text; var usernameString = username.text; var passwordString = password.text; var repeatString = repearPassword.text; if (string.IsNullOrEmpty(emailString)) { ShowInfoDialogWithText(LocaliseText.Get("Account.EmailEmptyError"), "OK"); return; } if (!IsMailValid(emailString)) { ShowInfoDialogWithText(LocaliseText.Get("Account.EmailNotValidError"), "OK"); return; } if (string.IsNullOrEmpty(usernameString)) { ShowInfoDialogWithText(LocaliseText.Get("Account.UsernameEmptyError"), "OK"); return; } if (!IsUsernameValid(usernameString)) { ShowInfoDialogWithText(LocaliseText.Get("Account.UsernameNotValid"), "OK"); return; } if (string.IsNullOrEmpty(passwordString)) { ShowInfoDialogWithText(LocaliseText.Get("Account.PasswordEmptyError"), "OK"); return; } if (string.IsNullOrEmpty(repeatString) || !repeatString.Equals(passwordString)) { ShowInfoDialogWithText(LocaliseText.Get("Account.PasswordsNotEqual"), "OK"); return; } if (!Reachability.Instance.IsReachable()) { ShowInfoDialogWithText(LocaliseText.Get("Account.NoConnection"), "CLOSE"); return; } if (!GS.Available) { GS.Reconnect(); } Loading.Instance.Show(); // user was logged from DeviceAuthenticationRequest and now only update his data if (PreferencesFactory.HasKey(Constants.ProfileAnonymousUserId)) { new ChangeUserDetailsRequest() .SetDisplayName(usernameString) .SetUserName(emailString) .SetNewPassword(passwordString) .Send((response) => { Loading.Instance.Hide(); if (response.HasErrors) { ParseServerResponse(response.Errors); return; } email.text = null; username.text = null; password.text = null; repearPassword.text = null; PreferencesFactory.SetString(Constants.ProfileEmail, emailString); PreferencesFactory.SetString(Constants.ProfileUsername, usernameString); PreferencesFactory.SetString(Constants.ProfileUserId, PreferencesFactory.GetString(Constants.ProfileAnonymousUserId)); PreferencesFactory.DeleteKey(Constants.ProfileAnonymousUserId); PreferencesFactory.Save(); if (_callback != null) { _callback.OnUserRegistered(); } GameManager.SafeQueueMessage(new UserRegisterMessage()); if (!Debug.isDebugBuild) { Flurry.Flurry.Instance.LogEvent("Register_Email"); Fabric.Answers.Answers.LogSignUp("Email"); Branch.userCompletedAction("Register"); Branch.setIdentity(PreferencesFactory.GetString(Constants.ProfileUserId)); } }); return; } new RegistrationRequest() .SetUserName(emailString) .SetDisplayName(usernameString) .SetPassword(passwordString) .Send(((response) => { Loading.Instance.Hide(); if (!response.HasErrors) { email.text = null; username.text = null; password.text = null; repearPassword.text = null; var scriptData = response.ScriptData; if (scriptData != null) { var avatar = scriptData.GetString("avatar"); if (avatar != null) { PreferencesFactory.SetString(Constants.ProfileAvatar, avatar); } } PreferencesFactory.SetString(Constants.ProfileEmail, emailString); PreferencesFactory.SetString(Constants.ProfileUsername, response.DisplayName); PreferencesFactory.SetString(Constants.ProfileUserId, response.UserId); PreferencesFactory.Save(); if (_callback != null) { _callback.OnUserRegistered(); } GameManager.SafeQueueMessage(new UserRegisterMessage()); if (!Debug.isDebugBuild) { Flurry.Flurry.Instance.LogEvent("Register_Email"); Fabric.Answers.Answers.LogSignUp("Email"); Branch.userCompletedAction("Register"); Branch.setIdentity(PreferencesFactory.GetString(Constants.ProfileUserId)); } } else { ParseServerResponse(response.Errors); } })); }
public void SendPoints(int points, string source = null, JSONObject pointsJsonData = null) { int offlinePoints = PreferencesFactory.GetInt(Constants.KeyOfflinePoints, 0); string _pointsDataString = PreferencesFactory.GetString(Constants.KeyOfflinePointsData, null); if (pointsJsonData != null && source != null) { pointsJsonData.Add("source", source); } JSONArray _pointsData = new JSONArray(); if (!string.IsNullOrEmpty(_pointsDataString)) { try { _pointsData = JSONArray.Parse(_pointsDataString); } catch (Exception e) {} } if (pointsJsonData != null) // add new record { _pointsData.Add(pointsJsonData); } if (Reachability.Instance.IsReachable() == false || IsUserLoggedIn() == false) { PreferencesFactory.SetInt(Constants.KeyOfflinePoints, points + offlinePoints); PreferencesFactory.SetString(Constants.KeyOfflinePointsData, _pointsData.ToString()); return; } if (points + offlinePoints <= 0) { return; } int levelNumber = -1; try { Level level = LevelController.FirstUnplayedLevel(); if (level != null) { levelNumber = level.Number - 1; } } catch (Exception e) {} GSRequestData requestData = new GSRequestData(); requestData.AddNumber("offlinePoints", offlinePoints); requestData.AddNumber("score", points); requestData.AddNumber("lastPlayedLevel", levelNumber); if (_pointsData != null) { requestData.AddJSONStringAsObject("pointsData", _pointsData.ToString()); } if (source != null) { requestData.AddString("source", source); } new LogEventRequest() .SetEventKey("SubmitScoreV2") .SetEventAttribute("score", points + offlinePoints) .SetEventAttribute("data", requestData) .Send((response) => { if (!response.HasErrors) { PreferencesFactory.DeleteKey(Constants.KeyOfflinePoints); PreferencesFactory.DeleteKey(Constants.KeyOfflinePointsData); } }); }
// Use this for initialization void Start() { Branch.initSession(CallbackWithBranchUniversalObject); int show = PreferencesFactory.GetInt(Constants.KeyShowBannerOnMainMenuScreen, 0); container = GameObject.Find("Container"); if (PreferencesFactory.GetInt(Constants.KeyNoAds, 0) == 1) { show = 0; // disable ads } _rewardShareButton = GameObjectHelper.GetChildNamedGameObject(gameObject, "RewardButton", true); if (_rewardShareButton != null && RewardsShareHelper.WillReward()) { ShowRewardShareButton(); } #if !UNITY_EDITOR // delay request until AdColony is configured StartCoroutine(CoRoutines.DelayedCallback(1.5f, () => { AdColonyManager.Instance.RequestAd(); })); #endif if (show > 0) // show banner only when return to main screen, not cold start { AddBanner(); PreferencesFactory.DeleteKey(Constants.KeyShowBannerOnMainMenuScreen); int CountClicks = PreferencesFactory.GetInt(Constants.KeyCountMainMenuClicks); PreferencesFactory.SetInt(Constants.KeyCountMainMenuClicks, CountClicks + 1); // if (CountClicks > 0 && CountClicks % Constants.ShowAdsPerTime == 0 && Reachability.Instance.IsReachable ()) { // Loading.Instance.Show (); // AdColonyManager.Instance.SetCallback (BannerMainMenuClosed); // AdColonyManager.Instance.PlayAd(AdColonyManager.Instance.AdForZoneId()); //} } else // show banner on cold start { ColdStart = true; int CountMainMenuColdStart = PreferencesFactory.GetInt(Constants.KeyCountMainMenuColdStart); PreferencesFactory.SetInt(Constants.KeyCountMainMenuColdStart, CountMainMenuColdStart + 1); } GameManager.SafeAddListener <BannerLoadedMessage> (BannerLoadedHandler); GameManager.SafeAddListener <VideoAdShowingMessage> (VideoAdShowingHandler); ((CustomGameManager)GameManager.Instance).ResetDefaultSound(); if (!Debug.isDebugBuild) { FlurryIOS.LogPageView(); FlurryAndroid.OnPageView(); Fabric.Answers.Answers.LogContentView("Menu", "Screen"); } StartCoroutine(CoRoutines.DelayedCallback(0.5f, () => { CheckForPrize(); })); GameSparksManager.Instance.SetGameMode(GameMode.Single); AnimatePig(); }