浏览代码

Removed LobbyAPIInterface completely.

Re-hooked up polling loop to LobbyContentUpdater
/main/staging/2021_Upgrade/Async_Refactor
当前提交
8e59f225
共有 1 个文件被更改,包括 27 次插入14 次删除
  1. 41
      Assets/Scripts/GameLobby/Lobby/LobbyAsyncRequests.cs

41
Assets/Scripts/GameLobby/Lobby/LobbyAsyncRequests.cs


using LobbyRelaySample.lobby;
using System;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using JetBrains.Annotations;
using Unity.Services.Authentication;
using Unity.Services.Lobbies;
using Unity.Services.Lobbies.Models;

}
}
public Lobby CurrentLobby => m_RemoteLobby;
public Action<Lobby> onLobbyUpdated;
//Once connected to a lobby, cache the local lobby object so we don't query for it for every lobby operation.
// (This assumes that the player will be actively in just one lobby at a time, though they could passively be in more.)

}
public async Task<Lobby> GetLobbyAsync(string lobbyId)
async Task<Lobby> GetLobbyAsync(string lobbyId)
{
await m_rateLimitQuery.WaitUntilCooldown();

var lobby = await LobbyService.Instance.QuickJoinLobbyAsync(joinRequest);
JoinLobby(lobby);
return lobby;
#pragma warning disable 4014
GetLobbyLoop();
#pragma warning restore 4014
}
/// <summary>

{
await m_rateLimitQuery.WaitUntilCooldown();
Debug.Log("Retrieving Lobby List");
var filters = LobbyColorToFilters(limitToColor);
QueryLobbiesOptions queryOptions = new QueryLobbiesOptions

/// <param name="onComplete">Called once the request completes, regardless of success or failure.</param>
public async Task LeaveLobbyAsync(string lobbyId)
{
m_RemoteLobby = null;
m_RemoteLobby = null;
// Lobbies will automatically delete the lobby if unoccupied, so we don't need to take further action.
}

}
private float m_heartbeatTime = 0;
private const int k_heartbeatPeriodMS = 8000; // The heartbeat must be rate-limited to 5 calls per 30 seconds. We'll aim for longer in case periods don't align.
private const int m_LobbyUpdateTime = 500;
async Task GetLobbyLoop()
{
//In this sample we only use the loop internally, when we've joined. Only after we have joined or created a lobby can we poll for updates.
//Since you only need the ID, there might be a use case to get the lobby before joining it, since you can get the ID's from Querying
while (m_RemoteLobby != null)
{
m_RemoteLobby = await GetLobbyAsync(m_RemoteLobby.Id);
await Task.Delay(m_LobbyUpdateTime);
}
}
private const int k_heartbeatPeriodMS = 8000; // The heartbeat must be rate-limited to 5 calls per 30 seconds. We'll aim for longer in case periods don't align.
/// <summary>
/// Lobby requires a periodic ping to detect rooms that are still active, in order to mitigate "zombie" lobbies.
/// </summary>

public void Dispose()
{
if (m_RemoteLobby == null)
return;
#pragma warning disable 4014
LeaveLobbyAsync(m_RemoteLobby.Id);
#pragma warning restore 4014
}
public class RateLimitCooldown
{

正在加载...
取消
保存