docs.unity.cn
    Show / Hide Table of Contents

    Class UserSettingsRepository

    Represents a settings repository for user preferences.

    Inheritance
    Object
    UserSettingsRepository
    Namespace: UnityEditor.SettingsManagement
    Syntax
    public class UserSettingsRepository : object, ISettingsRepository

    Properties

    name

    Gets the identifying name for this repository.

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

    User settings are named "EditorPrefs".

    Implements
    ISettingsRepository.name

    path

    Gets the full path to the file containing the serialized settings data.

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

    The location stored for this repository.

    Implements
    ISettingsRepository.path
    Remarks

    This property returns an empty string.

    See Also
    path

    scope

    Gets the scope this repository applies to.

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

    Indicates that this is a preference.

    Implements
    ISettingsRepository.scope
    See Also
    scope

    Methods

    ContainsKey<T>(String)

    Determines whether this repository contains a settings entry that matches the specified key and is of type T.

    Declaration
    public bool ContainsKey<T>(string key)
    Parameters
    Type Name Description
    String key

    The key used to identify the settings entry.

    Returns
    Type Description
    Boolean

    True if a settings entry matches both key and type T; false if no entry is found.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    Implements
    ISettingsRepository.ContainsKey<T>(String)

    Get<T>(String, T)

    Returns a value for a settings entry with a matching key and type T.

    Declaration
    public T Get<T>(string key, T fallback = null)
    Parameters
    Type Name Description
    String key

    The key used to identify the settings entry.

    T fallback

    Specify the value of type T to return if the entry can't be found.

    Returns
    Type Description
    T

    The value matching both key and type T. If there was no match, this returns the fallback value.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    Implements
    ISettingsRepository.Get<T>(String, T)

    Remove<T>(String)

    Removes a key-value pair from this settings repository. This method identifies the settings entry to remove by matching the specified key for a value of type T.

    Declaration
    public void Remove<T>(string key)
    Parameters
    Type Name Description
    String key

    The key used to identify the settings entry.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    Implements
    ISettingsRepository.Remove<T>(String)

    Save()

    Saves all settings to their serialized state.

    Declaration
    public void Save()
    Implements
    ISettingsRepository.Save()
    See Also
    Save()

    Set<T>(String, T)

    Sets a value for a settings entry with a matching key and type T.

    Declaration
    public void Set<T>(string key, T value)
    Parameters
    Type Name Description
    String key

    The key used to identify the settings entry.

    T value

    The value to set. This must be serializable.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    Implements
    ISettingsRepository.Set<T>(String, T)
    Back to top Copyright © 2021 Unity Technologies
    Generated by DocFX
    on Monday, December 6, 2021
    Terms of use