97 lines
3.1 KiB
C#
97 lines
3.1 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 healthCost;
|
|
public TMP_Text cooldown_Text;
|
|
public Image icon;
|
|
public GameObject noMana;
|
|
public GameObject noHealth;
|
|
public GameObject healthCostGO;
|
|
public GameObject pressed;
|
|
public Image coolDown;
|
|
public GameObject locked;
|
|
|
|
[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.GetFinalManaCost(abilityKeyBinder.Mana).ToString("F0");
|
|
healthCostGO.SetActive(abilityKeyBinder.Ability.GetFinalHealthCost(abilityKeyBinder.Health) > 0);
|
|
this.healthCost.text = abilityKeyBinder.Ability.GetFinalHealthCost(abilityKeyBinder.Health).ToString("F0");
|
|
if (cooldown_Text != null)
|
|
this.cooldown_Text.text = abilityKeyBinder.Ability.cooldown.ToString();
|
|
this.icon.sprite = abilityKeyBinder.Ability.Icon;
|
|
noMana.SetActive(false);
|
|
noHealth.SetActive(false);
|
|
pressed.SetActive(false);
|
|
coolDown.fillAmount = 1;
|
|
coolDown.gameObject.SetActive(false);
|
|
|
|
abilityKeyBinder.SetupAbilityBindInstance(this);
|
|
}
|
|
public void ForceUpdateOnComboAbility(BaseAbility currentComboAbility)
|
|
{
|
|
this.manaCost.text = currentComboAbility.GetFinalManaCost(abilityKeyBinder.Mana).ToString("F0");
|
|
healthCostGO.SetActive(currentComboAbility.GetFinalHealthCost(abilityKeyBinder.Health) > 0);
|
|
this.healthCost.text = currentComboAbility.GetFinalHealthCost(abilityKeyBinder.Health).ToString("F0");
|
|
this.icon.sprite = currentComboAbility.Icon;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public void SetUnlocked(bool unlocked)
|
|
{
|
|
locked.SetActive(!unlocked);
|
|
}
|
|
}
|