game over UI done, rematch left
This commit is contained in:
@@ -5,6 +5,9 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
const string SfxEnabledPrefsKey = "Audio.SfxEnabled";
|
||||
const string MusicEnabledPrefsKey = "Audio.MusicEnabled";
|
||||
|
||||
[Header("Sources")]
|
||||
public AudioSource musicSource;
|
||||
public AudioSource uiSfxSource;
|
||||
@@ -44,6 +47,7 @@ public class AudioManager : MonoBehaviour
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
_maxMusicVolume = musicSource != null ? musicSource.volume : 1f;
|
||||
LoadAudioPrefs();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
@@ -227,6 +231,82 @@ public class AudioManager : MonoBehaviour
|
||||
|
||||
#region SFX
|
||||
|
||||
void LoadAudioPrefs()
|
||||
{
|
||||
ToggleSFX(PlayerPrefs.GetInt(SfxEnabledPrefsKey, 1) == 1, savePreference: false);
|
||||
ToggleMusic(PlayerPrefs.GetInt(MusicEnabledPrefsKey, 1) == 1, savePreference: false);
|
||||
}
|
||||
|
||||
public void ToggleSFX(bool isOn)
|
||||
{
|
||||
ToggleSFX(isOn, savePreference: true);
|
||||
}
|
||||
|
||||
public void ToggleMusic(bool isOn)
|
||||
{
|
||||
ToggleMusic(isOn, savePreference: true);
|
||||
}
|
||||
|
||||
public bool IsSFXOn()
|
||||
{
|
||||
if (uiSfxSource != null)
|
||||
return !uiSfxSource.mute;
|
||||
if (gameSfxSource != null)
|
||||
return !gameSfxSource.mute;
|
||||
if (crowdSfxSourceA != null)
|
||||
return !crowdSfxSourceA.mute;
|
||||
if (crowdSfxSourceB != null)
|
||||
return !crowdSfxSourceB.mute;
|
||||
return PlayerPrefs.GetInt(SfxEnabledPrefsKey, 1) == 1;
|
||||
}
|
||||
|
||||
public bool IsMusicOn()
|
||||
{
|
||||
if (musicSource != null)
|
||||
return !musicSource.mute;
|
||||
return PlayerPrefs.GetInt(MusicEnabledPrefsKey, 1) == 1;
|
||||
}
|
||||
|
||||
public void SetSfxVolume(float volume)
|
||||
{
|
||||
ToggleSFX(volume > 0f);
|
||||
}
|
||||
|
||||
public void SetMusicVolume(float volume)
|
||||
{
|
||||
ToggleMusic(volume > 0f);
|
||||
}
|
||||
|
||||
void ToggleSFX(bool isOn, bool savePreference)
|
||||
{
|
||||
if (uiSfxSource != null)
|
||||
uiSfxSource.mute = !isOn;
|
||||
if (gameSfxSource != null)
|
||||
gameSfxSource.mute = !isOn;
|
||||
if (crowdSfxSourceA != null)
|
||||
crowdSfxSourceA.mute = !isOn;
|
||||
if (crowdSfxSourceB != null)
|
||||
crowdSfxSourceB.mute = !isOn;
|
||||
|
||||
if (!savePreference)
|
||||
return;
|
||||
|
||||
PlayerPrefs.SetInt(SfxEnabledPrefsKey, isOn ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
void ToggleMusic(bool isOn, bool savePreference)
|
||||
{
|
||||
if (musicSource != null)
|
||||
musicSource.mute = !isOn;
|
||||
|
||||
if (!savePreference)
|
||||
return;
|
||||
|
||||
PlayerPrefs.SetInt(MusicEnabledPrefsKey, isOn ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public void PlayWallHit(float vol=1){
|
||||
gameSfxSource.PlayOneShot(audioDirectory.wallHits[Random.Range(0, audioDirectory.wallHits.Length)], vol);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user