【m】增添设置3D音频功能
This commit is contained in:
@@ -21,7 +21,9 @@ namespace Stary.Evo.AudioCore
|
||||
/// 播放语音
|
||||
/// </summary>
|
||||
/// <param name="audioData">{[clip:音频], [volume:音量],
|
||||
/// [onComplete:回调行为], [delayOnCompleteTime:延迟回调执行的时间]}</param>
|
||||
/// [onComplete:回调行为], [delayOnCompleteTime:延迟回调执行的时间],
|
||||
/// [is3DAudio:是否3D音频], [audio3DPosition:3D音频位置],
|
||||
/// [audio3DMaxDistance:3D音频最大距离]}</param>
|
||||
public override void Play(AudioData audioData)
|
||||
{
|
||||
// 停止当前正在播放的语音与旧协程,或旧异步
|
||||
@@ -39,6 +41,31 @@ namespace Stary.Evo.AudioCore
|
||||
|
||||
currentSource.clip = audioData.clip;
|
||||
currentSource.volume = audioData.volume;
|
||||
|
||||
// 设置2D与3D音频
|
||||
if (audioData.is3DAudio)
|
||||
{
|
||||
currentSource.transform.position = audioData.audio3DPosition;
|
||||
currentSource.spatialBlend = 1;
|
||||
currentSource.minDistance = 1f;
|
||||
if (audioData.audio3DMaxDistance != 0)
|
||||
{
|
||||
currentSource.maxDistance = audioData.audio3DMaxDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 默认3D最大距离为3米
|
||||
currentSource.maxDistance = 3f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSource.transform.position = Vector3.zero;
|
||||
currentSource.spatialBlend = 0;
|
||||
currentSource.minDistance = 1f;
|
||||
currentSource.maxDistance = 500f;
|
||||
}
|
||||
|
||||
currentSource.Play();
|
||||
|
||||
// 使用协程处理延迟和回调
|
||||
@@ -76,9 +103,11 @@ namespace Stary.Evo.AudioCore
|
||||
/// <summary>
|
||||
/// 异步播放语音
|
||||
/// </summary>
|
||||
/// <param name="audioClip"></param>
|
||||
/// <param name="volume"></param>
|
||||
public async Task Play(AudioClip audioClip, float volume)
|
||||
/// <param name="audioData">{[clip:音频], [volume:音量],
|
||||
/// [onComplete:回调行为], [delayOnCompleteTime:延迟回调执行的时间],
|
||||
/// [is3DAudio:是否3D音频], [audio3DPosition:3D音频位置],
|
||||
/// [audio3DMaxDistance:3D音频最大距离]}</param>
|
||||
public async Task PlayAsync(AudioData audioData)
|
||||
{
|
||||
// 停止当前正在播放的语音与旧协程,或旧异步
|
||||
Stop();
|
||||
@@ -86,12 +115,35 @@ namespace Stary.Evo.AudioCore
|
||||
currentSource = audioSourcePool.GetAudioSource("Voice");
|
||||
if (currentSource == null) return;
|
||||
|
||||
currentSource.clip = audioClip;
|
||||
currentSource.volume = volume;
|
||||
currentSource.clip = audioData.clip;
|
||||
currentSource.volume = audioData.volume;
|
||||
|
||||
// 设置2D与3D音频
|
||||
if (audioData.is3DAudio)
|
||||
{
|
||||
currentSource.transform.position = audioData.audio3DPosition;
|
||||
currentSource.spatialBlend = 1;
|
||||
currentSource.minDistance = 1f;
|
||||
if (audioData.audio3DMaxDistance != 0)
|
||||
{
|
||||
currentSource.maxDistance = audioData.audio3DMaxDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 默认3D最大距离为3米
|
||||
currentSource.maxDistance = 3f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSource.transform.position = Vector3.zero;
|
||||
currentSource.spatialBlend = 0;
|
||||
currentSource.minDistance = 1f;
|
||||
currentSource.maxDistance = 500f;
|
||||
}
|
||||
currentSource.Play();
|
||||
|
||||
cancelTokenSource = new CancellationTokenSource();
|
||||
await Task.Delay(TimeSpan.FromSeconds(audioClip.length),cancelTokenSource.Token);
|
||||
await Task.Delay(TimeSpan.FromSeconds(audioData.clip.length),cancelTokenSource.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user