Class EditorPrefsUtils
Utilities for getting and setting values stored in EditorPrefs.
Inherited Members
Namespace: Unity.XR.CoreUtils.Editor
Syntax
public static class EditorPrefsUtils
Remarks
The EditorPrefUtils
class caches any preference values retrieved or set using its methods.
Avoid accessing the same preference values using the EditorPrefs class directly.
Methods
ColorToColorPref(String, Color)
Encodes a Color object as a string.
Declaration
public static string ColorToColorPref(string path, Color value)
Parameters
Type | Name | Description |
---|---|---|
String | path | The preference key/path prepended to the color string. |
Color | value | The color value to encode. |
Returns
Type | Description |
---|---|
String | A formatted string representing the color value. |
Remarks
ColorToColorPref
encodes a string that can be decoded by PrefToColor(String).
The function prepends the color information with the string specified in path
.
This function is used by SetColor(String, Color, String) to store a preference that can be retrieved with GetColor(String, Color, String).
GetBool(String, Boolean, String)
Gets the bool value stored in the Editor preferences for the calling property.
Declaration
public static bool GetBool(string typeName, bool defaultValue = false, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property. |
Boolean | defaultValue | Value to be used as default if a preference value has not been stored. |
String | propertyName | Name of calling method. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
Returns
Type | Description |
---|---|
Boolean | The bool value stored in the Editor preferences for the calling property. |
GetColor(String, Color, String)
Gets the color value stored in the Editor preferences for the calling property.
Declaration
public static Color GetColor(string typeName, Color defaultValue, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property. |
Color | defaultValue | Value to be used as default if a preference value has not been stored. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
Returns
Type | Description |
---|---|
Color | The color value stored in the Editor preferences for the calling property. |
GetFloat(String, Single, String)
Gets the float value stored in the Editor preferences for the calling property.
Declaration
public static float GetFloat(string typeName, float defaultValue = 0F, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property |
Single | defaultValue | Value to be used as default if a preference value has not been stored. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
Returns
Type | Description |
---|---|
Single | The float value stored in the Editor preferences for the calling property. |
GetInt(String, Int32, String)
Gets the int value stored in the Editor preferences for the calling property.
Declaration
public static int GetInt(string typeName, int defaultValue = 0, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property. |
Int32 | defaultValue | Value to be used as default if a preference value has not been stored. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
Returns
Type | Description |
---|---|
Int32 | The int value stored in the Editor preferences for the calling property. |
GetPrefKey(String, String)
Gets a standardized Editor preference key name.
Declaration
public static string GetPrefKey(string typeName, string propertyName)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property. |
String | propertyName | Name of property. |
Returns
Type | Description |
---|---|
String | Editor preference key for property. |
Remarks
Constructs the key name by combining the parent object type's full name and the property name.
GetString(String, String, String)
Gets the string value stored in the Editor preferences for the calling property.
Declaration
public static string GetString(string typeName, string defaultValue = "", string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property. |
String | defaultValue | Value to be used as default if a preference value has not been stored. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
Returns
Type | Description |
---|---|
String | The string value stored in the Editor preferences for the calling property. |
PrefToColor(String)
Creates a Color object from a specially formatted string.
Declaration
public static Color PrefToColor(string pref)
Parameters
Type | Name | Description |
---|---|---|
String | pref | A color preference value encoded as a string by ColorToColorPref(String, Color). |
Returns
Type | Description |
---|---|
Color | A decoded Color object for a string stored in the Editor preferences. If the string cannot be decoded,
the default |
Remarks
PrefToColor
decodes a string encoded by ColorToColorPref(String, Color).
This function is used by GetColor(String, Color, String) to read a preference value stored by SetColor(String, Color, String).
SetBool(String, Boolean, String)
Stores the bool value in the Editor preferences for the calling property.
Declaration
public static void SetBool(string typeName, bool value, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type which declares the property. |
Boolean | value | Value to set in Editor preferences. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
SetColor(String, Color, String)
Stores the color value in the Editor preferences for the calling property.
Declaration
public static void SetColor(string typeName, Color value, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property. |
Color | value | Value to set in Editor preferences. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
SetFloat(String, Single, String)
Stores the float value in the Editor preferences for the calling property.
Declaration
public static void SetFloat(string typeName, float value, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property. |
Single | value | Value to set in Editor preferences. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
SetInt(String, Int32, String)
Stores the int value in the Editor preferences for the calling property.
Declaration
public static void SetInt(string typeName, int value, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type which declares the property. |
Int32 | value | Value to set in Editor preferences. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |
SetString(String, String, String)
Stores the string value in the Editor preferences for the calling property.
Declaration
public static void SetString(string typeName, string value, string propertyName = null)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | The name of the type that declares the property. |
String | value | Value to set in Editor preferences. |
String | propertyName | Name of calling property. When invoking this function from a property getter or setter, you can leave this parameter blank and it will be filled in by the property name. |