浏览代码

Small Nitpicks for relay roundtrip and asyncRequests

/main/staging/2021_Upgrade/Async_Refactor
当前提交
a6f862b2
共有 3 个文件被更改,包括 16 次插入11 次删除
  1. 14
      Assets/Scripts/GameLobby/Lobby/LobbyAsyncRequests.cs
  2. 1
      Assets/Scripts/GameLobby/NGO/SetupInGame.cs
  3. 12
      Assets/Scripts/GameLobby/Tests/PlayMode/RelayRoundTripTests.cs

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


private RateLimitCooldown m_rateLimitQuery = new RateLimitCooldown(1.5f); // Used for both the lobby list UI and the in-lobby updating. In the latter case, updates can be cached.
private RateLimitCooldown m_rateLimitJoin = new RateLimitCooldown(3f);
private RateLimitCooldown m_rateLimitHost = new RateLimitCooldown(3f);
private RateLimitCooldown m_rateLimitHost = new RateLimitCooldown(3f);
#endregion

string uasId = AuthenticationService.Instance.PlayerId;
await LobbyService.Instance.RemovePlayerAsync(lobbyId, uasId);
// Lobbies will automatically delete the lobby if unoccupied, so we don't need to take further action.
}
/// <param name="data">Key-value pairs, which will overwrite any existing data for these keys. Presumed to be available to all lobby members but not publicly.</param>

if (result != null)
m_RemoteLobby = result;
}
private const int m_LobbyUpdateTime = 500;
#region LobbyLoops
const int m_LobbyUpdateTime = 1000;
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.

}
}
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.
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>

await Task.Delay(k_heartbeatPeriodMS);
}
}
#endregion
async Task AwaitRemoteLobby()
{

1
Assets/Scripts/GameLobby/NGO/SetupInGame.cs


OnGameEnd();
}
}
else if (type == MessageType.ChangeMenuState)
{
// Once we're in-game, any state change reflects the player leaving the game, so we should clean up.

12
Assets/Scripts/GameLobby/Tests/PlayMode/RelayRoundTripTests.cs


using System;
using System.Collections;
using LobbyRelaySample;
using Test.Tools;
using Unity.Services.Relay;
using Unity.Services.Relay.Models;
using UnityEngine;
using UnityEngine.TestTools;

// Allocation
float timeout = 5;
Allocation allocation = null;
RelayAPIInterface.AllocateAsync(4, (a) => { allocation = a; });
yield return AsyncTestHelper.Await(async () => allocation = await Relay.Instance.CreateAllocationAsync(4));
while (allocation == null && timeout > 0)
{
yield return new WaitForSeconds(0.25f);

// Join code retrieval
timeout = 5;
string joinCode = null;
RelayAPIInterface.GetJoinCodeAsync(allocationId, (j) => { joinCode = j; });
yield return AsyncTestHelper.Await(async () => joinCode = await Relay.Instance.GetJoinCodeAsync(allocationId));
while (joinCode == null && timeout > 0)
{
yield return new WaitForSeconds(0.25f);

// Joining with the join code
timeout = 5;
JoinAllocation joinResponse = null;
RelayAPIInterface.JoinAsync(joinCode, (j) => { joinResponse = j; });
yield return AsyncTestHelper.Await(async () => joinResponse = await Relay.Instance.JoinAllocationAsync(joinCode));
while (joinResponse == null && timeout > 0)
{
yield return new WaitForSeconds(0.25f);

正在加载...
取消
保存