docs.unity3d.com
Search Results for

    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 Project and one for User.

    Inheritance
    object
    UserSetting<T>
    Implements
    IUserSetting
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: UnityEditor.SettingsManagement
    Assembly: Unity.Settings.Editor.dll
    Syntax
    public class UserSetting<T> : IUserSetting
    Type Parameters
    Name Description
    T

    Constructors

    UserSetting(Settings, string, string, T, SettingsScope)

    Constructor for UserSetting type.

    Declaration
    public UserSetting(Settings settings, string repository, string key, T value, SettingsScope scope = SettingsScope.Project)
    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.

    UserSetting(Settings, string, T, SettingsScope)

    Constructor for UserSetting type.

    Declaration
    public UserSetting(Settings settings, string key, T value, SettingsScope scope = SettingsScope.Project)
    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.

    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.

    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.

    settings

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

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

    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.

    type

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

    The type that this setting represents ().

    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()

    Delete(bool)

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

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

    True to immediately re-serialize project settings.

    GetDefaultValue()

    Get a copy of the default value.

    Declaration
    public object GetDefaultValue()
    Returns
    Type Description
    object

    The default value.

    GetValue()

    Get the currently stored value.

    Declaration
    public object GetValue()
    Returns
    Type Description
    object

    The value that is currently set.

    Reset(bool)

    Set the current value back to the default.

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

    True to immediately re-serialize project settings.

    SetValue(object, bool)

    Set the value for this setting.

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

    The new value.

    bool 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(T, bool)

    Set the value for this setting.

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

    The new value.

    bool 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().

    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 operator T(UserSetting<T>)

    Implicit cast to backing type.

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

    The UserSetting to cast to .

    Returns
    Type Description
    T

    The currently stored value.

    Implements

    IUserSetting
    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)