ArrayPrefs

Author: Eric Haines (Eric5h5)

Contributions
(Set/Get Vector3) 03/2010: Mario Madureira Fontes (fontmaster)

(Created CSharp Version) 10/2010: Daniel P. Rossi (DR9885)

(Inherit PlayerPrefs Functionality) 10/2010: Daniel P. Rossi (DR9885)

Description
Provides a way to save and load arrays from PlayerPrefs. (Note: You probably want to use ArrayPrefs2 instead, which is generally faster and better.)

Usage
Have this script somewhere in your project. Ideally it should be in the Scripts folder in Standard Assets; this way it can be called from C# and Boo scripts. Call it PlayerPrefsX, and then you can use the following functions:


 * PlayerPrefsX.SetVector3
 * PlayerPrefsX.GetVector3
 * PlayerPrefsX.SetIntArray
 * PlayerPrefsX.GetIntArray
 * PlayerPrefsX.SetFloatArray
 * PlayerPrefsX.GetFloatArray
 * PlayerPrefsX.SetStringArray
 * PlayerPrefsX.GetStringArray

SetVector3
static function SetVector3 (key : string, value : Vector3) : boolean

Description

Sets the value of the preference identified by key. The value in this case is a Vector3. Returns false if a PlayerPrefsException occured (for example, trying to save more than 1MB of data when using the web player), otherwise returns true.

GetVector3
static function GetVector3 (key : string) : Vector3

Description

Returns the value corresponding to key in the preference file if it exists.

If it doesn't exist, it will return Vector3(0,0,0).

SetIntArray
static function SetIntArray (key : string, value : int[]) : boolean

Description

Sets the value of the preference identified by key. The value in this case is an array of integers (int[]). Returns false if a PlayerPrefsException occured (for example, trying to save more than 1MB of data when using the web player), otherwise returns true.

GetIntArray
static function GetIntArray (key : string) : int[]

Description

Returns the value corresponding to key in the preference file if it exists.

If it doesn't exist, it will return int[0].

static function GetIntArray (key : string, defaultValue : int, defaultSize : int) : int[]

Description

Returns the value corresponding to key in the preference file if it exists.

If it doesn't exist, it will return an integer array of size defaultSize, filled with value defaultValue.

SetFloatArray
static function SetFloatArray (key : string, value : float[]) : boolean

Description

Sets the value of the preference identified by key. The value in this case is an array of floats (float[]). Returns false if a PlayerPrefsException occured (for example, trying to save more than 1MB of data when using the web player), otherwise returns true.

GetFloatArray
static function GetFloatArray (key : string) : float[]

Description

Returns the value corresponding to key in the preference file if it exists.

If it doesn't exist, it will return float[0].

static function GetFloatArray (key : string, defaultValue : float, defaultSize : int) : float[]

Description

Returns the value corresponding to key in the preference file if it exists.

If it doesn't exist, it will return a float array of size defaultSize, filled with value defaultValue.

SetStringArray
static function SetStringArray (key : string, value : String[]) : boolean

Description

Sets the value of the preference identified by key. The value in this case is an array of strings (String[]). Returns false if a PlayerPrefsException occured (for example, trying to save more than 1MB of data when using the web player), otherwise returns true.

static function SetStringArray (key : string, value : String[], separator : char) : boolean

Description

By default, a line break is used as a separator when storing array entries. If your string array contains strings that include line breaks, then reading the array back would fail. Therefore, you can choose to supply a different separator character.

GetStringArray
static function GetStringArray (key : string) : string[]

Description

Returns the value corresponding to key in the preference file if it exists.

If it doesn't exist, it will return String[0].

static function GetStringArray (key : string, separator : char) : string[]

Description

If you specified a separator character when saving a string array, you can supply it when reading that array back.

static function GetStringArray (key : string, defaultValue : String, defaultSize : int) : string[]

Description

If key doesn't exist, it will return a String array of size defaultSize, filled with value defaultValue.

static function GetStringArray (key : string, separator : char, defaultValue : String, defaultSize : int) : string[]

Description

If you specified a separator character when saving a string array, you can supply it when reading that array back, and if key doesn't exist, it will return a String array of size defaultSize, filled with value defaultValue.