PlayerPrefsx

Author: StarManta; built on CookieCutter by KeliHlodversson

Widget Support: Casemon (with thanks to StarManta & Eric5h5)

This script has been made obsolete by Unity 2.1; PlayerPrefs now works in Web players.

As is, it works with Unity 2.0 Web Players. It has not been tested with 1.x. If it doesn't work, line 24 is probably the line that would need to be changed.

Description
CookieCutter is a utility script for accessing the browser cookies from the web player. PlayerPrefsx takes that base, and adds functions so that, to make your game web-game-save compatible, you can simply find and replace PlayerPrefs with PlayerPrefsx. PlayerPrefsx will automatically determine whether to use CookieCutter code or PlayerPrefs code so your game can always save.

For Dashboard widgets, use exactly like you would with webplayers. PlayerPrefsx with Dashboard players will create a single widget preferenceKey (in your game's widget plist in ~/Library/Preferences) that contains all of your prefs. Recommend against saving prefs every frame, otherwise you'll notice a slow down (especially in widgets).

Usage
Place this script on a GameObject. Make sure the GameObject has a unique name.

After the game has started, cookies can be read by calling PlayerPrefs.SetInt("Player Count", 5), etc - just like PlayerPrefs. PPX also has SetBool and GetBool methods that work online and off.

For best reliability, put the following code before you use PlayerPrefsx:

It shouldn't take any significant amount of time to load the cookies - a frame at most, probably. (Non-Web player builds will be loaded instantaneously) In any case this will make sure PPX function are not called when they shouldn't be.