# 管理配置文件

> Create and manage multiple player profiles on a single device to allow players to sign in with different accounts.

玩家可以使用配置文件在一台设备上登录多个帐户。配置文件为保存到 `PlayerPrefs` 中的数值增加了一层隔离。配置文件不会自动持续存在，是否会持续存在取决于开发者的管理方式。

### 切换配置文件##switch-profiles

玩家必须注销才能切换当前的配置文件。使用 `AuthenticationService.Instance.SwitchProfile(profileName)`。配置文件名称仅支持字母数字值、“-”和“\_”，且最大字符数为 30。

如果玩家未注销，`SwitchProfile` 会抛出 `AuthenticationException`，错误代码为 `AuthenticationErrorCodes.ClientInvalidUserState`。

如果使用的是无效名称，`SwitchProfile` 会抛出 `AuthenticationException`，错误代码为 `AuthenticationErrorCodes.ClientInvalidProfile`

### 当前配置文件##current-profile

要查看当前配置文件，请使用 `AuthenticationService.Instance.Profile`。

### 默认配置文件##default-profile

如果初始化选项中未提供配置文件，则会使用 `default` 值。

### 在初始化时设置配置文件##set-the-profile-at-initialization

您也可以在初始化 `UnityServices` 时设置配置文件。如果未提供配置文件，`AuthenticationService` 将使用 `default` 值。

```cs
async Task InitializeUnityServices()
{
    var options = new InitializationOptions();
    options.SetProfile(“test_profile”);
    await UnityServices.InitializeAsync(options);
}
```

##
