Helpful extensions for the Unity PlayerPrefs sub-system
- Open your project manifest file (
MyProject/Packages/manifest.json
). - Add
"com.debox.playerprefs": "https://github.com/debox-dev/playerprefs.git"
to thedependencies
list. - Open or focus on Unity Editor to resolve packages.
- Unity 2019 or higher.
using DeBox.PlayerPrefsExtensions;
public class MyClass
{
private readonly PlayerPrefsInt _playerGold = new PlayerPrefsInt("gold", 0);
public void GetGold()
{
return _playerGold.Value;
}
public void AddGold(int value):
{
_playerGold.Value += value;
}
public void ResetGold()
{
_playerGold.Delete();
// _playerGold.Value will return 0 now
}
}