Ejemplo n.º 1
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();
        }
    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.º 3
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();
        }