feat: implement audio object definitions and refactor audio system

- Add AudioObjectDefinitions.cs with name-to-ID mappings and ambiguity detection
- Update AudioSystem.cs to support Play(uint) and deprecated Play(string) with warnings
- Rename PitchStepManager to PitchStepResolver and update all references
- Refactor generated code to use 'this.' prefix and foreach loops
- Remove TestEnum from audio enums and IDs
- Update SampleScene.unity to use new AudioSystem namespace and rain sound parameter
- Optimize binary serialization in generated audio classes
This commit is contained in:
2026-04-02 14:31:46 +08:00
parent d824d65549
commit 7fc3282e80
18 changed files with 208 additions and 32 deletions
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using UnityEngine;
namespace OCES.Audio
{
public class PitchStepResolver
{
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);
}
}
}