MythicalWar/Assets/Invector-3rdPersonController/Melee Combat/Scripts/MeleeWeapon/PlayablesBehaviours/vRandomAttackBehaviourPDM.cs

35 lines
1.1 KiB
C#

#if INVECTOR_PLAYABLESANIMATOR
using InvectorCore.Playables;
using UnityEngine;
namespace Invector.vMelee
{
/// <summary>
/// PlayablesAnimator counterpart of <see cref="vRandomAttackBehaviour"/>. Rolls the attack index
/// on state enter and stores it on <see cref="vPlayablesRandomAttack"/>, whose
/// <c>RandomAttack</c> member the PDM rows read as a condition.
/// </summary>
public class vRandomAttackBehaviourPDM : PlayablesStateBehaviour
{
public int attackCount;
public override void OnStateEnter(in PlayablesStateContext context)
{
if (context.Animator == null)
return;
vPlayablesRandomAttack holder = context.Animator.GetComponent<vPlayablesRandomAttack>();
if (holder == null)
{
Debug.LogWarning(
$"{nameof(vRandomAttackBehaviourPDM)} needs a {nameof(vPlayablesRandomAttack)} " +
$"on '{context.Animator.name}' to publish the rolled index.", context.Animator);
return;
}
holder.Roll(attackCount);
}
}
}
#endif