Ejemplo n.º 1
0
        private void LoadItems()
        {
            if (items != null && items.Count > 0)
            {
                for (int i = 0; i < items.Count; i++)
                {
                    Item      item      = items[i];
                    SavedItem savedItem = BinaryPrefs.GetClass <SavedItem>(item.id.ToString());
                    if (savedItem != null)
                    {
                        items[i].LoadFrom(savedItem);
                    }
                }
            }
            else
            {
                Debug.LogWarning("There is no item in your game ! Please verify that everything is setup correctly", this);
            }

            LoadPack();

            if (!IsInitialized)
            {
                IsInitialized = true;
                onInitializeSuccess?.Invoke();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Reset prefs to initial values
 /// </summary>
 public static void ResetValues()
 {
     BinaryPrefs.SetDouble(LastDayKey, DateTime.Now.ToOADate());
     BinaryPrefs.SetInt(DayCountKey, 1);
     BinaryPrefs.SetInt(DailySessionCountKey, 1);
     BinaryPrefs.SetInt(SessionCountKey, 1);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Force Daycount increase in prefs
 /// </summary>
 public static void IncreaseDayCount()
 {
     BinaryPrefs.SetDouble(LastDayKey, DateTime.Now.ToOADate());
     BinaryPrefs.SetInt(DayCountKey, BinaryPrefs.GetInt(DayCountKey) + 1);
     BinaryPrefs.SetInt(DailySessionCountKey, 1);
     BinaryPrefs.SetInt(SessionCountKey, BinaryPrefs.GetInt(SessionCountKey) + 1);
 }
Ejemplo n.º 4
0
        private void Start()
        {
            if (timer == null)
            {
                timer = new Timer(tickPeriod, 0, 0f, true);
            }

            if (!String.IsNullOrEmpty(buttonKey))
            {
                string _saveString = String.Empty;
                if (saveThisCountdown)
                {
                    _saveString         = BinaryPrefs.GetString(buttonKey);
                    waitForDelayExpired = BinaryPrefs.GetBool(buttonKey + waitForDelayExpiredKey, false);
                }

                if (!String.IsNullOrEmpty(_saveString))
                {
                    SetEndDate(Convert.ToDateTime(_saveString));

                    if (DateTime.Compare(DateTime.Now, endDate) < 0)
                    {
                        StartCountdown();
                    }
                    else if (waitForDelayExpired)
                    {
                        ResetCountdown();
                    }
                }
            }
            else
            {
                Debug.LogError("You need to specify a buttonName for the save");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Start the countdown, need to have a End Date
        /// </summary>
        public void StartCountdown()
        {
            if (timer == null)
            {
                timer = new Timer(tickPeriod, 0, 0f, true);
            }

            if (saveThisCountdown)
            {
                BinaryPrefs.SetString(buttonKey, endDate.ToString());
            }

            countdownDisplayValue = TimeManager.Instance.GetCountdownDisplayValue(DateTime.Now, endDate);

            waitForDelayExpired = true;
            if (saveThisCountdown)
            {
                BinaryPrefs.SetBool(buttonKey + waitForDelayExpiredKey, waitForDelayExpired);
            }

            timer.Looped += NewTick;
            timer.Start();

            UpdateUI();
        }
Ejemplo n.º 6
0
        private void CurrencyChanged()
        {
            OnCurrencyChanged?.Invoke(this);
            SavedCurrency savedCurrency = new SavedCurrency(id, currentAmount);

            BinaryPrefs.SetClass(id.ToString(), savedCurrency);
        }
    void Start()
    {
        //---------------------------------------------------------------------------------//
        //---------------------------------------------------------------------------------//
        // BinaryPrefs works like PlayerPrefs:
        // BinaryPrefs gets values as fast as PlayerPrefs and sets them 40 times faster.

        // PLAYER PREFS
        PlayerPrefs.SetInt("testInt", 5);
        int playerPrefsInt = PlayerPrefs.GetInt("testInt");

        // BINARY PREFS
        BinaryPrefs.SetInt("testInt", 5);
        int binaryPrefsInt = BinaryPrefs.GetInt("testInt");

        //---------------------------------------------------------------------------------//
        //---------------------------------------------------------------------------------//

        // BinaryPrefs handles useful types as:
        BinaryPrefs.SetBool("testBool", true);
        BinaryPrefs.SetDouble("testDouble", 2.2);

        //---------------------------------------------------------------------------------//
        //---------------------------------------------------------------------------------//

        // BinaryPrefs handles multi-dimensional array serialization:
        BinaryPrefs.SetClass("testClass", new TwoDimensionArray()
        {
            m_Value = new int[, , ] {
                {
                    { 1, 2, 3, 4 },
                    { 4, 5, 6, 4 }
                },
                {
                    { 1, 2, 3, 4 },
                    { 4, 5, 6, 4 }
                },
            },
        });

        //---------------------------------------------------------------------------------//
        //---------------------------------------------------------------------------------//

        // BinaryPrefs is compatible with Json:
        BinaryPrefs.SetString("testJson", JsonUtility.ToJson(new DataToJson()));

        //---------------------------------------------------------------------------------//
        //---------------------------------------------------------------------------------//

        // BinaryPrefs comes along with useful tools:
        BinaryPrefs.HasKey("testJson");
        BinaryPrefs.DeleteKey("testJson");

        BinaryPrefs.ForceSave(); // Use with caution
        BinaryPrefs.DeleteAll(); // Use with caution

        //---------------------------------------------------------------------------------//
        //---------------------------------------------------------------------------------//
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Load the previously saved payment
        /// </summary>
        public void LoadPayment()
        {
            SavedPayment savedPayment = BinaryPrefs.GetClass <SavedPayment>(payment.id);

            if (savedPayment != null)
            {
                payment.LoadFrom(savedPayment);
            }
        }
Ejemplo n.º 9
0
    public void SaveSeeds()
    {
        List <string> ids = new List <string>();

        ids = new List <string>();
        foreach (var s in _viewedSeeds)
        {
            ids.Add(s._id);
        }
        BinaryPrefs.SetClass <List <string> >(ViewSeedString, ids);
    }
Ejemplo n.º 10
0
    private void LoadSeeds()
    {
        List <string> ids = new List <string>();

        ids = BinaryPrefs.GetClass <List <String> >(SeedString);

        ids = BinaryPrefs.GetClass <List <String> >(ViewSeedString);
        if (ids != null && ids.Count > 0)
        {
            foreach (var s in ids)
            {
                _viewedSeeds.Add(_seedLibrary.FirstOrDefault <Seed>(u => u._id == s));
            }
        }
    }
Ejemplo n.º 11
0
        private void NewTick(Timer _timer)
        {
            countdownDisplayValue = TimeManager.Instance.GetCountdownDisplayValue(DateTime.Now, endDate);

            UpdateUI();

            if (DateTime.Compare(DateTime.Now, endDate) > 0)
            {
                timer.Stop();
                OnCountdownEnded?.Invoke();
                if (saveThisCountdown)
                {
                    BinaryPrefs.SetString(buttonKey, endDate.ToString());
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Launch the "Random Selection Animation" in async mode with the list of skin _skins and the result skin _skin
        /// </summary>
        /// <param name="_skins"></param>
        /// <param name="_skin"></param>
        /// <returns></returns>
        private async Task LaunchRSAAsync(List <Skin> _skins, Skin _skin)
        {
            shop.UpdatePayment();
            shopView.EnableInteractivity(false);
            Queue <Skin> randomSelectionSkins = new Queue <Skin>();

            if (_skins.Count > 1)
            {
                int nbIteration = (int)Random.Range(numberOfRandomIteration * (1f - coeffRandomIteration),
                                                    numberOfRandomIteration * (1f + coeffRandomIteration));

                Skin skin = null;

                for (int i = 0; i < nbIteration - 1; i++)
                {
                    List <Skin> localSkins = new List <Skin>(_skins);
                    localSkins.Remove(skin);
                    skin = localSkins.GetRandomValue();
                    randomSelectionSkins.Enqueue(skin);
                }
            }

            randomSelectionSkins.Enqueue(_skin);

            try
            {
                while (randomSelectionSkins.Count > 0)
                {
                    shopView.SelectSkin(randomSelectionSkins.Dequeue());
                    await Task.Delay(selectionMaxDelay / (randomSelectionSkins.Count + 1));
                }

                skinManager.CollectSkin(_skin);
                shopView.SelectToggle(_skin);

                await Task.WhenAny(OnSkinAcquiredInvoker(), Task.Delay(lastFocusDuration));

                shopView.SelectSkin(null);
                shopView.EnableInteractivity();
            }
            catch
            {
                skinManager.CollectSkin(_skin);
                BinaryPrefs.ForceSave();
                throw;
            }
        }
Ejemplo n.º 13
0
        private void Awake()
        {
            double   lastOADay = BinaryPrefs.GetDouble(LastDayKey);
            DateTime lastDay   = lastOADay == 0.0 ? DateTime.MinValue : DateTime.FromOADate(lastOADay);
            bool     isNextDay = DateTime.Now.Year != lastDay.Year ||
                                 DateTime.Now.Month != lastDay.Month ||
                                 DateTime.Now.Day != lastDay.Day;

            if (lastDay == DateTime.MinValue || isNextDay)
            {
                IncreaseDayCount();
            }
            else
            {
                BinaryPrefs.SetInt(DailySessionCountKey, BinaryPrefs.GetInt(DailySessionCountKey) + 1);
                BinaryPrefs.SetInt(SessionCountKey, BinaryPrefs.GetInt(SessionCountKey) + 1);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Reset the countdown, set the End Date to Now, trigger the OnEndWait event
        /// </summary>
        public void ResetCountdown()
        {
            SetEndDate(DateTime.Now);

            if (saveThisCountdown)
            {
                BinaryPrefs.SetString(buttonKey, endDate.ToString());
            }

            timer.Stop();

            waitForDelayExpired = false;

            if (saveThisCountdown)
            {
                BinaryPrefs.SetBool(buttonKey + waitForDelayExpiredKey, waitForDelayExpired);
            }

            OnCountdownEnded?.Invoke();
        }
Ejemplo n.º 15
0
        private void LoadPack()
        {
            if (packs != null && packs.Count > 0)
            {
                for (int i = 0; i < packs.Count; i++)
                {
                    Pack      pack      = packs[i];
                    SavedPack savedPack = BinaryPrefs.GetClass <SavedPack>(pack.id.ToString());
                    if (savedPack != null)
                    {
                        packs[i].LoadFrom(savedPack);
                    }

                    pack.onCollectSuccessful += OnPackCollectSuccessfulInvoker;
                    pack.onCollectFailed     += OnPackCollectFailedInvoker;
                }
            }
            else
            {
                Debug.LogWarning("There is no pack in your game ! Please verify that everything is setup correctly", this);
            }
        }
Ejemplo n.º 16
0
 private void OnDestroy()
 {
     LastLoginTime = DateTime.Now;
     BinaryPrefs.ForceSave();
 }