【m】优化音频管理器

This commit is contained in:
Han
2025-12-19 11:55:13 +08:00
parent 99e5409122
commit 3910229c5d
8 changed files with 70 additions and 37 deletions

View File

@@ -1,10 +1,11 @@
using UnityEngine;
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
namespace Stary.Evo.AudioCore
{
public class AudioSourcePool
public class AudioSourcePool: IDisposable
{
private Dictionary<string, Queue<GameObject>> poolDict = new Dictionary<string, Queue<GameObject>>();
private GameObject poolObject;
@@ -22,9 +23,8 @@ namespace Stary.Evo.AudioCore
// 如果不存在,创建一个新对象
poolObject = new GameObject("AudioSourcePool");
}
CoroutineHelper.SetRunner();
// 初始化 Voice 池(初始 1 个,可动态扩展
// 初始化 Voice 池(只有 1 个)
poolDict["Voice"] = new Queue<GameObject>();
CreateAudioSource("Voice");
@@ -35,7 +35,7 @@ namespace Stary.Evo.AudioCore
CreateAudioSource("Music");
}
// 初始化 SFX 池(初始 4 个,可动态扩展)
// 初始化 SFX 池(初始 1 个,可动态扩展)
poolDict["SFX"] = new Queue<GameObject>();
CreateAudioSource("SFX");
}
@@ -135,5 +135,14 @@ namespace Stary.Evo.AudioCore
}
poolDict.Clear();
}
public void Dispose()
{
if (poolObject != null)
{
GameObject.Destroy(poolObject);
}
poolDict.Clear();
}
}
}