Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

49 行
1.5 KiB

using System.Collections;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Events;
namespace GameplayIngredients.Actions
{
[Callable("Audio", "Actions/ic-action-audio.png")]
public class AudioMixParameterCurveAction : ActionBase
{
public AudioMixer AudioMixer;
public string Parameter = "Parameter";
public AnimationCurve Curve = AnimationCurve.Linear(0,0,1,1);
public float InterpDuration = 2.0f;
public UnityEvent OnInterpComplete;
Coroutine m_Coroutine;
public override void Execute(GameObject instigator = null)
{
if (m_Coroutine != null)
StopCoroutine(m_Coroutine);
m_Coroutine = StartCoroutine(InterpParameterCoroutine(AudioMixer, InterpDuration, Parameter, Curve, OnInterpComplete));
}
IEnumerator InterpParameterCoroutine(AudioMixer mixer, float duration, string parameter, AnimationCurve curve, UnityEvent onInterpComplete)
{
float t = 0.0f;
while (t < 1.0f)
{
mixer.SetFloat(parameter, curve.Evaluate(t));
yield return new WaitForEndOfFrame();
t += Time.deltaTime / duration;
}
mixer.SetFloat(parameter, curve.Evaluate(1.0f));
yield return new WaitForEndOfFrame();
onInterpComplete.Invoke();
}
public override string GetDefaultName()
{
return $"Set Mixer Curve Param:'{Parameter}' ({InterpDuration})s";
}
}
}