refactor: 使用ActiveSound对象传递音高和音量参数
This commit is contained in:
@@ -212,7 +212,7 @@ namespace OCES.Audio
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 连续容器播放协程(Random / Sequence 持续模式)
|
/// 连续容器播放协程(Random / Sequence 持续模式)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IEnumerator PlayContainerContinuous(AudioSource source, AudioObject audioObject, ActiveSound chainActive, int startIndex, float pitch, float volume)
|
IEnumerator PlayContainerContinuous(AudioSource source, AudioObject audioObject, ActiveSound chainActive, int startIndex)
|
||||||
{
|
{
|
||||||
bool isRandom = audioObject.ContainerType == ContainerType.Random;
|
bool isRandom = audioObject.ContainerType == ContainerType.Random;
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ namespace OCES.Audio
|
|||||||
limitRepetition);
|
limitRepetition);
|
||||||
|
|
||||||
// 配置并播放
|
// 配置并播放
|
||||||
if (!SetupSource(source, audioObject, pitch, volume,index))
|
if (!SetupSource(source, chainActive, index))
|
||||||
{
|
{
|
||||||
Debug.LogError($"音频文件未找到:{audioObject.Name[index]}");
|
Debug.LogError($"音频文件未找到:{audioObject.Name[index]}");
|
||||||
yield break;
|
yield break;
|
||||||
@@ -339,8 +339,9 @@ namespace OCES.Audio
|
|||||||
return this.m_sfxGroup;
|
return this.m_sfxGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetupSource(AudioSource source, AudioObject audioObject, float pitch, float volume, int clipIndex = 0)
|
bool SetupSource(AudioSource source, ActiveSound activeSound, int clipIndex = 0)
|
||||||
{
|
{
|
||||||
|
AudioObject audioObject = activeSound.AudioObject;
|
||||||
AudioClip clip = Resources.Load<AudioClip>($"Audios/{audioObject.Name[clipIndex]}"); // TODO 抽象同一资源加载接口
|
AudioClip clip = Resources.Load<AudioClip>($"Audios/{audioObject.Name[clipIndex]}"); // TODO 抽象同一资源加载接口
|
||||||
if (!clip)
|
if (!clip)
|
||||||
{
|
{
|
||||||
@@ -352,8 +353,8 @@ namespace OCES.Audio
|
|||||||
source.loop = audioObject.LoopCount < 0;
|
source.loop = audioObject.LoopCount < 0;
|
||||||
source.priority = audioObject.Priority;
|
source.priority = audioObject.Priority;
|
||||||
source.outputAudioMixerGroup = GetMixerGroup(audioObject.MixingType);
|
source.outputAudioMixerGroup = GetMixerGroup(audioObject.MixingType);
|
||||||
source.pitch = pitch;
|
source.pitch = activeSound.Pitch;
|
||||||
source.volume = volume;
|
source.volume = activeSound.Volume;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -393,10 +394,10 @@ namespace OCES.Audio
|
|||||||
AudioObject = audioObject,
|
AudioObject = audioObject,
|
||||||
Pitch = pitch,
|
Pitch = pitch,
|
||||||
Volume = volume,
|
Volume = volume,
|
||||||
State = ActiveSoundState.Playing
|
State = ActiveSoundState.Playing,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!SetupSource(source, audioObject, pitch, volume, i))
|
if (!SetupSource(source, child, i))
|
||||||
{
|
{
|
||||||
this.m_pool.ReturnToPool(source.gameObject);
|
this.m_pool.ReturnToPool(source.gameObject);
|
||||||
continue;
|
continue;
|
||||||
@@ -432,7 +433,7 @@ namespace OCES.Audio
|
|||||||
int start = audioObject.ContainerType == ContainerType.Random ? -1 : 0;
|
int start = audioObject.ContainerType == ContainerType.Random ? -1 : 0;
|
||||||
|
|
||||||
active.Coroutine = StartCoroutine(
|
active.Coroutine = StartCoroutine(
|
||||||
PlayContainerContinuous(sourceSingle, audioObject, active, start, pitch, volume)
|
PlayContainerContinuous(sourceSingle, audioObject, active, start)
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -448,9 +449,9 @@ namespace OCES.Audio
|
|||||||
_ => 0
|
_ => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!SetupSource(sourceSingle, audioObject, pitch, volume, index))
|
if (!SetupSource(sourceSingle, active, index))
|
||||||
{
|
{
|
||||||
m_pool.ReturnToPool(sourceSingle.gameObject);
|
this.m_pool.ReturnToPool(sourceSingle.gameObject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user