feat: 在Unity内支持直接调整音频文件进行混音

This commit is contained in:
2026-05-19 12:04:31 +08:00
parent 67de857f8c
commit 9dc4228b5c
4 changed files with 77 additions and 12 deletions
@@ -23,11 +23,10 @@ namespace OCES
{
if (typeof(T) != typeof(AudioClip))
{
Debug.LogError($"[StreamingAssetProvider] Load<{typeof(T).Name}> 不支持,仅支持 AudioClip");
return null;
return Resources.Load<T>(path);
}
string fullPath = Path.Combine(Application.streamingAssetsPath, path);
string fullPath = Path.Combine("Audios", Application.streamingAssetsPath, path) + ".wav";
if (!File.Exists(fullPath))
{
Debug.LogError($"[StreamingAssetProvider] 文件 {fullPath} 不存在。");
@@ -48,25 +47,26 @@ namespace OCES
{
if (typeof(T) != typeof(AudioClip))
{
Debug.LogError($"[StreamingAssetProvider] LoadAsync<{typeof(T).Name}> 不支持,仅支持 AudioClip");
onComplete?.Invoke(null);
ResourceRequest resourceRequest = Resources.LoadAsync<T>(path);
yield return resourceRequest;
onComplete?.Invoke(resourceRequest.asset as T);
yield break;
}
string fullPath = Path.Combine(Application.streamingAssetsPath, path);
string fullPath = Path.Combine("Audios", Application.streamingAssetsPath, path);
string url = "file://" + fullPath;
using UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.WAV);
yield return request.SendWebRequest();
using UnityWebRequest webRequest = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.WAV);
yield return webRequest.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
if (webRequest.result == UnityWebRequest.Result.Success)
{
AudioClip clip = DownloadHandlerAudioClip.GetContent(request);
AudioClip clip = DownloadHandlerAudioClip.GetContent(webRequest);
onComplete?.Invoke(clip as T);
}
else
{
Debug.LogError($"[StreamingAssetProvider] 加载失败: {url}, 错误: {request.error}");
Debug.LogError($"[StreamingAssetProvider] 加载失败: {url}, 错误: {webRequest.error}");
onComplete?.Invoke(null);
}
}