示例#1
0
 /// <summary>
 /// Starts consuming the cooldown object if possible
 /// </summary>
 public virtual void Start()
 {
     if (Ready())
     {
         CooldownState = CooldownStates.Consuming;
     }
 }
示例#2
0
 /// <summary>
 /// Stops consuming the object
 /// </summary>
 public virtual void Stop()
 {
     if (CooldownState == CooldownStates.Consuming)
     {
         CooldownState = CooldownStates.PauseOnEmpty;
     }
 }
示例#3
0
 /// <summary>
 /// An init method that ensures the object is reset
 /// </summary>
 public virtual void Initialization()
 {
     _pauseOnEmptyWFS       = new WaitForSeconds(PauseOnEmptyDuration);
     CurrentDurationLeft    = ConsumptionDuration;
     CooldownState          = CooldownStates.Idle;
     _emptyReachedTimestamp = 0f;
 }
示例#4
0
        /// <summary>
        /// Processes the object's state machine
        /// </summary>
        public virtual void Update()
        {
            if (Unlimited)
            {
                return;
            }

            switch (CooldownState)
            {
            case CooldownStates.Idle:
                break;

            case CooldownStates.Consuming:
                CurrentDurationLeft = CurrentDurationLeft - Time.deltaTime;
                if (CurrentDurationLeft <= 0f)
                {
                    CurrentDurationLeft    = 0f;
                    _emptyReachedTimestamp = Time.time;
                    CooldownState          = CooldownStates.PauseOnEmpty;
                }
                break;

            case CooldownStates.PauseOnEmpty:
                if (Time.time - _emptyReachedTimestamp >= PauseOnEmptyDuration)
                {
                    CooldownState = CooldownStates.Refilling;
                }
                break;

            case CooldownStates.Refilling:
                CurrentDurationLeft += (RefillDuration * Time.deltaTime) / RefillDuration;
                if (CurrentDurationLeft >= RefillDuration)
                {
                    CurrentDurationLeft = ConsumptionDuration;
                    CooldownState       = CooldownStates.Idle;
                }
                break;
            }
        }