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

33 lines
1.3 KiB
C#

#if INVECTOR_PLAYABLESANIMATOR
using InvectorCore;
using UnityEngine;
namespace Invector.vMelee
{
/// <summary>
/// Holds the rolled attack index for the PlayablesAnimator and exposes it as a PDM condition,
/// replacing the <c>animator.SetInteger("RandomAttack", ...)</c> parameter the Animator
/// Controller version of <see cref="vRandomAttackBehaviour"/> writes.
/// </summary>
/// <remarks>
/// A PDM context is rebuilt from its providers every tick, so a state behaviour cannot write a
/// value into it directly and expect it to survive. The value has to live on a component that
/// the context collects from, which is what this is. Attach it next to the PlayablesAnimator and
/// reference <c>vPlayablesRandomAttack.RandomAttack</c> in the attack rows' conditions.
/// </remarks>
[vClassHeader("Playables Random Attack", "Rolled by vRandomAttackBehaviourPDM on state enter.")]
public class vPlayablesRandomAttack : vMonoBehaviour
{
[SerializeField, vReadOnly] private int randomAttack;
[ExposeCondition("Index rolled by vRandomAttackBehaviourPDM when an attack state starts.")]
public float RandomAttack => randomAttack;
public void Roll(int attackCount)
{
randomAttack = attackCount > 0 ? Random.Range(0, attackCount) : 0;
}
}
}
#endif