Pedro Gomes 81f2ac424e Insane update
Abilities:

- area of effect ability with impact event/chain reaction type added
- melee slash timing bugfix
- melee slash VFX added
- blizzard (second mage ability) added
- holy circle (ultimate priest ability) added
- consecration (ultimate knight ability) added
- whirling axes (second barbarian ability) added
- glacial bomb (ultimate mage ability) added
- ice shard (first mage ability) added

Others:

- aoe location snapshot on cast mechanic added
- reduced realtime shadows on rifthunters inn
2024-07-04 21:27:15 +01:00

113 lines
3.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class CastBarHandler : MonoBehaviour
{
#region Singleton
private static CastBarHandler _instance;
// Public reference to the singleton instance
public static CastBarHandler Instance
{
get
{
// If the instance doesn't exist, try to find it in the scene
if (_instance == null)
{
_instance = FindObjectOfType<CastBarHandler>();
// If it's still null, create a new GameObject and add the component
if (_instance == null)
{
GameObject singletonObject = new GameObject(typeof(CastBarHandler).Name);
_instance = singletonObject.AddComponent<CastBarHandler>();
}
}
return _instance;
}
}
#endregion
public GameObject castBar;
public Image imageToFill;
public float timer;
public float currentCastTime;
public BaseAbility currentAbility;
float startFill;
float endFill;
public UnityEvent<bool> OnCastingStateChanged = new UnityEvent<bool>();
Action currentlyWaitingAbilityExecution;
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(gameObject);
return;
}
// If this is the first instance, set it as the singleton
_instance = this;
DontDestroyOnLoad(gameObject);
}
private void Start()
{
ToggleCastBarVisibility(false);
}
public void ShowCastBar(BaseAbility ability, Action abilityExecution)
{
currentlyWaitingAbilityExecution = abilityExecution;
currentAbility = ability;
currentCastTime = ability.castTime;
StartCoroutine(FillImageOverTime(ability.castTime + 0.01f));
}
IEnumerator FillImageOverTime(float castTime)
{
ToggleCastBarVisibility(true);
timer = 0f;
startFill = 0f;
endFill = 1f;
imageToFill.fillAmount = startFill;
while (timer < castTime)
{
float fillAmount = Mathf.Lerp(startFill, endFill, timer / castTime);
imageToFill.fillAmount = fillAmount;
timer += Time.deltaTime;
yield return null;
}
// Ensure fillAmount is exactly 1 at the end
imageToFill.fillAmount = endFill;
ToggleCastBarVisibility(false);
}
private void ToggleCastBarVisibility(bool isVisible)
{
castBar.SetActive(isVisible);
OnCastingStateChanged.Invoke(isVisible);
}
public void ExecuteQueuedCastOnAnimationEvent()
{
Debug.Log("$$Executing queued melee before null check");
if (currentlyWaitingAbilityExecution == null) return;
Debug.Log("$$Executing queued melee after check");
currentlyWaitingAbilityExecution.Invoke();
}
}