docs.unity3d.com
    Show / Hide Table of Contents

    Class UserSetting<T>

    A generic implementation of IUserSetting to use with a Settings instance. This default implementation assumes that the Settings instance contains two ISettingsRepository interfaces:

    • Project settings ()
    • User preferences ()
    Inheritance
    Object
    UserSetting<T>
    Namespace: UnityEditor.SettingsManagement
    Syntax
    public class UserSetting<T> : object, IUserSetting
    Type Parameters
    Name Description
    T

    Type of value.

    Constructors

    UserSetting(Settings, String, T, SettingsScope)

    Initializes and returns an instance of the UserSetting<T> type.

    Declaration
    public UserSetting(Settings settings, string key, T value, SettingsScope scope = null)
    Parameters
    Type Name Description
    Settings settings

    The Settings instance to save and load this setting from.

    String key

    The key for this value.

    T value

    The default value for this key.

    SettingsScope scope

    The scope for this setting. By default, the scope is the project.

    UserSetting(Settings, String, String, T, SettingsScope)

    Initializes and returns an instance of the UserSetting<T> type using the specified repository.

    Declaration
    public UserSetting(Settings settings, string repository, string key, T value, SettingsScope scope = null)
    Parameters
    Type Name Description
    Settings settings

    The Settings instance to save and load this setting from.

    String repository

    The ISettingsRepository name to save and load this setting from. Specify null to save to the first available instance.

    String key

    The key for this value.

    T value

    The default value for this key.

    SettingsScope scope

    The scope for this setting. By default, the scope is the project.

    Properties

    defaultValue

    Gets the default value for this setting.

    Declaration
    public T defaultValue { get; }
    Property Value
    Type Description
    T

    key

    Gets the key for this value.

    Declaration
    public string key { get; }
    Property Value
    Type Description
    String
    Implements
    IUserSetting.key
    See Also
    key

    scope

    Gets the scope (ISettingsRepository) where the Settings instance saves its data.

    Declaration
    public SettingsScope scope { get; }
    Property Value
    Type Description
    SettingsScope
    Implements
    IUserSetting.scope
    See Also
    scope

    settings

    Gets the Settings instance to read from and save to.

    Declaration
    public Settings settings { get; }
    Property Value
    Type Description
    Settings
    Implements
    IUserSetting.settings
    See Also
    settings

    settingsRepositoryName

    Gets the name of the repository that this setting is saved in.

    Declaration
    public string settingsRepositoryName { get; }
    Property Value
    Type Description
    String
    Implements
    IUserSetting.settingsRepositoryName
    See Also
    settingsRepositoryName

    type

    Gets the type that this setting represents (<T>).

    Declaration
    public Type type { get; }
    Property Value
    Type Description
    Type
    Implements
    IUserSetting.type
    See Also
    type

    value

    Gets or sets the currently stored value.

    Declaration
    public T value { get; set; }
    Property Value
    Type Description
    T

    Methods

    ApplyModifiedProperties()

    Forces Unity to serialize the changed properties to the ISettingsRepository that is backing this value. When the inspected type is a reference value, it is possible to change properties without affecting the backing setting.

    Declaration
    public void ApplyModifiedProperties()
    Implements
    IUserSetting.ApplyModifiedProperties()
    See Also
    ApplyModifiedProperties()

    Delete(Boolean)

    Deletes the saved setting but doesn't clear the current value.

    Declaration
    public void Delete(bool saveProjectSettingsImmediately = false)
    Parameters
    Type Name Description
    Boolean saveProjectSettingsImmediately

    Set this value to true if you want to immediately serialize the ISettingsRepository that is backing this value. By default, this is false.

    Note: If not serializing immediately, you need to call Save().

    Implements
    IUserSetting.Delete(Boolean)
    See Also
    Reset(Boolean)
    Delete(Boolean)

    GetDefaultValue()

    Returns a copy of the default value.

    Declaration
    public object GetDefaultValue()
    Returns
    Type Description
    Object

    The default value.

    Implements
    IUserSetting.GetDefaultValue()
    See Also
    GetDefaultValue()

    GetValue()

    Returns the currently stored value.

    Declaration
    public object GetValue()
    Returns
    Type Description
    Object

    The value that is currently set.

    Implements
    IUserSetting.GetValue()
    See Also
    GetValue()

    Reset(Boolean)

    Sets the current value back to the default.

    Declaration
    public void Reset(bool saveProjectSettingsImmediately = false)
    Parameters
    Type Name Description
    Boolean saveProjectSettingsImmediately

    Set this value to true if you want to immediately serialize the ISettingsRepository that is backing this value. By default, this is false.

    Note: If not serializing immediately, you need to call Save().

    Implements
    IUserSetting.Reset(Boolean)
    See Also
    Reset(Boolean)

    SetValue(T, Boolean)

    Sets the value for this setting from the specified object.

    Declaration
    public void SetValue(T value, bool saveProjectSettingsImmediately = false)
    Parameters
    Type Name Description
    T value
    Boolean saveProjectSettingsImmediately

    Set this value to true if you want to immediately serialize the ISettingsRepository that is backing this value. By default, this is false.

    Note: If not serializing immediately, you need to call Save().

    See Also
    SetValue(Object, Boolean)

    SetValue(Object, Boolean)

    Sets the value for this setting from the specified object.

    Declaration
    public void SetValue(object value, bool saveProjectSettingsImmediately = false)
    Parameters
    Type Name Description
    Object value

    The new value to set.

    Boolean saveProjectSettingsImmediately

    Set this value to true if you want to immediately serialize the ISettingsRepository that is backing this value. By default, this is false.

    Note: If not serializing immediately, you need to call Save().

    Implements
    IUserSetting.SetValue(Object, Boolean)
    See Also
    SetValue(Object, Boolean)

    ToString()

    Returns a string representation of this setting.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String

    A string summary of this setting of format "[scope] setting. Key: [key] Value: [value]".

    Operators

    Implicit(UserSetting<T> to T)

    Implicit casts this setting to the backing type T.

    Declaration
    public static implicit operator T(UserSetting<T> pref)
    Parameters
    Type Name Description
    UserSetting<T> pref

    The UserSetting<T> to cast to T.

    Returns
    Type Description
    T

    The currently stored value.

    Back to top Copyright © 2021 Unity Technologies
    Generated by DocFX
    on Monday, December 6, 2021
    Terms of use