// Update is called once per frame void Update() { int TimesFreeCoins = PreferencesFactory.GetInt(Constants.KeyFreeCoinsCounter, 0); if (TimesFreeCoins >= Constants.TimesFreeCoins) { timeSinceLastCalled += Time.deltaTime; if (timeSinceLastCalled > 1f) { TimeSpan timeSpan = TimeForNextCoins(); if (timeSpan.TotalSeconds > 0) { freeCoinsCounterText.text = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); } else { ResetCounter(); } timeSinceLastCalled = 0f; } } }
private void ProcessDailyBonus(bool doublePrize = true) { _prizeIsProcessed = true; int DaysInRow = PreferencesFactory.GetInt(Constants.KeyFreePrizeTakeDaysInRow, 0); int extraCoins = 0; if (DaysInRow == 7) // reset { extraCoins = Constants.DialyBonusCoins; // bonus coins at last day PreferencesFactory.SetInt(Constants.KeyFreePrizeTakeDaysInRow, 1); } PreferencesFactory.SetString(Constants.KeyDateLastFreePrizeTake, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture)); if (PrizeDialogClosedAudioClip != null) { GameManager.Instance.PlayEffect(PrizeDialogClosedAudioClip); } if ((prizeIsCoins && this.PrizeItems > 0) || extraCoins > 0) { // add extra coins to reward coins only of prize is coins if (prizeIsCoins) { extraCoins += this.PrizeItems; } GameObject animatedCoins = GameObject.Find("AddCoinsAnimated"); GameObject addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent); AddCoinsAnimated addCoins = addCoinsClone.GetComponent <AddCoinsAnimated>(); addCoins.AnimateCoinsAdding(extraCoins); } if (prizeIsPoints) { GameObject animatedPoints = GameObject.Find("AddPointsAnimated"); GameObject _clone = Instantiate(animatedPoints, animatedPoints.transform.parent); AddPointsAnimated _add = _clone.GetComponent <AddPointsAnimated>(); _add.AnimateAdding(this.PrizeItems); GameSparksManager.Instance.SendPoints(this.PrizeItems, "FreePrize"); } SetCurrentPrizeAmount(); // Local notifications #if !UNITY_EDITOR CancelLocalNotifications(); RegisterLocalNotifications(); #endif if (doublePrize) { ShowDoubleScreen(); } }
public static bool BonusCoins() { DateTime dateTime = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyAskFriendsLastDate, UnbiasedTime.Instance.Now().AddDays(-1).ToString(CultureInfo.InvariantCulture))); if (dateTime.Date < UnbiasedTime.Instance.Now().Date) { // last invite was yesterday, reset all data PreferencesFactory.SetString(Constants.KeyAskFriendsLastDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture)); PreferencesFactory.SetInt(Constants.KeyAskFriendsTotal, 0); dateTime = UnbiasedTime.Instance.Now(); } bool addedCoins = false; int totalInvites = PreferencesFactory.GetInt(Constants.KeyAskFriendsTotal); if (dateTime.Date == UnbiasedTime.Instance.Now().Date&& totalInvites < Constants.AskFriendsPerDay) { GameObject animatedCoins = GameObject.Find("AddCoinsAnimated"); GameObject addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent); AddCoinsAnimated addCoins = addCoinsClone.GetComponent <AddCoinsAnimated>(); addCoins.AnimateCoinsAdding(Constants.AskFriendsCoins, rect: GameObject.Find("BoardContainer").transform as RectTransform, showAnimation: false); addedCoins = true; } PreferencesFactory.SetInt(Constants.KeyAskFriendsTotal, totalInvites + 1); return(addedCoins); }
public void Close() { if (shareView != null && shareView.activeSelf) { ShowPointsScreen(); return; } if (PreferencesFactory.GetInt(Constants.KeyNoAds, 0) == 1) { // no ads CloseProcess(); return; } int CountClicks = PreferencesFactory.GetInt(Constants.KeyCountCloseLevelClicks); PreferencesFactory.SetInt(Constants.KeyCountCloseLevelClicks, CountClicks + 1); // if (CountClicks > 0 && CountClicks % Constants.ShowAdsPerTime == 0 && Reachability.Instance.IsReachable()) //{ // Loading.Instance.Show(); // AdColonyManager.Instance.SetCallback(BannerCloseClosed); // AdColonyManager.Instance.PlayAd(AdColonyManager.Instance.AdForZoneId()); //} //else //{ CloseProcess(); //} }
public static void RewardRate() { DateTime dateTime = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyRateRewardLastDate, UnbiasedTime.Instance.Now().AddDays(-1).ToString(CultureInfo.InvariantCulture))); if (dateTime.Date < UnbiasedTime.Instance.Now().Date) { // last rate was yesterday, reset all data PreferencesFactory.SetString(Constants.KeyRateRewardLastDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture)); PreferencesFactory.SetInt(Constants.KeyRateRewardTotal, 0); dateTime = UnbiasedTime.Instance.Now(); } int totalRates = PreferencesFactory.GetInt(Constants.KeyRateRewardTotal); if (dateTime.Date == UnbiasedTime.Instance.Now().Date&& totalRates < 1) { GameObject animatedCoins = GameObject.Find("AddCoinsAnimated"); GameObject addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent); AddCoinsAnimated addCoins = addCoinsClone.GetComponent <AddCoinsAnimated>(); RectTransform tr = null; GameObject _c = GameObject.Find("BoardContainer"); if (_c != null) { tr = _c.transform as RectTransform; } addCoins.AnimateCoinsAdding(Constants.RateRewardCoins, rect: tr, showAnimation: false); } PreferencesFactory.SetInt(Constants.KeyRateRewardTotal, totalRates + 1); PreferencesFactory.SetInt(Constants.KeyRateMaxRewardsTime, PreferencesFactory.GetInt(Constants.KeyRateMaxRewardsTime, 0) + 1); }
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(); } }
public static int RegisterNotification(int id, DateTime fireDate, string body) { if (fireDate < UnbiasedTime.Instance.Now()) // fire date is in past { return(-1); } // notifications are disabled if (PreferencesFactory.GetInt(Constants.KeyNotificationsAllowed, 1) == 0) { return(-1); } #if UNITY_IPHONE NotificationCenter.RequestPermissions((result) => { PreferencesFactory.SetInt(Constants.KeyNotificationsAllowed, result.IsSucceeded ? 1 : 0); //Debug.Log("RequestPermissions callback: err: " + (result.HasError ? result.Error.Message : null) + "; success: " + result.IsSucceeded + "; failed: " + result.IsFailed); }); var content = new NotificationContent(); content.Body = body; content.Badge = 1; var dateComponents = new DateComponents() { Year = fireDate.Year, Month = fireDate.Month, Day = fireDate.Day, Hour = fireDate.Hour, Minute = fireDate.Minute, Second = fireDate.Second }; var trigger = new CalendarTrigger(dateComponents); var request = new NotificationRequest(id.ToString(), content, trigger); NotificationCenter.AddNotificationRequest(request, (result) => { //Debug.Log("AddNotificationRequest callback: err: " + (result.HasError ? result.Error.Message : null) + "; success: " + result.IsSucceeded + "; failed: " + result.IsFailed); }); #endif #if UNITY_ANDROID TimeSpan delay = fireDate - UnbiasedTime.Instance.Now(); AndroidNotificationBuilder builder = new AndroidNotificationBuilder(id, GameManager.Instance.GameName, body, (int)delay.TotalSeconds); AndroidNotificationManager.Instance.ScheduleLocalNotification(builder); #endif return(id); }
/// <summary> /// Show a dialog one time only using the specified dialog as a key for identifying this instance. /// </summary> /// <param name="dialogKey"></param> /// <param name="prefab"></param> /// <param name="title"></param> /// <param name="titleKey"></param> /// <param name="text"></param> /// <param name="textKey"></param> /// <param name="text2"></param> /// <param name="text2Key"></param> /// <param name="sprite"></param> /// <param name="doneCallback"></param> /// <param name="dialogButtons"></param> /// <returns></returns> public DialogInstance ShowOnce(string dialogKey, string prefab = null, string title = null, string titleKey = null, string text = null, string textKey = null, string text2 = null, string text2Key = null, Sprite sprite = null, Action <DialogInstance> doneCallback = null, DialogInstance.DialogButtonsType dialogButtons = DialogInstance.DialogButtonsType.Ok) { // show hint panel first time only if (PreferencesFactory.GetInt("GeneralMessage." + dialogKey, 0) == 0) { PreferencesFactory.SetInt("GeneralMessage." + dialogKey, 1); PreferencesFactory.Save(); return(Show(prefab, title, titleKey, text, textKey, text2, text2Key, sprite, doneCallback, dialogButtons)); } return(null); }
public void Play() { if (ColdStart && PreferencesFactory.GetInt(Constants.KeyNoAds, 0) == 0) { ColdStart = false; if (PreferencesFactory.GetInt(Constants.KeyShowTutorial, 0) == 0) { PreferencesFactory.SetInt(Constants.KeyShowTutorial, 1); } } NextScene(); }
public void Leaderboard() { int CountClicks = PreferencesFactory.GetInt(Constants.KeyCountLeaderboardClicks); PreferencesFactory.SetInt(Constants.KeyCountLeaderboardClicks, CountClicks + 1); // if (CountClicks > 0 && CountClicks % Constants.ShowAdsPerTime == 0 && Reachability.Instance.IsReachable ()) { // Loading.Instance.Show (); // AdColonyManager.Instance.SetCallback(BannerLeaderboardClosed); // AdColonyManager.Instance.PlayAd(AdColonyManager.Instance.AdForZoneId()); //} else { LeaderboardProcess(); //} }
// 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); } }
public void Continue() { // move back Purchase button if (_inviteButtonObject != null) { _inviteButtonObject = null; GameObjectUtils.MoveObjectTo(_buttonPurchaseObject, _inviteOriginalParent, _inviteOriginalPosition); } DialogInstance.DoneFinished(); if (PreferencesFactory.GetInt(Constants.KeyNoAds, 0) == 1) // no ads { ContinueProcess(); return; } #if UNITY_EDITOR ContinueProcess(); return; #endif int CountClicks = PreferencesFactory.GetInt(Constants.KeyCountNextLevelClicks); PreferencesFactory.SetInt(Constants.KeyCountNextLevelClicks, CountClicks + 1); Level level = GameManager.Instance.Levels.Selected; if (level.Number > 10 && level.Number % Constants.ShowAdsPerTime == 0 && Reachability.Instance.IsReachable()) { int rnd = UnityEngine.Random.Range(1, 10); if (rnd < 6 && interstitial != null && interstitial.IsLoaded()) { Loading.Instance.Show(); interstitial.Show(); return; } Loading.Instance.Show(); AdColonyManager.Instance.SetCallback(BannerClosed); AdColonyManager.Instance.PlayAd(AdColonyManager.Instance.AdForZoneId()); } else { ContinueProcess(); } }
public BannerView AddBanner(AdSize adSize) { if (PreferencesFactory.GetInt(Constants.KeyNoAds, 0) == 1) { return(null); } BannerView bannerView = new BannerView(Constants.AdMobUnitIdBanner, adSize, AdPosition.Bottom); // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the banner with the request. bannerView.LoadAd(request); return(bannerView); }
// 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 InterstitialAd AddInterstitialAd() { if (PreferencesFactory.GetInt(Constants.KeyNoAds, 0) == 1) { return(null); } // Initialize an InterstitialAd. InterstitialAd interstitial = new InterstitialAd(Constants.AdMobUnitIdInterstitial); // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the interstitial with the request. interstitial.LoadAd(request); return(interstitial); }
public static bool WillRewardInvite() { DateTime dateTime = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyInviteLastDate, UnbiasedTime.Instance.Now().AddDays(-1).ToString(CultureInfo.InvariantCulture))); if (dateTime.Date < UnbiasedTime.Instance.Now().Date) { // last invite was yesterday return(true); } int totalInvites = PreferencesFactory.GetInt(Constants.KeyInvitesTotal); if (dateTime.Date == UnbiasedTime.Instance.Now().Date&& totalInvites < Constants.InviteMaxPerDay) { return(true); } return(false); }
/// <summary> /// Load this item from perferences within the context of the specified GameItem /// </summary> public void LoadFromPrefs() { if (Configuration.CounterType == CounterConfiguration.CounterTypeEnum.Int) { if (Configuration.Save == CounterConfiguration.SaveType.None) { IntAmountSaved = IntAmount = Configuration.IntDefault; } else { IntAmountSaved = IntAmount = PreferencesFactory.GetInt(_prefsKey, Configuration.IntDefault); } if (Configuration.SaveBest == CounterConfiguration.SaveType.None) { IntAmountBestSaved = IntAmountBest = Configuration.IntDefault; } else { IntAmountBestSaved = IntAmountBest = PreferencesFactory.GetInt(_prefsKeyBest, Configuration.IntDefault); } } else { if (Configuration.Save == CounterConfiguration.SaveType.None) { FloatAmountSaved = FloatAmount = Configuration.FloatDefault; } else { FloatAmountSaved = FloatAmount = PreferencesFactory.GetFloat(_prefsKey, Configuration.FloatDefault); } if (Configuration.SaveBest == CounterConfiguration.SaveType.None) { FloatAmountBestSaved = FloatAmountBest = Configuration.FloatDefault; } else { FloatAmountBestSaved = FloatAmountBest = PreferencesFactory.GetFloat(_prefsKeyBest, Configuration.FloatDefault); } } }
public static void GenerateMoreLevels() { int NumberOfAdditionalCreatedLevels = PreferencesFactory.GetInt(Constants.KeyNumberOfAdditionalCreatedLevels); int StartupLevels = ((CustomGameManager)CustomGameManager.Instance).StartupLevels; #if UNITY_EDITOR Debug.Log("GenerateMoreLevels: StartupLevels: " + StartupLevels); Debug.Log("GenerateMoreLevels: NumberOfAdditionalCreatedLevels before: " + NumberOfAdditionalCreatedLevels); #endif NumberOfAdditionalCreatedLevels += 1; GameManager.Instance.Levels.Load(1, StartupLevels + NumberOfAdditionalCreatedLevels, 0, true); #if UNITY_EDITOR Debug.Log("GenerateMoreLevels: NumberOfAdditionalCreatedLevels after: " + NumberOfAdditionalCreatedLevels); Debug.Log("GenerateMoreLevels: Total: " + (StartupLevels + NumberOfAdditionalCreatedLevels)); #endif PreferencesFactory.SetInt(Constants.KeyNumberOfAdditionalCreatedLevels, NumberOfAdditionalCreatedLevels); PreferencesFactory.Save(); }
// Use this for initialization void Start() { FreeCoinsObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "FreeCoins", true); FreeCoinsCounterObject = GameObjectHelper.GetChildNamedGameObject(gameObject, "FreeCoinsCounter", true); freeCoinsCounterText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(FreeCoinsCounterObject, "Text", true); DateTime nowDate = UnbiasedTime.Instance.Now(); DateTime freeCoinsDate = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyFreeCoinsAvailable, nowDate.ToString(CultureInfo.InvariantCulture))); int TimesFreeCoins = PreferencesFactory.GetInt(Constants.KeyFreeCoinsCounter, 0); if (TimesFreeCoins == 0 || (TimesFreeCoins == Constants.TimesFreeCoins && freeCoinsDate <= nowDate)) { ResetCounter(); } else { if (TimesFreeCoins == Constants.TimesFreeCoins) { TimeSpan timeSpan = TimeForNextCoins(); freeCoinsCounterText.text = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); GameObjectHelper.SafeSetActive(FreeCoinsObject, false); GameObjectHelper.SafeSetActive(FreeCoinsCounterObject, true); } } if (!Reachability.Instance.IsReachable()) { // hide if no internet GameObjectHelper.SafeSetActive(FreeCoinsObject, false); } #if !UNITY_EDITOR AdColonyManager.Instance.RequestAd(Constants.AdColonyCoinsRewardZone); LoadAdmobRewarderVideo(); #endif }
public static bool WillReward() { if (PreferencesFactory.GetInt(Constants.KeyRateMaxRewardsTime, 0) >= Constants.RateMaxRewardsTime) { return(false); } DateTime dateTime = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyRateRewardLastDate, UnbiasedTime.Instance.Now().AddDays(-1).ToString(CultureInfo.InvariantCulture))); int totalRates = PreferencesFactory.GetInt(Constants.KeyRateRewardTotal); if (dateTime.Date < UnbiasedTime.Instance.Now().Date) { // last rate was yesterday return(true); } if (dateTime.Date == UnbiasedTime.Instance.Now().Date&& totalRates < 1) { return(true); } return(false); }
public void ToggleNotifications() { ButtonUtils.PlayClickSound(); if (PreferencesFactory.GetInt(Constants.KeyNotificationsAllowed, 1) == 1) { PreferencesFactory.SetInt(Constants.KeyNotificationsAllowed, 0); if (!Debug.isDebugBuild) { Flurry.Flurry.Instance.LogEvent("Notifications_Off"); Fabric.Answers.Answers.LogCustom("Notifications_Off"); } GameManager.SafeQueueMessage(new UserNotificationsChangedMessage(false)); } else { PreferencesFactory.SetInt(Constants.KeyNotificationsAllowed, 1); if (!LocalNotifications.Allowed()) { LocalNotifications.AllowDialog(() => { PreferencesFactory.SetInt(Constants.KeyNotificationsAllowed, 0); GameObject _n = GameObjectHelper.GetChildNamedGameObject(gameObject, "Notifications", true); Switch _switch = GameObjectHelper.GetChildComponentOnNamedGameObject <Switch> (_n, "Switch", true); _switch.SetOn(false); }); } else { GameManager.SafeQueueMessage(new UserNotificationsChangedMessage(true)); } } }
public override void ClickUnlocked() { if (PreferencesFactory.GetInt(Constants.KeyNoAds, 0) == 1) { // no ads ClickUnlockedProcess(); return; } int CountSelectLevelClicks = PreferencesFactory.GetInt(Constants.KeyCountSelectLevelClicks); PreferencesFactory.SetInt(Constants.KeyCountSelectLevelClicks, CountSelectLevelClicks + 1); //if (CountSelectLevelClicks > 0 && CountSelectLevelClicks % Constants.ShowAdsPerTime == 0 && Reachability.Instance.IsReachable()) //{ // Loading.Instance.Show(); // AdColonyManager.Instance.SetCallback(BannerUnlockedClosed); // AdColonyManager.Instance.PlayAd(AdColonyManager.Instance.AdForZoneId()); //} //else //{ ClickUnlockedProcess(); //} }
public static bool InviteBonusCoins() { DateTime dateTime = DateTime.Parse(PreferencesFactory.GetString(Constants.KeyInviteLastDate, UnbiasedTime.Instance.Now().AddDays(-1).ToString(CultureInfo.InvariantCulture))); if (dateTime.Date < UnbiasedTime.Instance.Now().Date) { // last invite was yesterday, reset all data PreferencesFactory.SetString(Constants.KeyInviteLastDate, UnbiasedTime.Instance.Now().ToString(CultureInfo.InvariantCulture)); PreferencesFactory.SetInt(Constants.KeyInvitesTotal, 0); dateTime = UnbiasedTime.Instance.Now(); } bool addedCoins = false; int totalInvites = PreferencesFactory.GetInt(Constants.KeyInvitesTotal); #if UNITY_EDITOR totalInvites = 0; #endif if (dateTime.Date == UnbiasedTime.Instance.Now().Date&& totalInvites < Constants.InviteMaxPerDay) { GameObject animatedCoins = GameObject.Find("AddCoinsAnimated"); GameObject addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent); AddCoinsAnimated addCoins = addCoinsClone.GetComponent <AddCoinsAnimated>(); addCoins.AnimateCoinsAdding(Constants.InviteAwardCoins); addedCoins = true; } PreferencesFactory.SetInt(Constants.KeyInvitesTotal, totalInvites + 1); return(addedCoins); }
void CompleteReward() { GameObject animatedCoins = GameObject.Find("AddCoinsAnimated"); GameObject addCoinsClone = Instantiate(animatedCoins, animatedCoins.transform.parent); AddCoinsAnimated addCoins = addCoinsClone.GetComponent <AddCoinsAnimated>(); addCoins.AnimateCoinsAdding(Constants.FreeCoinsDaily); // PreferencesFactory.SetString(Constants.KeyFreeCoinsAvailable, UnbiasedTime.Instance.Now().AddMinutes(Constants.MinutesBetweenFreeCoins).ToString(CultureInfo.InvariantCulture)); int TimesFreeCoins = PreferencesFactory.GetInt(Constants.KeyFreeCoinsCounter, 0); TimesFreeCoins += 1; PreferencesFactory.SetInt(Constants.KeyFreeCoinsCounter, TimesFreeCoins); if (TimesFreeCoins >= Constants.TimesFreeCoins) { GameObjectHelper.SafeSetActive(FreeCoinsObject, false); GameObjectHelper.SafeSetActive(FreeCoinsCounterObject, true); } }
/// <summary> /// Load saved values from preferences or set to default if not found. /// </summary> /// <param name="prefix"></param> /// <param name="useSecurePrefs"></param> public void Load(string prefix = "", bool?useSecurePrefs = null) { foreach (var variable in BoolVariables) { if (variable.PersistChanges) { variable.Value = PreferencesFactory.GetBool(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs); } else { variable.Value = variable.DefaultValue; } } foreach (var variable in FloatVariables) { if (variable.PersistChanges) { variable.Value = PreferencesFactory.GetFloat(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs); } else { variable.Value = variable.DefaultValue; } } foreach (var variable in IntVariables) { if (variable.PersistChanges) { variable.Value = PreferencesFactory.GetInt(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs); } else { variable.Value = variable.DefaultValue; } } foreach (var variable in StringVariables) { if (variable.PersistChanges) { variable.Value = PreferencesFactory.GetString(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs); } else { variable.Value = variable.DefaultValue; } } foreach (var variable in Vector2Variables) { if (variable.PersistChanges) { variable.Value = PreferencesFactory.GetVector2(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs) ?? Vector2.zero; } else { variable.Value = variable.DefaultValue; } } foreach (var variable in Vector3Variables) { if (variable.PersistChanges) { variable.Value = PreferencesFactory.GetVector3(prefix + variable.Tag, variable.DefaultValue, useSecurePrefs) ?? Vector3.zero; } else { variable.Value = variable.DefaultValue; } } }
/// <summary> /// Main setup routine /// </summary> protected override void GameSetup() { base.GameSetup(); var sb = new System.Text.StringBuilder(); MyDebug.DebugLevel = DebugLevel; sb.Append("GameManager: GameSetup()"); sb.Append("\nApplication.systemLanguage: ").Append(Application.systemLanguage); // secure preferences PreferencesFactory.UseSecurePrefs = SecurePreferences; if (SecurePreferences) { if (string.IsNullOrEmpty(PreferencesPassPhrase)) { Debug.LogWarning("You have not set a custom pass phrase in GameManager | Player Preferences. Please correct for improved security."); } else { PreferencesFactory.PassPhrase = PreferencesPassPhrase; } PreferencesFactory.AutoConvertUnsecurePrefs = AutoConvertUnsecurePrefs; } // Gameplay related properties IsUnlocked = PreferencesFactory.GetInt("IsUnlocked", 0) != 0; IsUserInteractionEnabled = true; IsSplashScreenShown = false; TimesGamePlayed = PreferencesFactory.GetInt("TimesGamePlayed", 0); TimesGamePlayed++; TimesLevelsPlayed = PreferencesFactory.GetInt("TimesLevelsPlayed", 0); TimesPlayedForRatingPrompt = PreferencesFactory.GetInt("TimesPlayedForRatingPrompt", 0); TimesPlayedForRatingPrompt++; sb.Append("\nTimesGamePlayed: ").Append(TimesGamePlayed); sb.Append("\nTimesLevelsPlayed: ").Append(TimesLevelsPlayed); sb.Append("\nTimesPlayedForRatingPrompt: ").Append(TimesPlayedForRatingPrompt); sb.Append("\nApplication.PersistantDataPath: ").Append(Application.persistentDataPath); MyDebug.Log(sb.ToString()); // audio related properties BackGroundAudioVolume = 1; // default if nothing else is set. EffectAudioVolume = 1; // default if nothing else is set. var audioSources = GetComponents <AudioSource>(); if (audioSources.Length > 0) { BackGroundAudioSource = audioSources[0]; BackGroundAudioVolume = BackGroundAudioSource.volume; } if (audioSources.Length > 1) { EffectAudioSources = new AudioSource[audioSources.Length - 1]; Array.Copy(audioSources, 1, EffectAudioSources, 0, audioSources.Length - 1); EffectAudioVolume = EffectAudioSources[0].volume; } BackGroundAudioVolume = PreferencesFactory.GetFloat("BackGroundAudioVolume", BackGroundAudioVolume, false); EffectAudioVolume = PreferencesFactory.GetFloat("EffectAudioVolume", EffectAudioVolume, false); Assert.IsNotNull(Camera.main, "You need a main camera in your scene!"); // display related properties SetDisplayProperties(); // Localisation setup. If nothing stored then use system Language if it exists. Otherwise we will default to English. LocaliseText.AllowedLanguages = SupportedLanguages; // setup players. Assert.IsTrue(PlayerCount >= 1, "You need to specify at least 1 player in GameManager"); Players = new PlayerGameItemManager(); Players.Load(0, PlayerCount - 1); //TODO: Make Obsolete if (WorldUnlockMode == GameItem.UnlockModeType.Coins || LevelUnlockMode == GameItem.UnlockModeType.Coins || CharacterUnlockMode == GameItem.UnlockModeType.Coins) { Debug.LogWarning("GameManager Unlock Modes are deprecated in favour of the more powerful UnlockXxx options in GameItem configuration files and will soon be removed. Change the GameManager settings to Custom to remove this warning and add / configure GameItem configuration files."); } // handle auto setup of worlds and levels Worlds = new WorldGameItemManager(); Levels = new LevelGameItemManager(); Characters = new CharacterGameItemManager(); if (AutoCreateWorlds) { var coinsToUnlockWorlds = WorldUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockWorlds : -1; Worlds.Load(1, NumberOfAutoCreatedWorlds, coinsToUnlockWorlds, LoadWorldDatafromResources); // if we have worlds then autocreate levels for each world. if (AutoCreateLevels) { for (var i = 0; i < NumberOfAutoCreatedWorlds; i++) { var coinsToUnlock = LevelUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockLevels : -1; Worlds.Items[i].Levels = new LevelGameItemManager(); Worlds.Items[i].Levels.Load(WorldLevelNumbers[i].Min, WorldLevelNumbers[i].Max, coinsToUnlock, LoadLevelDatafromResources); } // and assign the selected set of levels Levels = Worlds.Selected.Levels; } } else { // otherwise not automatically setting up worlds so if auto setup of levels then create at root level. if (AutoCreateLevels) { var coinsToUnlock = LevelUnlockMode == GameItem.UnlockModeType.Coins ? CoinsToUnlockLevels : -1; Levels.Load(1, NumberOfAutoCreatedLevels, coinsToUnlock, LoadLevelDatafromResources); } } // handle auto setup of characters if (AutoCreateCharacters) { if (CharacterUnlockMode == GameItem.UnlockModeType.Coins) { Characters.Load(1, NumberOfAutoCreatedCharacters, CoinsToUnlockCharacters, LoadCharacterDatafromResources); } else { Characters.Load(1, NumberOfAutoCreatedCharacters, loadFromResources: LoadCharacterDatafromResources); } } // coroutine to check for display changes (don't need to do this every frame) if (!Mathf.Approximately(DisplayChangeCheckDelay, 0)) { StartCoroutine(CheckForDisplayChanges()); } // flag as initialised IsInitialised = true; }
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); } }); }
public GameFeedback() { HasRated = PreferencesFactory.GetInt("HasRated") == 1; HasAskedToRate = PreferencesFactory.GetInt("HasAskedToRate") == 1; }
// 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(); }
/// <summary> /// Show a free prize dialog that gives the user coins. We default to the standard General Message window, adding any additional /// content as setup in the FreePrizeManager configuration. /// </summary> public DialogInstance ShowFreePrizeDialog(Action <DialogInstance> doneCallback = null) { // only allow the free prize dialog to be shown once. if (IsShowingFreePrizeDialog) { return(null); } IsShowingFreePrizeDialog = true; _prizeIsProcessed = false; dialogInstance = DialogManager.Instance.Create(ContentPrefab, null, null, null, runtimeAnimatorController: ContentAnimatorController); Sprite sprite = null; string text = BonusText(); if (prizeIsCoins && this.PrizeItems > 0) { sprite = Resources.Load <Sprite>("Images/coins"); } string DateLastFreePrizeTakeString = PreferencesFactory.GetString(Constants.KeyDateLastFreePrizeTake); DateTime DateLastFreePrizeTake = UnbiasedTime.Instance.Now(); if (!DateLastFreePrizeTakeString.Equals("")) { DateLastFreePrizeTake = DateTime.Parse(DateLastFreePrizeTakeString); } int DaysInRow = PreferencesFactory.GetInt(Constants.KeyFreePrizeTakeDaysInRow, 1); if (DateLastFreePrizeTake.AddDays(1).Date == UnbiasedTime.Instance.Now().Date) { DaysInRow += 1; PreferencesFactory.SetInt(Constants.KeyFreePrizeTakeDaysInRow, DaysInRow); } else { // reset DaysInRow = 1; PreferencesFactory.SetInt(Constants.KeyFreePrizeTakeDaysInRow, DaysInRow); } GameObject Days = GameObjectHelper.GetChildNamedGameObject(dialogInstance.gameObject, "Days", true); for (int i = 0; i < Constants.DailyBonusItems.Length; i++) { int prizeValue = Constants.DailyBonusItems[i]; string dayText = string.Format("Day{0}", (i + 1)); GameObject day = GameObjectHelper.GetChildNamedGameObject(Days, dayText, true); if (!day) { continue; } Text t = GameObjectHelper.GetChildNamedGameObject(day, "Text", true).GetComponent <Text>(); t.text = prizeValue.ToString(); if (DaysInRow - 1 > i) { GameObject image = GameObjectHelper.GetChildNamedGameObject(day, "Image", true); GameObjectHelper.SafeSetActive(image, true); } // if ( DaysInRow-1 == i) { // GameObject today = GameObjectHelper.GetChildNamedGameObject(day, "Today", true); // GameObjectHelper.SafeSetActive (today, true); // // GameObject dayNumber = GameObjectHelper.GetChildNamedGameObject(day, "DayNumber", true); // GameObjectHelper.SafeSetActive (dayNumber, false); // } if (DaysInRow == (i + 1)) { // add daily bonus this.PrizeItems += prizeValue; GameObject claimButton = GameObjectHelper.GetChildNamedGameObject(dialogInstance.Content, "ClaimButton", true); Text claimText = GameObjectHelper.GetChildComponentOnNamedGameObject <Text>(claimButton, "Text", true); if (prizeIsPoints) { claimText.text = LocaliseText.Format("FreePrize.ClaimPoints", this.PrizeItems); } if (prizeIsCoins) { claimText.text = LocaliseText.Format("FreePrize.ClaimButton", this.PrizeItems); } } } dialogInstance.Show(title: LocaliseText.Get("FreePrize.Title"), text: text, text2Key: "FreePrize.Text2", doneCallback: (DialogInstance _dialogInstance) => { if (doneCallback != null) { doneCallback(_dialogInstance); } ShowFreePrizeDone(_dialogInstance); }, dialogButtons: ContentShowsButtons ? DialogInstance.DialogButtonsType.Custom : DialogInstance.DialogButtonsType.Ok); GameObject ImageCoins = GameObjectHelper.GetChildNamedGameObject(dialogInstance.gameObject, "ph_Image", true); ImageCoins.SetActive(false); if (this.PrizeItems > 0 && prizeIsCoins && sprite != null) { ImageCoins.SetActive(true); ImageCoins.GetComponent <Image>().sprite = sprite; } StartNewCountdown(); if (!Debug.isDebugBuild) { Fabric.Answers.Answers.LogContentView("FreePrize", "Dialog"); } #if !UNITY_EDITOR AdColonyManager.Instance.RequestAd(Constants.AdColonyDoubleDailyBonus); LoadAdmobRewarderVideo(); #endif return(dialogInstance); }