Skip to content
VirtueSky edited this page Sep 8, 2024 · 5 revisions

What

Support play audio

Use Pool for spawning SoundComponents (with AudioSource attached)

Use

  • Create SoundComponent Prefab

Screenshot 2024-05-17 105818

  • Attach AudioManager to scene to handle play sound FX and Music background (don't destroy)

Screenshot 2024-05-17 105718

  • Create SoundDataSoundData contains AudioClip, and loop, volume, fade music parameters for customization

Right-click folder > Create > Unity-Common > Audio > SoundData or create from Magic Panel

Screenshot 2024-05-17 110442

Screenshot 2024-05-17 111105

  • Note: If you drag more than one AudioClip into the list, SoundData will return a random AudioClip in the list

  • Play sound fx and music

publicSoundDatasoundFX;publicSoundDatamusic;privateSoundCache_soundCache;/// <summary>/// Play sound fx/// </summary>publicvoidPlaySoundFX(){_soundCache=AudioManager.PlaySfx(soundFX);// or_soundCache=soundFX.PlaySfx();}/// <summary>/// Pause sound fx/// </summary>publicvoidPauseSoundFX(){AudioManager.PauseSfx(_soundCache);// or_soundCache.PauseSfx();}/// <summary>/// Resume sound fx/// </summary>publicvoidResumeSoundFX(){AudioManager.ResumeSfx(_soundCache);// or_soundCache.ResumeSfx();}/// <summary>/// Finish sound fx/// </summary>publicvoidFinishSoundFX(){AudioManager.FinishSfx(_soundCache);// or_soundCache.FinishSfx();}/// <summary>/// Stop sound fx/// </summary>publicvoidStopSoundFX(){AudioManager.StopSfx(_soundCache);// or_soundCache.StopSfx();}/// <summary>/// Stop all sound fx/// </summary>publicvoidStopAllSoundFX(){AudioManager.StopAllSfx();}/// <summary>/// Play music/// </summary>publicvoidPlayMusic(){AudioManager.PlayMusic(music);// ormusic.PlayMusic();}/// <summary>/// Pause music/// </summary>publicvoidPauseMusic(){AudioManager.PauseMusic();}/// <summary>/// Resume music/// </summary>publicvoidResumeMusic(){AudioManager.ResumeMusic();}/// <summary>/// Stop music/// </summary>publicvoidStopMusic(){AudioManager.StopMusic();}

Clone this wiki locally