Class Settings
The Settings class is provides an interface for getting and setting preference values. It manages the available
ISettingsRepository
instances.
Inheritance
Namespace: UnityEditor.SettingsManagement
Syntax
public sealed class Settings
Constructors
Settings(IEnumerable<ISettingsRepository>)
Create a new Settings instance with a collection of settings repositories.
Declaration
public Settings(IEnumerable<ISettingsRepository> repositories)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ISettingsRepository> | repositories |
Methods
ContainsKey<T>(String, SettingsScope)
Does the repository contain a setting with key and type.
Declaration
public bool ContainsKey<T>(string key, SettingsScope scope = SettingsScope.Project)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The settings key. |
SettingsScope | scope | Which scope should be searched for matching 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. |
DeleteKey<T>(String, SettingsScope)
Remove a key value pair from a settings repository.
Declaration
public void DeleteKey<T>(string key, SettingsScope scope = SettingsScope.Project)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to remove. |
SettingsScope | scope | Which scope should be searched for matching key. |
Type Parameters
Name | Description |
---|---|
T | The type that this key is pointing to. |
Get<T>(String, SettingsScope, 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, SettingsScope scope = SettingsScope.Project, T fallback = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The settings key. |
SettingsScope | scope | Which scope this settings should be retrieved from. |
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. |
GetRepository(SettingsScope)
Find a settings repository that matches the requested scope.
Declaration
public ISettingsRepository GetRepository(SettingsScope scope)
Parameters
Type | Name | Description |
---|---|---|
SettingsScope | scope | The scope of the settings repository to match. |
Returns
Type | Description |
---|---|
ISettingsRepository | An ISettingsRepository instance that is implementing the requested scope. May return null if no matching repository is found. |
Save()
Serialize the state of all settings repositories.
Declaration
public void Save()
Set<T>(String, T, SettingsScope)
Set a value for key of type T.
Declaration
public void Set<T>(string key, T value, SettingsScope scope = SettingsScope.Project)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The settings key. |
T | value | The value to set. Must be serializable. |
SettingsScope | scope | Which scope this settings should be saved in. |
Type Parameters
Name | Description |
---|---|
T | Type of value. |
Events
afterSettingsSaved
Declaration
public event Action afterSettingsSaved
Event Type
Type | Description |
---|---|
System.Action | An event that is raised after an |
beforeSettingsSaved
Declaration
public event Action beforeSettingsSaved
Event Type
Type | Description |
---|---|
System.Action | An event that is raised prior to an |