浏览代码

Tweaks to AudioSystem pt.1

/UI
Ciro Continisio 4 年前
当前提交
d7929a37
共有 4 个文件被更改,包括 17 次插入17 次删除
  1. 11
      UOP1_Project/Assets/Scripts/Audio/AudioCue.cs
  2. 6
      UOP1_Project/Assets/Scripts/Audio/AudioManager.cs
  3. 10
      UOP1_Project/Assets/Scripts/Audio/SoundEmitters/SoundEmitter.cs
  4. 7
      UOP1_Project/Assets/Scripts/Audio/SoundEmitters/SoundEmitterList.cs

11
UOP1_Project/Assets/Scripts/Audio/AudioCue.cs


StartCoroutine(PlayDelayed());
}
private void OnDisable()
{
_playOnStart = false;
}
//The wait allows the AudioManager to be ready for play requests
PlayAudioCue();
//This additional check prevents the AudioCue from playing if the object is disabled or the scene unloaded
//This prevents playing a looping AudioCue which then would be never stopped
if(_playOnStart)
PlayAudioCue();
}
public void PlayAudioCue()

6
UOP1_Project/Assets/Scripts/Audio/AudioManager.cs


soundEmitters[i].OnSoundFinishedPlaying += OnSoundEmitterFinishedPlaying;
}
}
else
{
Debug.LogWarning("Finishing an AudioCue was requested, but the AudioCue was not found.");
}
return isFound;
}

private void StopAndCleanEmitter(SoundEmitter soundEmitter)
{
if (soundEmitter.IsFinishing())
if(!soundEmitter.IsLooping())
soundEmitter.OnSoundFinishedPlaying -= OnSoundEmitterFinishedPlaying;
soundEmitter.Stop();

10
UOP1_Project/Assets/Scripts/Audio/SoundEmitters/SoundEmitter.cs


_audioSource.Pause();
}
/// <summary>
/// Used when the SFX finished playing. Called by the <c>AudioManager</c>.
/// </summary>
public void Stop() // Redundant?
public void Stop()
{
_audioSource.Stop();
}

public bool IsLooping()
{
return _audioSource.loop;
}
public bool IsFinishing()
{
return !_audioSource.loop;
}
IEnumerator FinishedPlaying(float clipLength)

7
UOP1_Project/Assets/Scripts/Audio/SoundEmitters/SoundEmitterList.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.Assertions;
using System.Collections.Generic;
public class SoundEmitterList
{

正在加载...
取消
保存