Ejemplo n.º 1
0
 /// <summary>
 /// Starts consuming the cooldown object if possible
 /// </summary>
 public virtual void Start()
 {
     if (Ready())
     {
         CooldownState = CooldownStates.Consuming;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Stops consuming the object
 /// </summary>
 public virtual void Stop()
 {
     if (CooldownState == CooldownStates.Consuming)
     {
         CooldownState = CooldownStates.PauseOnEmpty;
     }
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
            }
        }