docs.unity3d.com
    Show / Hide Table of Contents

    Class FileSettingsRepository

    Represents a settings repository that stores data serialized to a JSON file.

    Inheritance
    Object
    FileSettingsRepository
    PackageSettingsRepository
    ProjectUserSettings
    Namespace: UnityEditor.SettingsManagement
    Syntax
    public class FileSettingsRepository : object, ISettingsRepository

    Constructors

    FileSettingsRepository(String)

    Initializes and returns an instance of the FileSettingsRepository with the serialized data location set to the specified path.

    Declaration
    public FileSettingsRepository(string path)
    Parameters
    Type Name Description
    String path

    The project-relative path to save settings to.

    Fields

    k_PackageSettingsDirectory

    Location of where the package settings are saved under the ProjectSettings directory.

    Declaration
    protected const string k_PackageSettingsDirectory = null
    Field Value
    Type Description
    String

    The folder where package settings are saved under the ProjectSettings directory.

    k_UserProjectSettingsDirectory

    Location of where the package settings are saved under the UserSettings directory.

    Declaration
    protected const string k_UserProjectSettingsDirectory = null
    Field Value
    Type Description
    String

    Per-project user settings directory.

    Properties

    name

    Sets the name of file containing the serialized settings data.

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

    The bare filename of the settings file.

    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
    See Also
    path

    scope

    Sets the this repository applies to.

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

    , meaning that this setting applies to project settings (the default); or , meaning that this setting applies to user preferences.

    Implements
    ISettingsRepository.scope
    Remarks

    By default, this repository implementation is relevant to the Project scope, but any implementations that override this method can choose to store this serialized data at a user scope instead.

    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 match is found for both key and type; 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)
    See Also
    ContainsKey<T>(String)

    Get<T>(String, T)

    Returns a value with key of type T, or the fallback value if no matching key is found.

    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 settings value if a match is found; otherwise, it returns the default (fallback) value.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

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

    Remove<T>(String)

    Removes 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
    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)
    See Also
    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 value must be serializable.

    Type Parameters
    Name Description
    T

    The type of value that this key points to.

    Implements
    ISettingsRepository.Set<T>(String, T)
    See Also
    Set<T>(String, T)

    TryLoadSavedJson(out String)

    Loads the JSON file that stores the values for this settings object.

    Declaration
    public bool TryLoadSavedJson(out string json)
    Parameters
    Type Name Description
    String json

    The full path to the JSON file to load.

    Returns
    Type Description
    Boolean

    True if the file exists; false if it doesn't.

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