Extended methods for PlayerPrefs and EditorPrefs in Unity.
This small package uses the original PlayerPrefs and EditorPrefs methods to support other types.
Additional supported types:
BooleanVector2/Vector3/Vector2Int/Vector3IntBounds/BoundsIntResolutionColor
You can download a unity package from the latest release.
To access PlayerPrefs extended methods, use the ExtendedPlayerPrefs class. For EditorPrefs, respectively, use ExtendedEditorPrefs.
Here is an example of how you could set the saved screen resolution at the Start() using ExtendedPrefs:
usingExtendedPrefs;usingJetBrains.Annotations;usingUnityEngine;publicclassScreenResolutionPreference:MonoBehaviour{privateconststringSCREEN_RESOLUTION_PLAYER_PREF_NAME="SCREEN_RES_PREF";// Start is called before the first frame updateprivatevoidStart(){SetSavedResolution();}privatevoidSetSavedResolution(){varscreenResolution=ExtendedPlayerPrefs.GetVector2Int(SCREEN_RESOLUTION_PLAYER_PREF_NAME,GetCurrentResolution());Screen.SetResolution(screenResolution.x,screenResolution.y,Screen.fullScreenMode);}[UsedImplicitly]publicvoidSaveCurrentResolution(){ExtendedPlayerPrefs.SetVector2Int(SCREEN_RESOLUTION_PLAYER_PREF_NAME,GetCurrentResolution());}privatestaticVector2IntGetCurrentResolution(){returnnewVector2Int(Screen.width,Screen.height);}}After a while, I completely abandoned PlayerPrefs, preferring to use regular config files. They are easier to maintain and easier for users to edit. Custom config files will have better serialization and wider customization options.