Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Last active April 2, 2022 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtdekker/01da815d2dfd336a925ae38019c3a163 to your computer and use it in GitHub Desktop.
Save kurtdekker/01da815d2dfd336a925ae38019c3a163 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// by @kurtdekker - handy example of simple persistent settings.
//
// To use, just use the variables like any other:
//
// SETTINGS.VolumeLevel = 1.0f;
//
// if (SETTINGS.EnableTurboMode)
// {
// // Do turbo-mode stuff
// }
//
// EDIT: see defaults that you can set below
public static class SETTINGS
{
// change this if you want it to start out differently
private const float DefaultVolumeLevel = 1.0f;
private static string s_VolumeLevel = "VolumeLevel";
public static float VolumeLevel
{
get
{
return PlayerPrefs.GetFloat(s_VolumeLevel, DefaultVolumeLevel);
}
set
{
PlayerPrefs.SetFloat(s_VolumeLevel, value);
}
}
private const bool DefaultTurboMode = true;
private static string s_EnableTurboMode = "EnableTurboMode";
public static bool EnableTurboMode
{
get
{
return PlayerPrefs.GetInt(s_EnableTurboMode, DefaultTurboMode ? 1 : 0) != 0;
}
set
{
PlayerPrefs.SetInt(s_EnableTurboMode, value ? 1 : 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment