Interface IAccount
Abstraction of platform-specific account.
Namespace: Unity.PlatformToolkit
Assembly: Unity.PlatformToolkit.dll
Syntax
public interface IAccount
Remarks
Use Accounts to check if accounts are supported.
After an account becomes signed out, operations on it will throw an InvalidAccountException.
IAccount operations can throw an InvalidAccountException before State is set to SignedOut and before OnChange is invoked.
Through GetAttribute<T>(string) and HasAttribute<T>(string) methods accounts expose various attributes. Attributes can be things like a username, a user picture, IDs, or handles.
Properties
State
Current account state, which can be either SignedIn if the account is valid for use or SignedOut if the account has become invalid for use.
Declaration
AccountState State { get; }
Property Value
| Type | Description |
|---|---|
| AccountState |
Remarks
Once an account instance becomes SignedOut, it will remain so. If the same platform account signs in again, a new instance of IAccount is created.
Methods
GetAchievementSystem()
Get the IAchievementSystem belonging to the IAccount.
Declaration
Task<IAchievementSystem> GetAchievementSystem()
Returns
| Type | Description |
|---|---|
| Task<IAchievementSystem> | Task containing the achievement system for the account. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | IAccount doesn't support achievements. See AccountAchievements. |
| InvalidAccountException | IAccount is signed out. |
GetAttribute<T>(string)
Get the value of an attribute. This method can throw various exceptions depending on the attribute specified.
Declaration
Task<T> GetAttribute<T>(string attributeName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | attributeName | Name of the attribute. |
Returns
| Type | Description |
|---|---|
| Task<T> | Attribute value. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the attribute. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Attribute with a given type and name combination is not defined. Call HasAttribute<T>(string) to make sure the attribute is defined. |
| InvalidAccountException | IAccount is signed out. |
GetName()
Provides a non-specific account name that can be used to display a string identifier for a user.
Declaration
Task<string> GetName()
Returns
| Type | Description |
|---|---|
| Task<string> | A Task containing the name. |
Remarks
Some platforms can provide multiple types of name, in which case it may be more appropriate to use HasAttribute<T>(string) and GetAttribute<T>(string) to retrieve specific types of names for the account.
This method should not throw platform-specific exceptions.
Exceptions
| Type | Condition |
|---|---|
| InvalidAccountException | IAccount is signed out. |
GetPicture()
Provides a non-specific account picture.
Declaration
Task<Texture2D> GetPicture()
Returns
| Type | Description |
|---|---|
| Task<Texture2D> | A Task containing the picture or null. |
Remarks
Some platforms can provide multiple types of account picture, in which case it may be more appropriate to use HasAttribute<T>(string) and GetAttribute<T>(string) to retrieve specific types of picture for the account.
This method doesn't throw platform-specific exceptions.
Exceptions
| Type | Condition |
|---|---|
| InvalidAccountException | IAccount is signed out. |
GetSavingSystem()
Get the ISavingSystem belonging to the IAccount.
Declaration
Task<ISavingSystem> GetSavingSystem()
Returns
| Type | Description |
|---|---|
| Task<ISavingSystem> | Task containing the saving system for the account. |
Remarks
Saves within this system are stored in dedicated account storage: they are not visible or accessible using saving systems belonging to other accounts or using the local saving system.
When the account's GetSavingSystem() is called, the saving system may need to be created. While creating the save system, some platforms might perform long-running operations such as downloading cloud saves. During saving system creation, OS-level UI prompts may be displayed.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | IAccount doesn't support saving. See AccountSaving. |
| InvalidAccountException | IAccount is signed out. |
| UserRefusalException | User chose not to give access to the saving system. |
| NotEnoughSpaceException | User does not have enough disc space left on device for saving operation. |
See Also
HasAttribute<T>(string)
Check if an attribute with a given type and name is defined.
Declaration
bool HasAttribute<T>(string attributeName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | attributeName | Name of the attribute. |
Returns
| Type | Description |
|---|---|
| bool | True, if the attribute is defined, false otherwise. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the attribute. |
Remarks
Attributes are given a unique name, that is set in the editor.
Exceptions
| Type | Condition |
|---|---|
| InvalidAccountException | IAccount is signed out. |
SignOut()
Manually SignOut an account. Use AccountManualSignOut for a given account type to check if sign out is supported.
Declaration
Task<bool> SignOut()
Returns
| Type | Description |
|---|---|
| Task<bool> | A Task containing a result of the sign out. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Sign out isn't supported as indicated by ICapabilities. |