Interface ISavingSystem
Provides access to saving functionality.
Namespace: Unity.PlatformToolkit
Assembly: Unity.PlatformToolkit.dll
Syntax
public interface ISavingSystem
Remarks
Saves are identified by name. The name is a string consisting of lowercase latin alphabet letters [a-z], numbers [0-9] and hyphens -. Platforms have different maximum name length restrictions, so it’s recommended to keep the name short.
A save contains a set of files within it. Each file has a unique name within a save. The same naming rules apply to files as to saves.
If ISavingSystem operations fail with InvalidSystemException that means that the saving system needs to be re-created by calling GetSavingSystem() or LocalSaving. Exactly if and when a saving system can become invalid is platform dependent. Usually InvalidSystemException indicates that saves were changed from outside the application or even on another system.
Methods
DeleteSave(string)
Delete save.
Declaration
Task DeleteSave(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the save to be deleted. |
Returns
| Type | Description |
|---|---|
| Task | Task representing the deletion operation. |
Remarks
The save must be closed when attempting to delete it.
Attempting to delete a save that does not exist is allowed and will not result in an exception.
Exceptions
| Type | Condition |
|---|---|
| IOException | There was an error deleting the save. |
| InvalidOperationException | The save is open. |
| ArgumentException | The name is null or empty, contains invalid characters, or is too long. |
| InvalidAccountException | IAccount is signed out. |
| InvalidSystemException | ISavingSystem is invalid. |
EnumerateSaveNames()
Enumerate names of existing saves.
Declaration
Task<IReadOnlyList<string>> EnumerateSaveNames()
Returns
| Type | Description |
|---|---|
| Task<IReadOnlyList<string>> | Task containing save names in an IReadOnlyList. |
Remarks
Saves can only be enumerated when no saves are open. Attempting to enumerate saves while one or more saves are open will result in InvalidOperationException.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | One or more saves are open, which prevents them from being enumerated. |
| InvalidAccountException | IAccount is signed out. |
| InvalidSystemException | ISavingSystem is invalid. |
OpenSaveReadable(string)
Open a save in read-only mode.
Declaration
Task<ISaveReadable> OpenSaveReadable(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the save to be opened. |
Returns
| Type | Description |
|---|---|
| Task<ISaveReadable> | Task containing the save. |
Remarks
Within an ISavingSystem only one save with a given name can be opened at one time. This is true regardless if the save was opened using OpenSaveReadable(string) or OpenSaveWritable(string). Multiple saves with different names can be open at the same time, though different platforms can have different limits on how many saves can be opened.
Only saves that already exist can be opened in read-only mode.
Exceptions
| Type | Condition |
|---|---|
| InvalidAccountException | IAccount is signed out. |
| InvalidSystemException | ISavingSystem is invalid. |
| IOException | There was an error reading the data. |
| InvalidOperationException | Save is already open. |
| ArgumentException | The name is null or empty, contains invalid characters, or is too long. |
| FileNotFoundException | Save with a given name does not exist in the ISavingSystem. |
| IOException | An I/O error occurred while accessing the file. |
OpenSaveWritable(string)
Open a save in write-only mode.
Declaration
Task<ISaveWritable> OpenSaveWritable(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the save to be opened. |
Returns
| Type | Description |
|---|---|
| Task<ISaveWritable> | Task containing the save. |
Remarks
Within an ISavingSystem only one save with a given name can be opened at one time. This is true regardless if the save was opened using OpenSaveReadable(string) or OpenSaveWritable(string). Multiple saves with different names can be open at the same time, though different platforms can have different limits on how many saves can be opened.
If the method is given a name of an existing save, that save is opened for writing.
To create a new save call OpenSaveWritable(string) and give it a new name. A new save is only created after it is successfully committed.
Exceptions
| Type | Condition |
|---|---|
| InvalidAccountException | IAccount is signed out. |
| InvalidSystemException | ISavingSystem is invalid. |
| IOException | There was an error reading the data. |
| InvalidOperationException | Save is already open. |
| ArgumentException | The name is null or empty, contains invalid characters, or is too long. |
| IOException | An I/O error occurred while accessing the file. |
SaveExists(string)
Check if a save exists.
Declaration
Task<bool> SaveExists(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the save to be checked. |
Returns
| Type | Description |
|---|---|
| Task<bool> | Task containing a bool representing whether the save exists. |
Remarks
SaveExists(string) can only be called when no saves are open.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | One or more saves are open. |
| IOException | There was an error reading the data. |
| ArgumentException | The name is null or empty, contains invalid characters, or is too long. |
| InvalidAccountException | IAccount is signed out. |
| InvalidSystemException | ISavingSystem is invalid. |