Class UserSetting<T> | Settings Manager | 1.0.1
docs.unity.cn
    Show / Hide Table of Contents

    Class UserSetting<T>

    A generic implementation of IUserSetting to be used with a Settings instance. This default implementation assumes the Settings instance contains two ISettingsRepository, one for and one for .

    Inheritance
    Object
    UserSetting<T>
    Namespace: UnityEditor.SettingsManagement
    Syntax
    public class UserSetting<T> : IUserSetting
    Type Parameters
    Name Description
    T

    Constructors

    UserSetting(Settings, String, T, SettingsScope)

    Constructor for UserSetting{T} type.

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

    The Settings instance that this setting should be saved and loaded from.

    String key

    The key for this value.

    T value

    The default value for this key.

    SettingsScope scope

    The scope at which to save this setting.

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

    Constructor for UserSetting{T} type.

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

    The Settings instance that this setting should be saved and loaded from.

    String repository

    The ISettingsRepository name that this setting should be saved and loaded from. Pass null to save to first available instance.

    String key

    The key for this value.

    T value

    The default value for this key.

    SettingsScope scope

    The scope at which to save this setting.

    Properties

    defaultValue

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

    The default value for this setting.

    key

    Declaration
    public string key { get; }
    Property Value
    Type Description
    String

    The key for this value.

    Implements
    IUserSetting.key

    scope

    The scope affects which ISettingsRepository the settings instance will save it's data to.

    Declaration
    public SettingsScope scope { get; }
    Property Value
    Type Description
    SettingsScope

    The scope at which to save this key and value.

    Implements
    IUserSetting.scope

    settings

    Declaration
    public Settings settings { get; }
    Property Value
    Type Description
    Settings

    The Settings instance that this setting will be read from and saved to.

    Implements
    IUserSetting.settings

    settingsRepositoryName

    The name of the ISettingsRepository that this setting should be associated with. If null, the first repository matching the scope will be used.

    Declaration
    public string settingsRepositoryName { get; }
    Property Value
    Type Description
    String

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

    Implements
    IUserSetting.settingsRepositoryName

    type

    Declaration
    public Type type { get; }
    Property Value
    Type Description
    Type

    The type that this setting represents ({T}).

    Implements
    IUserSetting.type

    value

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

    The currently stored value.

    Methods

    ApplyModifiedProperties()

    When the inspected type is a reference value, it is possible to change properties without affecting the backing setting. ApplyModifiedProperties provides a method to force serialize these changes.

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

    Delete(Boolean)

    Delete the saved setting. Does not clear the current value.

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

    True to immediately re-serialize project settings.

    Implements
    IUserSetting.Delete(Boolean)

    GetDefaultValue()

    Get a copy of the default value.

    Declaration
    public object GetDefaultValue()
    Returns
    Type Description
    Object

    The default value.

    Implements
    IUserSetting.GetDefaultValue()

    GetValue()

    Get the currently stored value.

    Declaration
    public object GetValue()
    Returns
    Type Description
    Object

    The value that is currently set.

    Implements
    IUserSetting.GetValue()

    Reset(Boolean)

    Set the current value back to the default.

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

    True to immediately re-serialize project settings.

    Implements
    IUserSetting.Reset(Boolean)

    SetValue(T, Boolean)

    Set the value for this setting.

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

    The new value.

    Boolean saveProjectSettingsImmediately

    True to immediately serialize the ISettingsRepository that is backing this value, or false to postpone. If not serializing immediately, be sure to call Save().

    SetValue(Object, Boolean)

    Set the value for this setting.

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

    The new value.

    Boolean saveProjectSettingsImmediately

    True to immediately serialize the ISettingsRepository that is backing this value, or false to postpone. If not serializing immediately, be sure to call Save().

    Implements
    IUserSetting.SetValue(Object, Boolean)

    ToString()

    Get a summary of this setting.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String

    A string summary of this setting.

    Overrides
    Object.ToString()

    Operators

    Implicit(UserSetting<T> to T)

    Implicit cast to backing type.

    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 © 2019 Unity Technologies
    Generated by DocFX