Prefs Editor is a full editor for viewing, editing and managing your PlayerPrefs. It now includes support for encrypting your preferences to help stop people hacking your game.
- View, edit and manage your PlayerPrefs to speed up development and help with debugging.
- Custom editor window for ease of use.
- Secure player prefs to help prevent tampering.
- Easy to use API that closely mirrors the standard PlayerPrefs while adding useful extensions.
- and more…
The Prefs Editor window is available through the Unity Editor’s Window Menu by selecting the “Prefs Editor” option.
The Prefs Editor window displays a list of all your current PlayerPrefs along with a toolbar that gives you common options
for manipulating the items. Each PlayerPrefs item displayed shows it’s type and whether it is encrypted followed by options for editing the key and value. Finally buttons let you save changes or delete the prefs item.
If you are using encrypted preferences then you should enter a pass phrase. This should correspond to whatever you use in your code for accessing player prefs. See below for more information on encrypted preferences.
To create a new Player Prefs item select the New… option from the Prefs Editor window and then select the type, key
and value as you would if creating through the API. If this entry should be encrypted then select the Encrypted checkbox.
To modify an existing Player Prefs item, update the corresponding key or value and then click the Save, or Save All icons.
To delete an existing Player Prefs item, click the delete icon next to the corresponding entry, or the Delete All… button.
If the PlayerPrefs change, then you will need to click the ‘Refresh’ button to update the list.
Unity currently saves all preferences in un-encrypted format which can easily be tracked down and modified by someone with a little know how. For example on windows this is in the registry which is easy to access and modify. This leaves your game open to tampering and people could easily change things like their score, number of lives or progress. Depending on your type of game it may be important to protect against this kind of behavior and that is why Prefs Editor now supports encryption of preferences values before they are saves.
Prefs Editor provides an API that is very similar to that of the standard Unity PlayerPrefs for using secure PlayerPrefs. The API is fully compatible with existing PlayerPrefs and lets you chose either globally or at an individual level whether to use encrypted or standard player prefs. Conversion from the Unity PlayerPrefs API requires very little conversion effort. The API also supports automatic conversion of existing PlayerPrefs values.
One important note is that you will need to provide an encryption pass phrase. Typically this might be stored in your executable some place and so their is still the possibility that someone might be able to retrieve reverse engineer your code and retrieve this. This is a lot less likely than people being able to simply access the un-encrypted values and probably more than good enough for the majority of games. If however it is critical to prevent this sort of action then you would need look into some sort of online authentication and passphrase retrieval.
SecurePlayerPrefs Scripting API
Prefs Editor provides the SecurePlayerPrefs class that works with both encrypted as well as Unity standard PlayerPrefs.
Much of the functionality is the same as the standard Unity PlayerPrefs API with the following exceptions:
SecurePlayerPrefs has a property UseSecurePrefs that if set to true indicates that preference should default to being encrypted. If you set this to true then be sure to set a passphrase using the PassPhrase property. The pass phrase should be a random sequence of characters at least 6 characters long.
The AutoConvertUnsecurePrefs property indicates whether the framework should check for any un-encrypted preferences and automatically encrypt those entries. This can be useful if you have an existing game that might have values stored with the old PlayerPrefs. There is a minimal overhead with doing this check however so for new games this can be left to the default of false.
Usage of the API works in a similar fashion to the old PlayerPrefs API however many of the calls in SecurePlayerPrefs add an optional useSecuredPrefs parameter. If set then this will override the global UseSecurePrefs setting allowing to mix secure and unsecure preferences.
The following example shows how an example of using the old PlayerPrefs and new SecurePlayerPrefs API’s. Other calls for String and Float types work in a similar fashion.
// Example PlayerPrefs calls
var value = PlayerPrefs.GetInt("TestInt");
// Example SecurePlayerPrefs calls
SecurePlayerPrefs.UseSecurePrefs = true;
var value = SecurePlayerPrefs.GetInt("TestInt");
Saving Additional Types
Prefs editor supports saving additional types in addition to those supported by the standard PlayerPrefs. This includes boolean values through the SetBool() and GetBool() methods.
If you have any thoughts or suggestions on improvements or additions to the Advertising features then please let us know!