This class is used to access preferences stored via the PlayerPrefInterface. It is derived from the PrefOptionBase class. It contains details about the current value of the option, and the key string of course, but it also contains a default value, and label GUIContent. It provides a Value accessor function, which, along with the constructor, handle loading and saving the value to PlayerPrefInterface for the programmer. But keep in mind, the load/save operation will be performed every-time Value is accessed: while quite convenient, this could effect performance of loops and such.
- Template Parameters
-
ValueType | Defines the type of value that will be stored by this preference. Currently only Color, Vector2, Vector3, float, bool, string, int, Enum are valid types for an PlayerPrefOption ValueType. Using other, unsupported types, will generate runtime exceptions, but NOT compiler errors. To support additional types derive a new class from this one, and override the Has,Load,Save and Delete Functions. Be sure to call your new code first, returning upon success, to prevent an exception being generated. |
|
| PlayerPrefOptionArray (ValueType[] _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.
|
|
| 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.
|
|
|
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.
|
|
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.
|
|
object | _value |
| A reference to the current array of ValueTypes
|
|
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.
|
|