Class PackageSettingsRepository | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Class PackageSettingsRepository

    A settings repository that stores data local to a Unity project.

    Inheritance
    System.Object
    PackageSettingsRepository
    Namespace: UnityEditor.SettingsManagement
    Syntax
    [Serializable]
    public sealed class PackageSettingsRepository : ISettingsRepository

    Constructors

    PackageSettingsRepository(String, String)

    Constructor sets the serialized data path.

    Declaration
    public PackageSettingsRepository(string package, string name)
    Parameters
    Type Name Description
    System.String package

    The package name.

    System.String name

    A name for this settings file. Settings are saved in ProjectSettings/Packages/{package}/{name}.json.

    Properties

    name

    The name of this settings file.

    Declaration
    public string name { get; }
    Property Value
    Type Description
    System.String
    Implements
    ISettingsRepository.name

    path

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

    The full path to the settings file. This corresponds to Unity Project/Project Settings/Packages/com.unity.package/name.

    Implements
    ISettingsRepository.path

    scope

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

    This repository implementation is relevant to the Project scope.

    Implements
    ISettingsRepository.scope

    Methods

    ContainsKey<T>(String)

    Does the repository contain a setting with key and type.

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

    The settings key.

    Returns
    Type Description
    System.Boolean

    True if a setting matching both key and type is found, false if no entry is found.

    Type Parameters
    Name Description
    T

    The type of value to search for.

    Implements
    ISettingsRepository.ContainsKey<T>(String)

    Get<T>(String, T)

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

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

    The settings key.

    T fallback

    If no key with a value of type T is found, this value is returned.

    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    Type of value to search for.

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

    GetSettingsPath(String, String)

    Get a path for a settings file relative to the calling assembly package directory.

    Declaration
    public static string GetSettingsPath(string packageName, string name = "Settings")
    Parameters
    Type Name Description
    System.String packageName

    The name of the package requesting this setting.

    System.String name

    An optional name for the settings file. Default is "Settings."

    Returns
    Type Description
    System.String

    A package-scoped path to the settings file within Project Settings.

    Remove<T>(String)

    Remove a key value pair from the settings repository.

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

    Save()

    Save all settings to their serialized state.

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

    Set<T>(String, T)

    Set a value for key of type T.

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

    The settings key.

    T value

    The value to set. Must be serializable.

    Type Parameters
    Name Description
    T

    Type of value.

    Implements
    ISettingsRepository.Set<T>(String, T)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023