PlayerPrefsx

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 7: Line 7:
  
 
==Usage==
 
==Usage==
Unlike CookieCutter, PlayerPrefsx creates its own GameObject when it is needed. All you have to do is place the script in your Plugins folder. Replace (Find/Replace) all references to "PlayerPrefs" in your files (NOT in PlayerPrefsx.js) to PlayerPrefsx. That's all!
+
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:
 +
 
 +
while (PlayerPrefsx.loaded) yield;
 +
 
 +
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.
  
 
==Notes==
 
==Notes==
Line 14: Line 22:
  
 
==JavaScript - PlayerPrefsx.js==
 
==JavaScript - PlayerPrefsx.js==
BROKEN
+
Coming soon.....

Revision as of 16:37, 9 October 2007

Author: StarManta; built on CookieCutter by KeliHlodversson

CURRENTLY FIXED, but uses some as yet unreleased features. will release when these features are public.

Contents

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.

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:

while (PlayerPrefsx.loaded) yield;

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.

Notes

  • Safari requires the embedding html to be served from an http: url. When testing on a local file url, no cookies will be saved or returned. Either enable personal web sharing and open the player through http://localhost/... or use a browser that supports cookies on file:// urls (eg. Firefox)
  • Watch the size of the cookies. All cookies defined using this module will be sent to the web server serving the web player on every web request. This increases the amount of data sent to the server, but might also compromise privacy if the cookies contain sensitive data. Especially if you are hosting the player on a domain name shared by others. You can limit the scope of the cookies created by this module by setting the path variable to limit the cookie to a subdirectory on the web server. (Ie. if the web player is located at http://myhost.com/myProjects/coolGame/webPlayer.html, set path to /myProjects/coolGame to ensure the cookies are not available to urls outside that directory on the web server.)

JavaScript - PlayerPrefsx.js

Coming soon.....

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox