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(); }
/// <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)); } }