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
@@ -26,6 +26,13 @@ namespace OCES.Audio
// 公开接口
// ─────────────────────────────────────────────
public void Play(uint audioId)
{
AudioObject obj = this.m_audioObjects.QueryById(audioId);
if (obj != null)
Play(obj);
}
public void Play(AudioObject audioObject)
{
this.m_scheduler.TryPlay(audioObject);
@@ -33,14 +40,36 @@ namespace OCES.Audio
public void Play(int audioId)
{
AudioObject obj = this.m_audioObjects.QueryById((uint)audioId);
if (obj != null)
this.m_scheduler.TryPlay(obj);
Play((uint)audioId);
}
[Obsolete("Use Play(uint) instead")]
public void Play(string audioName)
{
// TODO: 按文件名播放
if (!AudioObjectDefinitions.NameToId.TryGetValue(audioName, out uint id))
{
Debug.LogWarning($"[Audio] Name '{audioName}' not found.");
return;
}
if (AudioObjectDefinitions.AmbiguousNames.Contains(audioName))
{
Debug.LogWarning(
$"[AudioSystem] Name '{audioName}' is ambiguous. Using first matched ID: {id}. " +
"Use ID instead to avoid unexpected behavior."
);
}
if (AudioObjectDefinitions.SharedIdNames.Contains(audioName))
{
Debug.LogWarning(
$"[AudioSystem] Name '{audioName}' is a item of a container AudioObject (ID: {id}). " +
"Use ID instead to avoid unexpected behavior."
);
}
Play(id);
}
public void SetLowpass(bool enable)