-
Notifications
You must be signed in to change notification settings - Fork 12
Audio
DucNV_2000 edited this page Oct 17, 2024
·
8 revisions
flowchart LR
AudioManager["Audio Manager"] --Object pulling--> SoundComponent(["Sound Component<br>(bring audio source)"])
SoundData[("Sound Data<br> (contains audio clip)")] --> EventPlaySfx & EventPlayMusic
subgraph Event
EventPlaySfx{Play Sound Fx Event}
EventPlayMusic{Play Music Event}
end
EventPlaySfx & EventPlayMusic --Raise--> AudioManager
- Use ObjectPooling to play audio
- Manage play, pause, resume, stop, finish, volume change of sound
- Attaches the
AudioManager
to the game object contained in the scene. The declarations in the AudioManager will be automatically generated and appended
- If AudioManager is missing declarations, you can reset it to get it back or open the Audio tab in
Magic Panel
to create and drag it in
- Create a prefab
SoundComponent
SoundComponent contains an AudioSource to control (play) an AudioClip
- Drag the
SoundCompoent
into the createdSoundComponentPool
and attach it to theAudioManager
SoundComponentPool is responsible for spawning/despawning SoundComponent
-
SoundData
containsAudioClip
, andloop
,volume
,fade music
parameters for customization - Create
SoundData
fromMagic Panel
- Note: If you drag more than one
AudioClip
into the list,SoundData
will return a randomAudioClip
in the list
using UnityEngine;
using VirtueSky.Audio;
public class PlayAudio : MonoBehaviour
{
public PlayMusicEvent playMusicEvent;
public PauseMusicEvent pauseMusicEvent;
public StopMusicEvent stopMusicEvent;
public ResumeMusicEvent resumeMusicEvent;
public PlaySfxEvent playSfxEvent;
public PauseSfxEvent pauseSfxEvent;
public ResumeSfxEvent resumeSfxEvent;
public FinishSfxEvent finishSfxEvent;
public StopSfxEvent stopSfxEvent;
public StopAllSfxEvent stopAllSfxEvent;
public SoundData musicGame;
public SoundData soundPlayer;
private SoundCache sfxCache;
public void PlayMusicGame()
{
playMusicEvent.Raise(musicGame);
}
public void PauseMusicGame()
{
pauseMusicEvent.Raise();
}
public void ResumeMusicGame()
{
resumeMusicEvent.Raise();
}
public void StopMusicGame()
{
stopMusicEvent.Raise();
}
public void PlaySoundPlayer()
{
sfxCache = playSfxEvent.Raise(soundPlayer);
}
public void PauseSoundPlayer()
{
pauseSfxEvent.Raise(sfxCache);
}
public void ResumeSoundPlayer()
{
resumeSfxEvent.Raise(sfxCache);
}
public void FinishSoundPlayer()
{
finishSfxEvent.Raise(sfxCache);
}
public void StopSoundPlayer()
{
stopSfxEvent.Raise(sfxCache);
}
public void StopAllSoundFX()
{
stopAllSfxEvent.Raise();
}
}