PrefOptionArrayBase< TValueType, TPrefInterfaceType > Class Template Reference

Similar in form to the PrefOptionBase class, this class is used to specify a preference that is to be stored as an array of values. Both EditorPrefOptionArray and PlayerPrefOptionArray classes are derived from this one, with each using a specific IStorePreferences interface for the PrefInterfaceType parameter. Unless creating your own IStorePreferences-implementing-class, users should use one of those two derived classes, rather than this one.

Detailed Description

Template Parameters
TValueTypeThe elements of the array will be of this type
TPrefInterfaceTypeThis IStorePreferences interface will define weather the preferences are stored as editor or player prefs).
Type Constraints
TPrefInterfaceType :IStorePreferences 
TPrefInterfaceType :new() 

Public Member Functions

 PrefOptionArrayBase (TValueType[] _defaultValue, string keyString, GUIContent guiLabel, bool _alwaysLoadAndSaveOnValueAccess=true)
 Constructor takes almost all members as parameters, with the exception of the current value. The current preference value is set when loaded, if the key exists, or set to the default value, if new.
 
virtual void Delete ()
 While the Delete function does not effect any member values, it will attempt to remove the current key (and associated values) from PlayerPrefs. If the type ValueType of the PlayerPrefObject, is not supported an exception is raised.
 
virtual void Load ()
 This function will attempt to retrieve from storage, and cache, the preference value from the PrefInterface, based on the current key value. If the key does not exist in PlayerPrefs, the defaultValue will be loaded instead. If the type ValueType of the PlayerPrefObject, is not supported an exception is raised.
 
virtual void Save ()
 The Save function will attempt to store the current member _value into PrefInterface, using the current key value. If the type ValueType of the PlayerPrefObject, is not supported an exception is raised.
 
virtual TValueType[] SetToDefault ()
 Sets the current value of this preference to defaultValue.
 

Public Attributes

bool alwaysLoadAndSaveOnValueAccess
 Specifies weather this preference should be automatically re-loaded or re-saved, every-time the value is read/written.
 
object defaultValue
 Default array, assigned to the run-time value, when the preference is deleted, or a not-yet-existing-in-storage key is loaded.
 

Protected Member Functions

virtual bool HasKey ()
 This protected function is used to check if the key exits in PrefInterface. Used before attempting to load or delete keys. No type exceptions are generated.
 

Protected Attributes

object _value
 A reference to the current array of ValueTypes
 

Properties

string Key [get]
 Read-only accessor to get the key used to store this preference. The key can only be set with the constructor.
 
GUIContent Label [get, set]
 Accessor used to access the optional GUIContent when for labeling this preference in the Unity Editor. Optional, may be null.
 
virtual TValueType[] Value [get, set]
 This Accessor's get function returns the current value of this preference. This current value is loaded, and cashed during initialization. If the current value object does not match the type ValueType, of the PlayerPrefOption, an exception is raised. If no value has been assigned yet, the defaultValue will, usually, be returned. However, if the type of the defaultValue object does not match the ValueType type of PlayerPrefOption, default(ValueType), will be returned instead. You can set defaultValue to null, if this is the desired result. The set functions will store the new value in the cache, but will NOT save it to PlayerPrefs (until Save(), is called). If the object to store does not match the type ValueType, of the PlayerPrefOption, an exception is raised. This accessor will check type compatibility before assigning or returning the preference's Value, and will either raise an exception or display a waning, respectively.
 
+ Inheritance diagram for PrefOptionArrayBase< TValueType, TPrefInterfaceType >: