using System.ComponentModel;
using UnityEngine;
namespace Unity.VisualScripting
{
#if MODULE_ANIMATION_EXISTS
///
/// Called when an animation event points to TriggerAnimationEvent.
/// This version allows you to use the string parameter as the event name.
///
[UnitCategory("Events/Animation")]
[UnitShortTitle("Animation Event")]
[UnitTitle("Named Animation Event")]
[TypeIcon(typeof(Animation))]
[DisplayName("Visual Scripting Named Animation Event")]
public sealed class BoltNamedAnimationEvent : MachineEventUnit
{
protected override string hookName => EventHooks.AnimationEvent;
///
/// The name of the event. The event will only trigger if this value
/// is equal to the string parameter passed in the animation event.
///
[DoNotSerialize]
[PortLabelHidden]
public ValueInput name { get; private set; }
///
/// The float parameter passed to the event.
///
[DoNotSerialize]
[PortLabel("Float")]
public ValueOutput floatParameter { get; private set; }
///
/// The integer parameter passed to the function.
///
[DoNotSerialize]
[PortLabel("Integer")]
public ValueOutput intParameter { get; private set; }
///
/// The Unity object parameter passed to the function.
///
[DoNotSerialize]
[PortLabel("Object")]
public ValueOutput objectReferenceParameter { get; private set; }
protected override void Definition()
{
base.Definition();
name = ValueInput(nameof(name), string.Empty);
floatParameter = ValueOutput(nameof(floatParameter));
intParameter = ValueOutput(nameof(intParameter));
objectReferenceParameter = ValueOutput(nameof(objectReferenceParameter));
}
protected override bool ShouldTrigger(Flow flow, AnimationEvent animationEvent)
{
return CompareNames(flow, name, animationEvent.stringParameter);
}
protected override void AssignArguments(Flow flow, AnimationEvent animationEvent)
{
flow.SetValue(floatParameter, animationEvent.floatParameter);
flow.SetValue(intParameter, animationEvent.intParameter);
flow.SetValue(objectReferenceParameter, animationEvent.objectReferenceParameter);
}
}
#endif
}