feat: 在Unity内支持直接调整音频文件进行混音
This commit is contained in:
@@ -21,10 +21,13 @@ namespace OCES
|
||||
[CanBeNull]
|
||||
internal T LoadSync<T>(string path) where T : Object
|
||||
{
|
||||
|
||||
#if !AUDIO_MIXING
|
||||
if (this.m_cachedObjects.TryGetValue(path, out Object cachedObject))
|
||||
{
|
||||
return cachedObject as T;
|
||||
}
|
||||
#endif
|
||||
|
||||
T newObject;
|
||||
if (this.m_assetProvider is not null)
|
||||
@@ -36,8 +39,10 @@ namespace OCES
|
||||
newObject = Resources.Load<T>(path);
|
||||
Debug.LogWarning($"[ResourceLoader] No IAssetProvider set, falling back to Resources.Load for '{path}'");
|
||||
}
|
||||
|
||||
|
||||
#if !AUDIO_MIXING
|
||||
this.m_cachedObjects.Add(path, newObject);
|
||||
#endif
|
||||
return newObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
|
||||
namespace OCES.Audio.HandWritten.Editor
|
||||
{
|
||||
public static class MixingHelper
|
||||
{
|
||||
static readonly List<NamedBuildTarget> s_selectedBuildTargets = new()
|
||||
{
|
||||
NamedBuildTarget.Android,
|
||||
NamedBuildTarget.iOS,
|
||||
NamedBuildTarget.Standalone,
|
||||
};
|
||||
|
||||
static readonly AudioExtendSettings s_audioExtendSettings = AssetDatabase.LoadAssetAtPath<AudioExtendSettings>(AssetDatabase.GUIDToAssetPath("de80878c933394e2da0966a1466fd793"));
|
||||
|
||||
[MenuItem("Tools/OCES/Audio/Enable Mixing")]
|
||||
public static void EnableMixing()
|
||||
{
|
||||
if (s_audioExtendSettings is not null && s_audioExtendSettings.useAssetBundle)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Mixing", "已启用Asset Bundle。\n对音频文件的调整不会生效。", "好吧");
|
||||
}
|
||||
|
||||
foreach (NamedBuildTarget buildTarget in s_selectedBuildTargets)
|
||||
{
|
||||
PlayerSettings.GetScriptingDefineSymbols(buildTarget, out string[] defineArray);
|
||||
List<string> defineList = defineArray.ToList();
|
||||
|
||||
if (!defineArray.Contains("AUDIO_MIXING"))
|
||||
{
|
||||
defineList.Add("AUDIO_MIXING");
|
||||
PlayerSettings.SetScriptingDefineSymbols(buildTarget, defineList.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/OCES/Audio/Disable Mixing")]
|
||||
public static void DisableMixing()
|
||||
{
|
||||
foreach (NamedBuildTarget buildTarget in s_selectedBuildTargets)
|
||||
{
|
||||
PlayerSettings.GetScriptingDefineSymbols(buildTarget, out string[] defineArray);
|
||||
List<string> defineList = defineArray.ToList();
|
||||
|
||||
if (defineList.Contains("AUDIO_MIXING"))
|
||||
{
|
||||
defineList.Remove("AUDIO_MIXING");
|
||||
PlayerSettings.SetScriptingDefineSymbols(buildTarget, defineList.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 388d2124804048c1a9ea3c403820b443
|
||||
timeCreated: 1779159928
|
||||
Reference in New Issue
Block a user