78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AbilityBindInstance : MonoBehaviour
|
|
{
|
|
public GameKey gameKey;
|
|
|
|
public bool isAlphaKey = true;
|
|
|
|
[SerializeField] private GameEventListener_AbilityKeyBinder onAbilityKeyBinderSpawned;
|
|
public TMP_Text bind;
|
|
public TMP_Text manaCost;
|
|
public TMP_Text cooldown_Text;
|
|
public Image icon;
|
|
public GameObject noMana;
|
|
public GameObject pressed;
|
|
public Image coolDown;
|
|
|
|
[Header("Set by Code:")]
|
|
public AbilityKeyBinder abilityKeyBinder;
|
|
|
|
private void Awake()
|
|
{
|
|
onAbilityKeyBinderSpawned.Response.AddListener(InitializeAbilityBindInstance);
|
|
}
|
|
|
|
public void InitializeAbilityBindInstance(AbilityKeyBinder abilityKeyBinder)
|
|
{
|
|
if (abilityKeyBinder.GameKey != gameKey) return;
|
|
|
|
this.abilityKeyBinder = abilityKeyBinder;
|
|
string keyName = gameKey.keyCode.ToString();
|
|
//alpha
|
|
if (isAlphaKey)
|
|
keyName = keyName.Remove(0, 5);
|
|
this.bind.text = keyName;
|
|
this.manaCost.text = abilityKeyBinder.Ability.manaCost.ToString();
|
|
if (cooldown_Text != null)
|
|
this.cooldown_Text.text = abilityKeyBinder.Ability.cooldown.ToString();
|
|
this.icon.sprite = abilityKeyBinder.Ability.Icon;
|
|
noMana.SetActive(false);
|
|
pressed.SetActive(false);
|
|
coolDown.fillAmount = 1;
|
|
coolDown.gameObject.SetActive(false);
|
|
|
|
abilityKeyBinder.SetupAbilityBindInstance(this);
|
|
}
|
|
|
|
public void StartCooldownTrackerUI()
|
|
{
|
|
StartCoroutine(UIAbilityCooldownTracking());
|
|
}
|
|
|
|
float cooldownTime;
|
|
float elapsedTime;
|
|
IEnumerator UIAbilityCooldownTracking()
|
|
{
|
|
cooldownTime = abilityKeyBinder.Ability.cooldown;
|
|
elapsedTime = 0f;
|
|
|
|
coolDown.fillAmount = 1f;
|
|
coolDown.gameObject.SetActive(true);
|
|
|
|
while (elapsedTime < cooldownTime)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
coolDown.fillAmount = 1f - (elapsedTime / cooldownTime);
|
|
yield return null;
|
|
}
|
|
|
|
coolDown.fillAmount = 0f;
|
|
coolDown.gameObject.SetActive(false);
|
|
}
|
|
}
|