您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

83 行
1.8 KiB

using UnityEngine;
namespace AxelF {
public enum EnvelopeMode {
None,
Exact,
Min,
Max
}
[System.Serializable]
public struct Envelope {
internal enum Cadence {
Snappy,
Normal,
Hesitant,
}
public static readonly Envelope instant = new Envelope {
attackTime = 0f,
attackValue = 1f,
releaseTime = 0f,
releaseValue = 0f,
sustainValue = 1f
};
public float attackTime;
internal float attackValue;
internal Cadence attackCadence;
public float releaseTime;
internal float releaseValue;
public float sustainValue;
public void SetAttack(float t) {
attackTime = t;
attackValue = 0f;
attackCadence =
t <= 1f ? Cadence.Snappy :
t <= 10f ? Cadence.Normal :
Cadence.Hesitant;
}
public float GetAttackValue() {
return attackValue;
}
public void SetRelease(float t) {
releaseTime = t;
releaseValue = 0f;
}
public float GetReleaseValue() {
return releaseValue;
}
public float GetValue() {
float a = attackValue;
float r = releaseValue;
if (attackCadence == Cadence.Snappy)
a = (a - 1f) * (a - 1f) * (a - 1f) + 1f;
else if (attackCadence == Cadence.Hesitant)
a = a * a;
r = 1f - ((r - 1f) * (r - 1f) * (r - 1f) + 1f);
return a * r * sustainValue;
}
public float UpdateAttack(float dt) {
float speed = attackTime > 0f ? 1f / attackTime : Mathf.Infinity;
return attackValue = Mathf.Clamp01(attackValue + dt * speed);
}
public float UpdateRelease(float dt) {
float speed = releaseTime > 0f ? 1f / releaseTime : Mathf.Infinity;
return releaseValue = Mathf.Clamp01(releaseValue + dt * speed);
}
}
} // AxelF