退出游戏

当游戏不再希望用户登录时,它会调用 VivoxService.Instance.LogoutAsync 方法。用户退出后,Vivox SDK 不会收到或发送任何网络流量。

Note: This is typically called when quitting the application, or in the scenario where a user can sign in to different accounts within an app, when disconnecting from the game server.

以下代码显示了退出过程的示例

using UnityEngine;
using Unity.Services.Vivox;

class LogoutExample : MonoBehaviour
{
    void LogOut()
    {
        VivoxService.Instance.LogoutAsync();
    }
}

为了处理由于连接问题造成的退出,游戏必须处理事件 VivoxService.Instance.LoggedOut。当 Vivox 的连接意外丢失时,例如网络连接问题,或者用户手动启动退出时,Vivox SDK 会发送此消息。

以下代码是订阅 VivoxService.Instance.LoggedOut 事件的示例

using UnityEngine;
using Unity.Services.Vivox;
using System.Components;

class SessionPropChangeExample : MonoBehaviour
{
    VivoxService.Instance.LoggedOut += onVivoxLoggedOut;

    private void onVivoxLoggedOut()
    {
        //Vivox has logged out, and clean up should be done
    }
}