コード例 #1
0
        private void Update()
        {
            if (!GameData.Instance || PlayerControl.LocalPlayer?.Data == null || KillButtonManager == null)
            {
                EndEffect(false);

                ApplyCooldown(0F);

                return;
            }

            if (KillButtonManager.transform.localPosition.x > 0F)
            {
                Vector3 vector = KillButtonManager.transform.localPosition;
                vector.x = (vector.x + 1.3F) * -1;

                vector += new Vector3(PositionOffset.x, PositionOffset.y);

                KillButtonManager.transform.localPosition = vector;
            }

            if (IsCoolingDown && (IsEffectActive || Visible && PlayerControl.LocalPlayer.CanMove))
            {
                CooldownTime -= Time.deltaTime;

                if (!IsCoolingDown)
                {
                    if (IsEffectActive)
                    {
                        EndEffect();
                    }
                    else
                    {
                        OnCooldownEnd?.SafeInvoke(this, EventArgs.Empty);
                    }
                }
            }

            if (HudVisible)
            {
                OnUpdate?.SafeInvoke(this, EventArgs.Empty);             // Implementing code can control visibility and appearance.
            }
            if (IsDisposed)
            {
                return;             // Dispose may be called during OnUpdate, resulting exceptions.
            }
            KillButtonManager.gameObject.SetActive(HudVisible && Visible);
            KillButtonManager.renderer.enabled  = HudVisible && Visible;
            KillButtonManager.TimerText.enabled = HudVisible && Visible && IsCoolingDown;

            KillButtonManager.renderer.color = IsCoolingDown || !Clickable ? Palette.DisabledColor : Palette.EnabledColor;

            //KillButtonManager.renderer.material.SetFloat("_Desat", 0F);
            KillButtonManager.renderer.material.SetFloat("_Desat", Clickable ? 0F : 1F);

            //KillButtonManager.SetCoolDown(Timer, MaxTimer);
            UpdateCooldown();
        }
コード例 #2
0
 /// <summary>
 /// Decreases the skills cooldown
 /// </summary>
 /// <param name="time">Time to decrement skill</param>
 public void DoCooldown(float time)
 {
     if (_currCooldown > 0)
     {
         _currCooldown -= time;
         if (_currCooldown <= 0)
         {
             OnCooldownEnd?.Invoke();
             _currCooldown = 0;
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Sets the button on cooldown. Defaults to <see cref="CooldownDuration"/>.
        /// </summary>
        /// <remarks>Raises the <see cref="OnCooldownStart"/> or <see cref="OnCooldownEnd"/> events depending on whether the button wasn't or was on cooldown, respectively.</remarks>
        /// <remarks>Ends effect duration if the effect is active when called.</remarks>
        /// <param name="customCooldown">Optional custom cooldown duration (does not affect <see cref="CooldownDuration"/>, may be longer or shorter than <see cref="CooldownDuration"/>)</param>
        public void ApplyCooldown(float?customCooldown = null)
        {
            if (IsEffectActive)
            {
                EndEffect(false);
            }

            bool wasCoolingDown = IsCoolingDown;

            CooldownTime = customCooldown ?? CooldownDuration;

            if (!wasCoolingDown && IsCoolingDown)
            {
                OnCooldownStart?.SafeInvoke(this, EventArgs.Empty, nameof(OnCooldownStart));
            }
            else if (wasCoolingDown && !IsCoolingDown)
            {
                OnCooldownEnd?.SafeInvoke(this, EventArgs.Empty, nameof(OnCooldownEnd));
            }
        }
コード例 #4
0
    /// <summary>
    /// Reduces cooldowns until they are 0.
    /// </summary>
    protected virtual void ReduceCooldown()
    {
        if (AttackCooldown > 0f)
        {
            _attackCooldown -= Time.fixedDeltaTime;
        }
        else if (AttackCooldown <= 0f && AttackCooldown != null)
        {
            OnCooldownEnd?.Invoke();
            _attackCooldown = null;
        }

        if (BlockCooldown > 0f && CurrentState is Idle)
        {
            BlockCooldown -= Time.fixedDeltaTime;
        }
        else if (BlockCooldown <= 0f && BlockCooldown != null)
        {
            BlockCooldown = null;
        }
    }
コード例 #5
0
 /// <summary>
 /// Invoke the end of cooldown for the current weapon when cooldown timer finishes
 /// </summary>
 public void InvokeCooldownEnd() => OnCooldownEnd?.Invoke();