first commit

This commit is contained in:
2026-03-20 17:55:53 +08:00
commit c5778c498b
328 changed files with 11867 additions and 0 deletions
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using UnityEngine;
namespace OCES.Audio
{
public class PitchStepManager
{
readonly Dictionary<uint, int> m_pitchStepCounts = new();
readonly Dictionary<uint, double> m_pitchStepLastTime = new();
internal float ResolvePitch(AudioObject audioObject, double time)
{
if (audioObject.PitchStep == 0 || audioObject.PitchStepThreshold == 0) //没配置PitchStep
{
return 1f;
}
// 超时了,或者没播过
if (!this.m_pitchStepLastTime.TryGetValue(audioObject.Id, out double lastPitchStepTime)
|| time - lastPitchStepTime > audioObject.PitchStepThreshold)
{
this.m_pitchStepCounts[audioObject.Id] = 0;
this.m_pitchStepLastTime[audioObject.Id] = time;
return 1f;
}
//命中了
int pitchStepCount = this.m_pitchStepCounts[audioObject.Id];
pitchStepCount = this.m_pitchStepCounts[audioObject.Id] = Mathf.Min(pitchStepCount + 1, audioObject.PitchStepLimit);
this.m_pitchStepLastTime[audioObject.Id] = time;
return Mathf.Pow(2, audioObject.PitchStep * pitchStepCount / 12f);
}
}
}