AudioCore0.11
This commit is contained in:
@@ -4,29 +4,21 @@ using UnityEngine;
|
||||
public class VoicePlayer
|
||||
{
|
||||
private AudioSourcePool audioSourcePool;
|
||||
private AudioSource currentSource; // 当前正在播放的 AudioSource
|
||||
Coroutine myCoroutine;
|
||||
private AudioSource currentSource;
|
||||
private Coroutine myCoroutine;
|
||||
|
||||
public VoicePlayer(AudioSourcePool audioSourcePool)
|
||||
{
|
||||
this.audioSourcePool = audioSourcePool;
|
||||
}
|
||||
|
||||
/*public override void Play(AudioClip clip, float volume = 1)
|
||||
{
|
||||
// 停止当前正在播放的语音
|
||||
Stop();
|
||||
|
||||
currentSource = audioSourcePool.GetAudioSource("Voice");
|
||||
if (currentSource == null) return;
|
||||
|
||||
currentSource.clip = clip;
|
||||
currentSource.volume = volume;
|
||||
currentSource.Play();
|
||||
}
|
||||
*/
|
||||
|
||||
// 播放语音
|
||||
/// <summary>
|
||||
/// 播放语音
|
||||
/// </summary>
|
||||
/// <param name="clip">音频</param>
|
||||
/// <param name="volume">音量</param>
|
||||
/// <param name="onComplete">结束行为</param>
|
||||
/// <param name="delayOnComplete">延迟结束行为时间</param>
|
||||
public void Play(AudioClip clip, float volume = 1f, System.Action onComplete = null, float delayOnComplete = 0f)
|
||||
{
|
||||
// 停止当前正在播放的语音与旧协程
|
||||
@@ -47,7 +39,9 @@ public class VoicePlayer
|
||||
myCoroutine = CoroutineHelper.StartCoroutine(PlayVoiceCoroutine(currentSource, delayOnComplete, onComplete));
|
||||
}
|
||||
|
||||
// 停止语音
|
||||
/// <summary>
|
||||
/// 停止语音
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
if (currentSource != null && currentSource.isPlaying)
|
||||
@@ -58,7 +52,13 @@ public class VoicePlayer
|
||||
}
|
||||
}
|
||||
|
||||
// 播放语音的协程
|
||||
/// <summary>
|
||||
/// 播放语音的协程
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="delayOnComplete"></param>
|
||||
/// <param name="onComplete"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerator PlayVoiceCoroutine(AudioSource source, float delayOnComplete, System.Action onComplete)
|
||||
{
|
||||
yield return new WaitForSeconds(source.clip.length+delayOnComplete);
|
||||
|
||||
Reference in New Issue
Block a user