HartoukChartEditor/Assets/Script/Data/BPMGroup.cs

96 lines
3.4 KiB
C#
Raw Normal View History

using Unity.VisualScripting;
/// <summary>
/// BPM组单元用于储存对应时间组的物件速度变化与乐曲相关
/// </summary>
public class BPMGroup
{
/*BPM变换的机制
*BPM变换是一种用来完成适应中间有BPM变换的歌曲的一种机制
*BPM的基准BPM的比值使NoteSpeed得以变化
*BPM变换到比原定的数值更大时
*BPM变换到比原定的数值更小时
*
*Note划分组别
*使
*
*
*
*NoteSpeed以达到控制Note的效果
*NoteSpeed更新自身位置
*
*100
*/
/// <summary>
/// 当前BPM组的NoteSpeed
/// </summary>
public float CurrentNoteSpeed
{
get
{
if (CurrentBPM == 0) return 0;
//单位向量*基础速度*音符流速*BPM/基准BPM
return _noteStream * CurrentBPM * _baseSpeed / _baseBPM;
}
}
private float _noteStream;
private float _baseSpeed;
private float _baseBPM;
/// <summary>
/// 每拍的时间长度(秒)
/// </summary>
public float Beat
{
get
{
return CurrentBPM > 0 ? 60f / CurrentBPM : 0f;
}
}
/// <summary>
/// 音符相对当前BPM的抵达下落目标所需时间,单位:ms
/// </summary>
public float InitializeOffset
{
get
{
if (CurrentNoteSpeed == 0) return 0;
//到达目标点的时间
return TrackLength / CurrentNoteSpeed;
}
}
/// <summary>
/// 轨道长度,该值应当添加至游戏主控变成玩家偏好设置
/// </summary>
private float TrackLength;
public float CurrentBPM { set; get; }
public int GroupNum { get; }
public BPMGroup(float currentBPM, int groupNum, float noteStream, float baseSpeed, float baseBPM, float trackLength)
{
CurrentBPM = currentBPM;
GroupNum = groupNum;
_noteStream = noteStream;
_baseSpeed = baseSpeed;
_baseBPM = baseBPM;
TrackLength = trackLength;
}
public void UpdatePlayerSetting(float noteStream, float baseSpeed, float baseBPM, float trackLength)
{
_noteStream = noteStream;
_baseSpeed = baseSpeed;
_baseBPM = baseBPM;
TrackLength = trackLength;
}
public override string ToString()
{
return $"BPMGroup [Group: {GroupNum}]\n" +
$"BPM: {CurrentBPM}\n" +
$"Beat: {Beat:F3}s\n" +
$"NoteSpeed: {CurrentNoteSpeed:F2}\n" +
$"Stream: {_noteStream}\n" +
$"BaseSpeed: {_baseSpeed}\n" +
$"BaseBPM: {_baseBPM}\n" +
$"InitializeOffset:{InitializeOffset}\n"+
$"当前速度:{CurrentNoteSpeed}"
;
}
}