#Hey, im looking for info about events

1 messages · Page 1 of 1 (latest)

weak elbow
#

Code for my attempt to filter out events

public void OnAnimationStart(AnimatorStateInfo animatorStateInfo)
{
    _currentAnimatorStateInfo = animatorStateInfo;
    Debug.LogWarning($"Animation started: {_currentAnimatorStateInfo.fullPathHash}");
}
public void OnHardCancelStart()
{
    if (CanFireEvents() == false) { return; }
    HardCancelStart?.Invoke();
}
public void OnHardCancelStop()
{
    if (CanFireEvents() == false) { return; }
    HardCancelStop?.Invoke();
}
public void OnActive()
{
    if (CanFireEvents() == false) { return; }
    DealDamage?.Invoke();
}
public void OnRecovery()
{
    if (CanFireEvents() == false) { return; }
    Recovery?.Invoke();
}
public void OnAnimationEnd(AnimatorStateInfo animatorStateInfo)
{
    // Determine if the animation naturally completed (normalizedTime >= 1.0 means it finished)
    if (animatorStateInfo.normalizedTime >= 1.0f)
        AnimationEnd?.Invoke();

}
private bool CanFireEvents()
{
    var nextStateInfo = _animator.GetNextAnimatorStateInfo(0);
    // Check if next state exists
    var isNotTransitioning = nextStateInfo.fullPathHash == 0;
    // Check if the next state is the same as the current state from StateMachineBehaviour OnStateEnter
    var isNextState = nextStateInfo.fullPathHash == _currentAnimatorStateInfo.fullPathHash;
    var value = isNotTransitioning || isNextState;
    Debug.LogWarning($"CanFireEvents: {value}");
    return value;
}
#

This is what i was attempting

#

Animation events example

#

animator hierarchy

#

public override void Use(Caster caster)
{
    _caster = caster;

    _animatorListener = caster.Animator.GetComponent<AnimatorListener>();
    _animatorListener.Recovery += OnRecovery;
    _animatorListener.AnimationEnd += OnAnimationEnd;

    _movable = caster.owner.GetComponent<IMovable>();

    _hurtbox = caster.owner.GetComponentInChildren<Hurtbox>();
    _hurtbox.StartInvincibility();

    var statsHolder = caster.owner.GetComponentInChildren<StatsHolder>();
    _delayRatio = 1 / statsHolder.Stats["Attack Speed"].Value;

    StartDash();
}

#

Example of usage of the animation events, ofc when cancelling and ending animation im clearing the events

#

If you see this message, noone have written anything

weak elbow
#

@tribal nova

tribal nova
#

I feel like you're over complicating things