Ejemplo n.º 1
0
 void OnChangeTimer(ITimer timer)
 {
     if (typeof(PomodoroTimer) == timer.GetType())
     {
         Content = new PomodoroTimerViewModel();
     }
     else if(typeof(CountdownTimer) == timer.GetType())
     {
         Content = new CountdownTimerViewModel();
     }
 }
Ejemplo n.º 2
0
        private void TimerEventTest(ITimer timer)
        {
            Console.WriteLine($"TimerEventTest {timer.GetType().Name}");
            timer.Interval = 5;
            timer.Start();

            Task.Run(() =>
            {
                var stopwatch = new HiResStopwatch();
                stopwatch.Start();

                var timerEvent = new TimerEvent(timer);
                var count      = 0;
                while (count++ < 400)
                {
                    timerEvent.WaitOne();
                    Console.WriteLine($"TimerEventTest TickCount {count}, Timer = {stopwatch.ElapsedMicroseconds:#,0} µs");
                }

                timerEvent.Dispose();
                stopwatch.Stop();
            }).Wait();

            Console.WriteLine("Stopping...");

            timer.Dispose();
        }
Ejemplo n.º 3
0
        public void Record()
        {
            List <RecordTimer> timers = new List <RecordTimer>();

            for (int i = 0; i < m_timers.Count; i++)
            {
                ITimer timer = m_timers[i];
                if (timer.GetType() == typeof(RecordTimer))
                {
                    RecordTimer recordTimer = (RecordTimer)timer;
                    recordTimer.recordDate = DateTime.Now;
                    timers.Add(recordTimer);
                }
            }
            // timers -> json -> playeroprefs
            if (timers.Count <= 0)
            {
                return;
            }
            List <RecordTimerData> datas = new List <RecordTimerData>();

            for (int i = 0; i < timers.Count; i++)
            {
                RecordTimerData data = new RecordTimerData();
                data.TimerName = timers[i].name;
                var    date       = timers[i].recordDate;
                string dateString = date.Year + "|" + date.Month + "|" + date.Day + "|" + date.Hour + "|" + date.Minute + "|" + date.Second;
                data.RecordDate = dateString;
                data.RemainTime = timers[i].remainTime;
                datas.Add(data);
            }
            string recordTimers = SimpleJson.SimpleJson.SerializeObject(datas);

            PlayerPrefs.SetString("RecordTimers", recordTimers);
        }
Ejemplo n.º 4
0
        private void TimerTest(ITimer timer)
        {
            Console.WriteLine($"TimerTest {timer.GetType().Name}");
            var stopwatch = new HiResStopwatch();

            stopwatch.Start();

            timer.Interval = 5;
            timer.Elapsed += (sender, args) => OnTimerTick(stopwatch, args);
            timer.Start();

            // Do something whilst events happening, for demo sleep 2000ms (2sec)
            Thread.Sleep(2000);

            Console.WriteLine("Stopping...");

            timer.Dispose();
        }
Ejemplo n.º 5
0
 private void TimeRun()
 {
     if (m_timers.Count <= 0)
     {
         return;
     }
     for (int i = 0; i < m_timers.Count; i++)
     {
         ITimer timer = m_timers[i];
         if (timer.timing)
         {
             if (timer.timeScaleEffect)
             {
                 timer.elapsed += Time.deltaTime;
             }
             else
             {
                 timer.elapsed += Time.unscaledDeltaTime;
             }
             if (null != timer.OnTimingAction)
             {
                 timer.OnTimingAction(timer.elapsed);
             }
             // skill timer?
             if (timer.GetType() == typeof(SkillTimer) || timer.GetType() == typeof(Countdown))
             {
                 ISkillTimer skillTimer = (ISkillTimer)timer;
                 if (skillTimer.elapsed >= skillTimer.cdTime)
                 {
                     skillTimer.CloseTime();
                 }
             }
             // invoke the interval event
             if (null == timer.intervalEvents || timer.intervalEvents.Count <= 0)
             {
                 continue;
             }
             for (int m = 0; m < timer.intervalEvents.Count; m++)
             {
                 var intervalEvent = timer.intervalEvents[m];
                 if (!intervalEvent.actionRepeat)
                 {
                     if (intervalEvent.intervalTime >= timer.elapsed)
                     {
                         if (null != intervalEvent.intervalAction)
                         {
                             intervalEvent.intervalAction();
                         }
                     }
                 }
                 else
                 {
                     // repeat mode
                     int curPointer = (int)(timer.elapsed / intervalEvent.intervalTime);
                     if (curPointer > intervalEvent.intervalPointer)
                     {
                         if (null != intervalEvent.intervalAction)
                         {
                             intervalEvent.intervalAction();
                             intervalEvent.intervalPointer++;
                         }
                     }
                 }
             }
         }
     }
 }