-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from baobao/feature/dev
Audio settings are now saved locally
- Loading branch information
Showing
6 changed files
with
172 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
Assets/Shibuya24UnityAudioManager/Runtime/AudioLocalSave.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#if ENABLE_LOCALSAVE_SHIBUYA24_AUDIO | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace info.shibuya24.Audio | ||
{ | ||
/// <summary> | ||
/// Shibuya24AudioManager Local Save | ||
/// Use PlayerPrefs | ||
/// </summary> | ||
public static class AudioLocalSave | ||
{ | ||
private const string BgmVolumeKey = "shibuya24.bgm.volume"; | ||
private const string SeVolumeKey = "shibuya24.se.volume"; | ||
|
||
private const string BgmMuteKey = "shibuya24.bgm.mute"; | ||
private const string SeMuteKey = "shibuya24.se.mute"; | ||
|
||
/// <summary> | ||
/// Save Volume | ||
/// </summary> | ||
public static void SetVolume(AudioChannel ch, float value) | ||
{ | ||
switch (ch) | ||
{ | ||
case AudioChannel.BGM: | ||
SetFloat(BgmVolumeKey, value); | ||
break; | ||
case AudioChannel.SE: | ||
SetFloat(SeVolumeKey, value); | ||
break; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get Volume. | ||
/// </summary> | ||
public static float GetVolume(AudioChannel ch, float defaultValue = 1f) | ||
{ | ||
switch (ch) | ||
{ | ||
case AudioChannel.BGM: | ||
return GetFloat(BgmVolumeKey, defaultValue); | ||
case AudioChannel.SE: | ||
return GetFloat(SeVolumeKey, defaultValue); | ||
} | ||
|
||
Debug.LogError($"Invalid key : {ch}"); | ||
return 0; | ||
} | ||
|
||
/// <summary> | ||
/// Set Mute State. | ||
/// </summary> | ||
public static void SetMute(AudioChannel ch, bool value) | ||
{ | ||
switch (ch) | ||
{ | ||
case AudioChannel.BGM: | ||
SetBool(BgmMuteKey, value); | ||
break; | ||
case AudioChannel.SE: | ||
SetBool(SeMuteKey, value); | ||
break; | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Get Mute State. | ||
/// </summary> | ||
public static bool GetMute(AudioChannel ch, bool defaultValue = false) | ||
{ | ||
switch (ch) | ||
{ | ||
case AudioChannel.BGM: | ||
return GetBool(BgmMuteKey, defaultValue); | ||
case AudioChannel.SE: | ||
return GetBool(SeMuteKey, defaultValue); | ||
} | ||
|
||
Debug.LogError($"Invalid key : {ch}"); | ||
return false; | ||
} | ||
|
||
#region PlayerPrefs Wrapper | ||
|
||
private static void SetFloat(string key, float value) | ||
{ | ||
PlayerPrefs.SetFloat(key, value); | ||
} | ||
|
||
private static float GetFloat(string key, float defaultValue = 0) | ||
{ | ||
return PlayerPrefs.GetFloat(key, defaultValue); | ||
} | ||
|
||
private static void SetInt(string key, int value) | ||
{ | ||
PlayerPrefs.SetInt(key, value); | ||
} | ||
|
||
private static int GetInt(string key, int defaultValue = 0) | ||
{ | ||
return PlayerPrefs.GetInt(key, defaultValue); | ||
} | ||
|
||
private static void SetBool(string key, bool value) | ||
{ | ||
SetInt(key, value ? 1 : 0); | ||
} | ||
|
||
private static bool GetBool(string key, bool defaultValue = false) | ||
{ | ||
return GetInt(key, defaultValue ? 1 : 0) != 0; | ||
} | ||
|
||
#endregion | ||
} | ||
} | ||
#endif |
11 changes: 11 additions & 0 deletions
11
Assets/Shibuya24UnityAudioManager/Runtime/AudioLocalSave.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters