Class Settings
Represents a collection of objects that implement ISettingsRepository.
Namespace: UnityEditor.SettingsManagement
Syntax
public sealed class Settings : object
Constructors
Settings(IEnumerable<ISettingsRepository>)
Creates a new Settings instance with a collection of objects that implement ISettingsRepository.
Declaration
public Settings(IEnumerable<ISettingsRepository> repositories)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<ISettingsRepository> | repositories | The repositories to populate the Settings instance with. |
Settings(String, String)
Creates a new Settings instance with a UserSettingsRepository and PackageSettingsRepository.
Declaration
public Settings(string package, string settingsFileName = "Settings")
Parameters
| Type | Name | Description |
|---|---|---|
| String | package | The package name, such as |
| String | settingsFileName | The name of the settings file. The default value is |
Methods
ContainsKey<T>(String, SettingsScope)
Determines whether the repository in the specified T.
Declaration
public bool ContainsKey<T>(string key, SettingsScope scope = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| SettingsScope | scope | The |
Returns
| Type | Description |
|---|---|
| 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 that this key points to. |
ContainsKey<T>(String, String, SettingsScope)
Determines whether the specified repository contains a settings entry that matches the specified key and is of type T.
Declaration
public bool ContainsKey<T>(string key, string repositoryName, SettingsScope scope = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| String | repositoryName | The repository name to match. |
| SettingsScope | scope | The |
Returns
| Type | Description |
|---|---|
| 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 that this key points to. |
ContainsKey<T, K>(String, String)
Determines whether the specified repository of type K contains a settings entry that matches the specified key and is of type T.
Declaration
public bool ContainsKey<T, K>(string key, string repositoryName = null)
where K : ISettingsRepository
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| String | repositoryName | The repository name to match. |
Returns
| Type | Description |
|---|---|
| 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 that this key points to. |
| K | The type of repository to search for matching keys. |
DeleteKey<T>(String, SettingsScope)
Removes a key-value pair from a settings repository. This method identifies the settings entry to remove
from any repository in the specified T.
Declaration
public void DeleteKey<T>(string key, SettingsScope scope = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| SettingsScope | scope | The |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
DeleteKey<T>(String, String, SettingsScope)
Removes a key-value pair from a settings repository. This method identifies the settings entry to remove
from the specified repository by matching the specified key for a value of type T.
Declaration
public void DeleteKey<T>(string key, string repositoryName, SettingsScope scope = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| String | repositoryName | The repository name to match. |
| SettingsScope | scope | The |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
DeleteKey<T, K>(String, String)
Removes a key-value pair from a settings repository. This method identifies the settings entry to remove
from the specified repository of type K by matching the specified key for a value of type T.
Declaration
public void DeleteKey<T, K>(string key, string repositoryName = null)
where K : ISettingsRepository
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| String | repositoryName | The repository name to match. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
| K | The type of repository to search for matching keys. |
Get<T>(String, SettingsScope, T)
Returns a value for a settings entry with a matching key and type T.
Declaration
public T Get<T>(string key, SettingsScope scope = null, T fallback = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| SettingsScope | scope | The |
| T | fallback | Specify the value of type |
Returns
| Type | Description |
|---|---|
| T | The value from a matching settings entry; or the default value if not found. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
Get<T>(String, String, SettingsScope, T)
Returns a value for a settings entry with a matching key and type T.
Declaration
public T Get<T>(string key, string repositoryName, SettingsScope scope = null, T fallback = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| String | repositoryName | The repository name to match. |
| SettingsScope | scope | The |
| T | fallback | Specify the value of type |
Returns
| Type | Description |
|---|---|
| T | The value from a matching settings entry; or the default value if not found. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
Get<T, K>(String, T, String)
Returns a value for a settings entry with a matching key and type T from the specified repository of type K.
Declaration
public T Get<T, K>(string key, T fallback = null, string repositoryName = null)
where K : ISettingsRepository
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| T | fallback | Specify the value of type |
| String | repositoryName | If provided, only repositories with a matching name will be searched for the key. |
Returns
| Type | Description |
|---|---|
| T | The value from a matching settings entry; or the default value if not found. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
| K | The type of repository to search for matching keys. |
GetRepository(SettingsScope)
Finds and returns a settings repository that matches the specified scope.
Declaration
public ISettingsRepository GetRepository(SettingsScope scope)
Parameters
| Type | Name | Description |
|---|---|---|
| SettingsScope | scope | The |
Returns
| Type | Description |
|---|---|
| ISettingsRepository | An ISettingsRepository instance that implements the requested scope; or null if no matching repository is found. |
GetRepository(SettingsScope, String)
Finds and returns a settings repository that matches the specified scope and name.
Declaration
public ISettingsRepository GetRepository(SettingsScope scope, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| SettingsScope | scope | The |
| String | name | The name of the ISettingsRepository to match. |
Returns
| Type | Description |
|---|---|
| ISettingsRepository | An ISettingsRepository instance that implements the specified scope and matches the name; or null if no matching repository is found. |
Save()
Serializes the state of all settings repositories.
Declaration
public void Save()
Set<T>(String, T, SettingsScope)
Sets a value for a settings entry with a matching key and type T.
Declaration
public void Set<T>(string key, T value, SettingsScope scope = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| T | value | The value to set. This must be serializable. |
| SettingsScope | scope | The |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
Set<T>(String, T, String, SettingsScope)
Sets a value for a settings entry with a matching key and type T from the specified repository.
Declaration
public void Set<T>(string key, T value, string repositoryName, SettingsScope scope = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| T | value | The value to set. This must be serializable. |
| String | repositoryName | Optional. The name of the repository to set this value in. |
| SettingsScope | scope | The |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
Set<T, K>(String, T, String)
Sets a value for a settings entry with a matching key and type T from the specified repository of type K.
Declaration
public void Set<T, K>(string key, T value, string repositoryName = null)
where K : ISettingsRepository
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | The key used to identify the settings entry. |
| T | value | The value to set. This must be serializable. |
| String | repositoryName | Optional. The name of the repository to set this value in. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value that this key points to. |
| K | The type of repository to search for matching keys. |
Events
afterSettingsSaved
Called immediately after an instance of ISettingsRepository serializes its current state.
Declaration
public event Action afterSettingsSaved
Event Type
| Type | Description |
|---|---|
| Action |
beforeSettingsSaved
Called prior to when an instance of ISettingsRepository serializes its current state.
Declaration
public event Action beforeSettingsSaved
Event Type
| Type | Description |
|---|---|
| Action |