Class UserSetting<T>
A generic implementation of IUserSetting to use with a Settings instance. This default implementation assumes that the Settings instance contains two ISettingsRepository interfaces:
- Project settings (
) - User preferences (
)
Namespace: UnityEditor.SettingsManagement
Syntax
public class UserSetting<T> : object, IUserSetting
Type Parameters
| Name | Description |
|---|---|
| T | Type of value. |
Constructors
UserSetting(Settings, String, T, SettingsScope)
Initializes and returns an instance of the UserSetting<T> type.
Declaration
public UserSetting(Settings settings, string key, T value, SettingsScope scope = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Settings | settings | The Settings instance to save and load this setting from. |
| String | key | The key for this value. |
| T | value | The default value for this key. |
| SettingsScope | scope | The scope for this setting. By default, the scope is the project. |
UserSetting(Settings, String, String, T, SettingsScope)
Initializes and returns an instance of the UserSetting<T> type using the specified repository.
Declaration
public UserSetting(Settings settings, string repository, string key, T value, SettingsScope scope = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Settings | settings | The Settings instance to save and load this setting from. |
| String | repository | The ISettingsRepository name to save and load this setting from. Specify null to save to the first available instance. |
| String | key | The key for this value. |
| T | value | The default value for this key. |
| SettingsScope | scope | The scope for this setting. By default, the scope is the project. |
Properties
defaultValue
Gets the default value for this setting.
Declaration
public T defaultValue { get; }
Property Value
| Type | Description |
|---|---|
| T |
key
Gets the key for this value.
Declaration
public string key { get; }
Property Value
| Type | Description |
|---|---|
| String |
Implements
See Also
scope
Gets the scope (ISettingsRepository) where the Settings instance saves its data.
Declaration
public SettingsScope scope { get; }
Property Value
| Type | Description |
|---|---|
| SettingsScope |
Implements
See Also
settings
Gets the Settings instance to read from and save to.
Declaration
public Settings settings { get; }
Property Value
| Type | Description |
|---|---|
| Settings |
Implements
See Also
settingsRepositoryName
Gets the name of the repository that this setting is saved in.
Declaration
public string settingsRepositoryName { get; }
Property Value
| Type | Description |
|---|---|
| String |
Implements
See Also
type
Gets the type that this setting represents (<T>).
Declaration
public Type type { get; }
Property Value
| Type | Description |
|---|---|
| Type |
Implements
See Also
value
Gets or sets the currently stored value.
Declaration
public T value { get; set; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
ApplyModifiedProperties()
Forces Unity to serialize the changed properties to the ISettingsRepository that is backing this value. When the inspected type is a reference value, it is possible to change properties without affecting the backing setting.
Declaration
public void ApplyModifiedProperties()
Implements
See Also
Delete(Boolean)
Deletes the saved setting but doesn't clear the current value.
Declaration
public void Delete(bool saveProjectSettingsImmediately = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | saveProjectSettingsImmediately | Set this value to true if you want to immediately serialize the ISettingsRepository that is backing this value. By default, this is false. Note: If not serializing immediately, you need to call Save(). |
Implements
See Also
GetDefaultValue()
Returns a copy of the default value.
Declaration
public object GetDefaultValue()
Returns
| Type | Description |
|---|---|
| Object | The default value. |
Implements
See Also
GetValue()
Returns the currently stored value.
Declaration
public object GetValue()
Returns
| Type | Description |
|---|---|
| Object | The value that is currently set. |
Implements
See Also
Reset(Boolean)
Sets the current value back to the default.
Declaration
public void Reset(bool saveProjectSettingsImmediately = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | saveProjectSettingsImmediately | Set this value to true if you want to immediately serialize the ISettingsRepository that is backing this value. By default, this is false. Note: If not serializing immediately, you need to call Save(). |
Implements
See Also
SetValue(T, Boolean)
Sets the value for this setting from the specified object.
Declaration
public void SetValue(T value, bool saveProjectSettingsImmediately = false)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | |
| Boolean | saveProjectSettingsImmediately | Set this value to true if you want to immediately serialize the ISettingsRepository that is backing this value. By default, this is false. Note: If not serializing immediately, you need to call Save(). |
See Also
SetValue(Object, Boolean)
Sets the value for this setting from the specified object.
Declaration
public void SetValue(object value, bool saveProjectSettingsImmediately = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | value | The new value to set. |
| Boolean | saveProjectSettingsImmediately | Set this value to true if you want to immediately serialize the ISettingsRepository that is backing this value. By default, this is false. Note: If not serializing immediately, you need to call Save(). |
Implements
See Also
ToString()
Returns a string representation of this setting.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String | A string summary of this setting of format "[scope] setting. Key: [key] Value: [value]". |
Operators
Implicit(UserSetting<T> to T)
Implicit casts this setting to the backing type T.
Declaration
public static implicit operator T(UserSetting<T> pref)
Parameters
| Type | Name | Description |
|---|---|---|
| UserSetting<T> | pref | The UserSetting<T> to cast to |
Returns
| Type | Description |
|---|---|
| T | The currently stored value. |