예제 #1
0
        public void StartTimer(float from, string id, bool looping = false)
        {
            TickerObject ticker = new TickerObject();

            if (ticker.routine == null)
            {
                ticker.lastSystemTime = "0";
                ticker.routine        = routineRunner.StartCoroutine(UpdateTimerCoro(ticker, from, id, looping));
            }

            _runningTickers.Add(id, ticker);
        }
예제 #2
0
        public void StartEventTimer(string eventID)
        {
            logger.Log("<color=blue>EventTimer </color>", "Start");
            float timeTillEnd = EventTimerCooldown(eventID);

            if (timeTillEnd > 0)
            {
                TickerObject ticker = new TickerObject();
                if (ticker.routine == null)
                {
                    ticker.lastSystemTime = "0";
                    ticker.routine        = routineRunner.StartCoroutine(UpdateTimerCoro(ticker, timeTillEnd, eventID, false));
                }

                _runningTickers.Add(eventID, ticker);
            }
        }
예제 #3
0
        public void StartRewardTimer()
        {
            if (GsdkSettingsData.Instance.IsRewardSystemEnabled)
            {
                logger.Log("<color=yellow>RewardTimer</color>", "Init");

                if (RewardTimerCooldown() > 0)
                {
                    TickerObject ticker = new TickerObject();
                    if (ticker.routine == null)
                    {
                        ticker.lastSystemTime = "0";
                        ticker.routine        = routineRunner.StartCoroutine(UpdateTimerCoro(ticker, RewardTimerCooldown(), RewardTimerID, false));
                    }

                    _runningTickers.Add(RewardTimerID, ticker);
                }
            }
        }
예제 #4
0
        private IEnumerator UpdateTimerCoro(TickerObject ticker, float from, string id, bool looping)
        {
            ticker.timeLeft = from;

            while (!ticker.stop)
            {
                DateTime systemTime;
                if (networkCheck.HasInternetConnection())
                {
                    systemTime = serverTime.GetLocalTime();
                }
                else
                {
                    systemTime = DateTime.Now;
                }

                if (ticker.lastSystemTime == "0")
                {
                    string time = systemTime.ToString();
                    ticker.lastSystemTime = time;
                }
                else
                {
                    DateTime lastSysT = DateTime.Parse(ticker.lastSystemTime);
                    TimeSpan timediff = systemTime - lastSysT;
                    ticker.timeLeft      -= (float)timediff.TotalSeconds;
                    ticker.lastSystemTime = systemTime.ToString();
                }

                if (ticker.timeLeft <= 0)
                {
                    if (looping)
                    {
                        ticker.timeLeft = from;
                    }
                    else
                    {
                        ticker.stop = true;
                    }

                    onTimerLoopCompleteSignal.Dispatch(id);
                }

                ticker.minutes = Mathf.Floor(ticker.timeLeft / 60);
                ticker.seconds = Mathf.Ceil(ticker.timeLeft % 60);

                if (ticker.seconds == 60f)
                {
                    ticker.minutes += 1;
                    ticker.seconds  = 0;
                }

                ticker.timerCounter = string.Format("{0:0}:{1:00}", ticker.minutes, ticker.seconds);

                yield return(new WaitForSeconds(1f));
            }

            routineRunner.StopCoroutine(ticker.routine);

            ticker.routine = null;
            _runningTickers.Remove(id);
        }