コード例 #1
0
ファイル: Timer.cs プロジェクト: sata11grd/PotAndRouge
        private void Update()
        {
            RemainingDuration -= Time.deltaTime;

            if (RemainingDuration <= 0f)
            {
                RemainingDuration = 0f;
                OnTimeElapsed.Invoke();
                gameObject.SetActive(false);
            }
        }
コード例 #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);
         }
     }
 }
コード例 #3
0
ファイル: GameTimer.cs プロジェクト: lunacys/lunge
        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();
            }
        }
コード例 #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
        }
コード例 #5
0
 private void NotificationHandler(object sender, ElapsedEventArgs e)
 {
     OnTimeElapsed?.Invoke(this, e);
 }
コード例 #6
0
        private void ShedulerExecute(object sender, ElapsedEventArgs e)
        {
            Operation operation = (Operation)sender;

            OnTimeElapsed?.Invoke(operation, e);
        }