Files
beyond/Assets/ThirdParty/PlayMaker/Actions/Audio/SetAudioPitch.cs
2024-11-20 15:21:28 +01:00

59 lines
1.1 KiB
C#

// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Audio)]
[Tooltip("Sets the Pitch of the Audio Clip played by the AudioSource component on a Game Object.")]
public class SetAudioPitch : ComponentAction<AudioSource>
{
[RequiredField]
[CheckForComponent(typeof(AudioSource))]
public FsmOwnerDefault gameObject;
public FsmFloat pitch;
public bool everyFrame;
public override void Reset()
{
gameObject = null;
pitch = 1;
everyFrame = false;
}
public override void OnEnter()
{
DoSetAudioPitch();
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate ()
{
DoSetAudioPitch();
}
void DoSetAudioPitch()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (UpdateCache(go))
{
if (!pitch.IsNone)
{
audio.pitch = pitch.Value;
}
}
}
#if UNITY_EDITOR
public override string AutoName()
{
return ActionHelpers.AutoName(this, pitch);
}
#endif
}
}