コード例 #1
0
ファイル: MMCooldown.cs プロジェクト: Baeckser/Astral-Revolve
 /// <summary>
 /// Starts consuming the cooldown object if possible
 /// </summary>
 public virtual void Start()
 {
     if (Ready())
     {
         CooldownState = CooldownStates.Consuming;
     }
 }
コード例 #2
0
ファイル: MMCooldown.cs プロジェクト: Baeckser/Astral-Revolve
 /// <summary>
 /// Stops consuming the object
 /// </summary>
 public virtual void Stop()
 {
     if (CooldownState == CooldownStates.Consuming)
     {
         CooldownState = CooldownStates.PauseOnEmpty;
     }
 }
コード例 #3
0
ファイル: MMCooldown.cs プロジェクト: Baeckser/Astral-Revolve
 /// <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
ファイル: MMCooldown.cs プロジェクト: Baeckser/Astral-Revolve
        /// <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;
            }
        }