Auto Prefs

The InspectorGadgets.AutoPrefs class contains a group of nested classes which simplify the way you can store and retrieve values in PlayerPrefs and EditorPrefs.

// First you declare your pref with the key and default value (optional):
public static readonly AutoPrefs.Bool MyPref = new AutoPrefs.Bool("MyPref", true);

// If you don't want to specify a default value, you can use an implicit cast:
public static readonly AutoPrefs.Bool MyOtherPref = "MyOtherPref";

// Then you can get and set the value without using the key everywhere:
if (MyPref)// Or MyPref.Value.
{
    MyPref.Value = false;
}
  • AutoPrefs.Bool stores its value in PlayerPrefs while AutoPrefs.EditorBool stores its value in EditorPrefs.
  • Other pref types are also available: float, int, string, Vector2, Vector3, Vector4, Quaternion.
  • You can create your own AutoPref types by inheriting from AutoPref<T>.