docs.unity.cn
    Show / Hide Table of Contents

    Interface ISettingsRepository

    An interface that represents a settings repository, which is responsible for implementing the saving and loading of values.

    Namespace: UnityEditor.SettingsManagement
    Syntax
    public interface ISettingsRepository

    Properties

    name

    Implement this property to get the name to identify this repository.

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

    The bare filename of this repository.

    path

    Implement this property to get the file path to the serialized settings data.

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

    Full path to the JSON file containing the settings data.

    scope

    Implement this property to get the this repository applies to.

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

    Indicates whether this is a setting or a preference.

    Methods

    ContainsKey<T>(String)

    Implement this method to evaluate whether the repository contains a settings entry that matches the specified key and is of type T.

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

    Get<T>(String, T)

    Implement this method to get a value for a settings entry with a matching key and type T.

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

    Remove<T>(String)

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

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

    Save()

    Implement this method to save all settings to their serialized state.

    Declaration
    void Save()

    Set<T>(String, T)

    Implement this method to set a value for a settings entry with a matching key and type T.

    Declaration
    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. Must be serializable.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

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