Class FileSettingsRepository
Represents a settings repository that stores data serialized to a JSON file.
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 |
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
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
See Also
scope
Sets the
Declaration
public virtual SettingsScope scope { get; }
Property Value
| Type | Description |
|---|---|
| SettingsScope |
Implements
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
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
See Also
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 |
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
See Also
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
See Also
Save()
Saves all settings to their serialized state.
Declaration
public void Save()
Implements
See Also
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
See Also
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. |