1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public abstract class TimeBase
- {
- protected bool _start = false;
- protected float _LeftTime = 0;
- public TimeBase(float time) { _LeftTime = time; _start = false; }
- virtual public void Start()
- {
- _start = true;
- }
- virtual public void Pause()
- {
- _start = false;
- }
- abstract public void Update(float deltaTime, Action cb);
- }
- public class TickTime: TimeBase
- {
- private float mtime = 0;
- public TickTime(float time) : base(time) { mtime = time; }
- override public void Start()
- {
- base.Start();
- _LeftTime = mtime;
- }
- public override void Update(float deltaTime, Action cb)
- {
- if (_start)
- {
- _LeftTime -= deltaTime;
- if (_LeftTime <= 0)
- {
- if(cb != null)
- {
- cb.Invoke();
- }
- }
- _start = false;
- }
- }
- }
- public class RepeatTime : TimeBase
- {
- private float _PassTime = 0;
- public RepeatTime(float time) : base(time) { }
- public override void Update(float deltaTime, Action cb)
- {
- if (_start)
- {
- _PassTime += deltaTime;
- if (_PassTime >= _LeftTime)
- {
- if (cb != null)
- {
- cb.Invoke();
- }
- _PassTime = 0;
- }
- }
- }
- }
|