Hey there,
I wanted to reply to the already existing question about caching CooldownStore and Mana (Caching CD and Mana) but it is closed.
So I re-open it here.
I understand all that have been said there… anyway, I still feel like @psyconius.
I feel like I want to cache these components in order to be able to use them.
Would caching them in the AbilityData be a valid approach?
I mean something like this:
public class AbilityData
{
GameObject user;
IEnumerable<GameObject> targets;
Vector3 targetPoint;
Mana mana;
CooldownStore cooldownStore;
public AbilityData(GameObject user)
{
this.user = user;
mana = user.GetComponent<Mana>();
cooldownStore = user.GetComponent<CooldownStore>();
}
public CooldownStore CooldownStore { get => cooldownStore; }
public Mana Mana { get => mana; }
...
And then, when used:
public override void Use(GameObject user)
{
abilityData = new AbilityData(user);
if (abilityData.CooldownStore == null || abilityData.CooldownStore.GetRemainingTime(this) == 0)
{
if (abilityData.Mana != null && abilityData.Mana.CanCast(manaCost))
{
targetingStrategy.StartTargeting(abilityData, () => TargetAcquired(abilityData));
}
}
}
...
Any downside?
Thanks!
NB: of course, it means that enemies will have a cooldown store component and a mana component too. But this feel ok for me…