Preferences


Game Framework provides its own interface to Unity PlayerPrefs that also provides easy support for storing additional data types, secure preference and third party assets. In most cases swapping to GameFrameworks interface is as simple as renaming any calls to PlayerPrefs to PreferencesFactory instead.

Basic Usage

In most cases swapping to Game Framework’s interface is as simple as renaming any calls to PlayerPrefs to PreferencesFactory instead. The API aims to be compatible with existing PlayerPrefs providing all of the same properties and methods while adding useful extensions.

For a full list of all the methods and properties please see the API documentation.

GameItems also provide an additional layer on top of this to automatically save preferences within the context of the GameItem.

Support For Additional Data Types

PreferencesFactory provides additional methods for storing and retrieving other common data types such as boolean values. These work in a similar fashion to the PlayerPrefs Int, Float and String calls

Secure Preferences

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. Through the use of third party extensions, Game Framework supports encryption of preferences values before they are saved.

Encryption

To use secure preferences you will need to enable integration with an asset that provides this support (see below). With this done you can enable secure preferences in the GameManager component.

GameManagerSecurePrefs

Pass Phrase should be a random sequence of characters at least 6 characters long. Convert Unsecure Prefs can be enabled if you have an existing game that used standard PlayerPrefs to automatically convert and keep existing values. For new games this should be left unchecked as it is not necessary and keeps overhead (although minimal) to a minimum.

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.

Scripting Secure Preferences

Usage of the PreferencesFactory API works in a similar fashion to the old PlayerPrefs API however many of the calls in PreferencesFactory add an optional useSecuredPrefs parameter. If set then this will override the global setting UseSecurePrefs allowing to mix secure and unsecure preferences.

The following example shows how an example of using the old PlayerPrefs and new PreferencesFactory API’s. Other calls for String and Float types etc. work in a similar fashion.

See the class documentation for full details on all the properties and methods available

Third Party Integration

To use secure preferences you will need have installed an asset that provides this support and enable integration with it through the through the Menu | Windows| Game Framework | Integration Window.

PrefsEditorIntegration

 

Our Prefs Editor asset is included in the extras bundle and provides this support along with a useful editor for viewing and managing your preferences.

Screenshot2

See also

If you have any thoughts or suggestions on improvements or additions to the Advertising features then please let us know!