Esempio n. 1
0
        private void Update()
        {
            RemainingDuration -= Time.deltaTime;

            if (RemainingDuration <= 0f)
            {
                RemainingDuration = 0f;
                OnTimeElapsed.Invoke();
                gameObject.SetActive(false);
            }
        }
Esempio n. 2
0
 // Update is called once per frame
 void Update()
 {
     TimeLeft = TimeLeft.Subtract(TimeSpan.FromSeconds(Time.deltaTime));
     if (TimeLeft.CompareTo(TimeSpan.Zero) <= 0)
     {
         TimeLeft = TimeSpan.Zero;
         enabled  = false;
         if (OnTimeElapsed != null)
         {
             OnTimeElapsed.Invoke(this, null);
         }
     }
 }
Esempio n. 3
0
        public void Update(GameTime gameTime)
        {
            if (!IsStopped)
            {
                TotalSeconds += gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (!(TotalSeconds >= Interval))
            {
                return;
            }

            OnTimeElapsed?.Invoke(this, new GameTimerEventArgs(TotalSeconds, Interval));
            TotalSeconds = 0;
            if (!IsLooped)
            {
                Reset();
            }
        }
Esempio n. 4
0
        private int count; // number of iterations - if it is negative it means an infinite loop (see below in constructor)

        #endregion Fields

        #region Constructors

        public Timer(OnTimeElapsed method, int interval, int count = -1)
        {
            if (interval <= 0) throw new ArgumentOutOfRangeException(); // interval cannot be negative or zero
            // initializes parameters
            this.count = count;
            this.intervalSeconds = interval;
            this.doWork = method;

            // creates separate thread that loops until it has been executed "count" number of times
            Thread run = new Thread(delegate()
                {
                    while (this.count != 0)
                    {
                        Thread.Sleep(this.intervalSeconds * 1000); // waits some interval of seconds
                        if (this.count > 0) this.count--; // counts down only if positive, otherwise it results to infinite loop
                        this.doWork();
                    }
                });
            run.Start(); // the thread must be started explicitly
        }
Esempio n. 5
0
 private void NotificationHandler(object sender, ElapsedEventArgs e)
 {
     OnTimeElapsed?.Invoke(this, e);
 }
Esempio n. 6
0
        private void ShedulerExecute(object sender, ElapsedEventArgs e)
        {
            Operation operation = (Operation)sender;

            OnTimeElapsed?.Invoke(operation, e);
        }