docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class EditorPrefsUtils

    Utilities for getting and setting values stored in EditorPrefs.

    Inheritance
    object
    EditorPrefsUtils
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.XR.CoreUtils.Editor
    Assembly: Unity.XR.CoreUtils.Editor.dll
    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, bool, 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.

    bool 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
    bool

    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, float, string)

    Gets the float value stored in the Editor preferences for the calling property.

    Declaration
    public static float GetFloat(string typeName, float defaultValue = 0, string propertyName = null)
    Parameters
    Type Name Description
    string typeName

    The name of the type that declares the property

    float 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
    float

    The float value stored in the Editor preferences for the calling property.

    GetInt(string, int, 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.

    int 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
    int

    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 Color (all 0 components) is returned.

    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, bool, 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.

    bool 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, float, 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.

    float 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, int, 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.

    int 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.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)