浏览代码

Removed LobbyAPIInterface completely.

Re-hooked up polling loop to LobbyContentUpdater
/main/staging/2021_Upgrade/Async_Refactor
当前提交
abc179d2
共有 6 个文件被更改,包括 19 次插入119 次删除
  1. 2
      Assets/Scripts/GameLobby/Game/GameManager.cs
  2. 11
      Assets/Scripts/GameLobby/Lobby/LobbyContentUpdater.cs
  3. 2
      Assets/Scripts/GameLobby/NGO/SetupInGame.cs
  4. 28
      Assets/Scripts/GameLobby/Tests/PlayMode/LobbyRoundtripTests.cs
  5. 11
      Assets/Scripts/GameLobby/Lobby/LobbyAPIInterface.cs.meta
  6. 84
      Assets/Scripts/GameLobby/Lobby/LobbyAPIInterface.cs

2
Assets/Scripts/GameLobby/Game/GameManager.cs


}
}
private async void OnLeftLobby()
private void OnLeftLobby()
{
m_localUser.ResetState();
#pragma warning disable 4014

11
Assets/Scripts/GameLobby/Lobby/LobbyContentUpdater.cs


#pragma warning restore 4014
m_lifetime = 0;
LobbyAsyncRequests.Instance.onLobbyUpdated += OnRemoteLobbyUpdated;
}
public void EndTracking()

Locator.Get.Messenger.Unsubscribe(this);
if (m_LocalLobby != null)
m_LocalLobby.onChanged -= OnLocalLobbyChanged;
LobbyAsyncRequests.Instance.onLobbyUpdated -= OnRemoteLobbyUpdated;
m_LocalLobby = null;
}

if (m_ShouldPushData)
PushDataToLobby();
else
UpdateLocalLobby();
void PushDataToLobby()
{

}
}
void OnRemoteLobbyUpdated(Lobby lobby)
void UpdateLocalLobby()
var remoteLobby = LobbyAsyncRequests.Instance.CurrentLobby;
if (remoteLobby == null)
return;
LobbyConverters.RemoteToLocal(lobby, m_LocalLobby);
LobbyConverters.RemoteToLocal(remoteLobby, m_LocalLobby);
//Dont push data this tick, since we "pulled"s
if (!m_LocalUser.IsHost)

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


{
m_doesNeedCleanup = true;
SetMenuVisibility(false);
#pragma warning disable 4014
#pragma warning restore 4014
}
else if (type == MessageType.MinigameBeginning)

28
Assets/Scripts/GameLobby/Tests/PlayMode/LobbyRoundtripTests.cs


yield return
new WaitForSeconds(
1); // To prevent a possible 429 with the upcoming Query request, in case a previous test had one; Query requests can only occur at a rate of 1 per second.
QueryResponse queryResponse = null;
QueryResponse queryResponse = null;
Debug.Log("Got Lobby List 1");
// Create a test lobby.
Lobby createResponse = null;

Assert.IsNotNull(createResponse, "CreateLobbyAsync should return a non-null result.");
m_workingLobbyId = createResponse.Id;
Assert.AreEqual(lobbyName, createResponse.Name, "Created lobby should match the provided name.");
Debug.Log("Got Lobby List 2");
Assert.IsNotNull(queryResponse, "QueryAllLobbiesAsync should return a non-null result. (#1)");
Assert.AreEqual(1 + numLobbiesIni, queryResponse.Results.Count, "Queried lobbies list should contain the test lobby.");

// Query for solely the test lobby via GetLobby.
Debug.Log("Getting Lobby");
Lobby lobby = null;
yield return AsyncTestHelper.Await(async ()=> lobby = await LobbyAsyncRequests.Instance.GetLobbyAsync(createResponse.Id));
Debug.Log("Got Lobby");
Debug.Log("Getting current Lobby");
Assert.IsNotNull(lobby, "GetLobbyAsync should return a non-null result.");
Assert.AreEqual(lobbyName, lobby.Name, "Checking the lobby we got for name.");
Assert.AreEqual(m_workingLobbyId, lobby.Id, "Checking the lobby we got for ID.");
Lobby currentLobby = LobbyAsyncRequests.Instance.CurrentLobby;
Assert.IsNotNull(currentLobby, "GetLobbyAsync should return a non-null result.");
Assert.AreEqual(lobbyName, currentLobby.Name, "Checking the lobby we got for name.");
Assert.AreEqual(m_workingLobbyId, currentLobby.Id, "Checking the lobby we got for ID.");
Debug.Log("Deleting current Lobby");
// Query to ensure the lobby is gone.
yield return new WaitForSeconds(1); // To prevent a possible 429 with the upcoming Query request.
Debug.Log("Got Lobby List 3");
Assert.IsNotNull(queryResponse, "QueryAllLobbiesAsync should return a non-null result. (#2)");
Assert.AreEqual(numLobbiesIni, queryResponse.Results.Count, "Queried lobbies list should be empty.");

11
Assets/Scripts/GameLobby/Lobby/LobbyAPIInterface.cs.meta


fileFormatVersion: 2
guid: 03c4b466cb7c8c64fb37b8b7e7007305
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

84
Assets/Scripts/GameLobby/Lobby/LobbyAPIInterface.cs


using System;
using Unity.Services.Lobbies;
namespace LobbyRelaySample.lobby
{
/// <summary>
/// Wrapper for all the interactions with the Lobby API.
/// </summary>
public static class LobbyAPIInterface
{
/* TODO Delete LobbyAPIInterface
public static void CreateLobbyAsync(string requesterUASId, string lobbyName, int maxPlayers, bool isPrivate, Dictionary<string, PlayerDataObject> localUserData, Action<Lobby> onComplete)
{
CreateLobbyOptions createOptions = new CreateLobbyOptions
{
IsPrivate = isPrivate,
Player = new Player(id: requesterUASId, data: localUserData)
};
var task = LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, createOptions);
AsyncRequestLobby.Instance.DoRequest(task, onComplete);
}
public static void DeleteLobbyAsync(string lobbyId, Action onComplete)
{
var task = LobbyService.Instance.DeleteLobbyAsync(lobbyId);
AsyncRequestLobby.Instance.DoRequest(task, onComplete);
}
public static void JoinLobbyAsync_ByCode(string requesterUASId, string lobbyCode, Dictionary<string, PlayerDataObject> localUserData, Action<Lobby> onComplete)
{
JoinLobbyByCodeOptions joinOptions = new JoinLobbyByCodeOptions { Player = new Player(id: requesterUASId, data: localUserData) };
var task = LobbyService.Instance.JoinLobbyByCodeAsync(lobbyCode, joinOptions);
AsyncRequestLobby.Instance.DoRequest(task, onComplete);
}
public static void JoinLobbyAsync_ById(string requesterUASId, string lobbyId, Dictionary<string, PlayerDataObject> localUserData, Action<Lobby> onComplete)
{
JoinLobbyByIdOptions joinOptions = new JoinLobbyByIdOptions { Player = new Player(id: requesterUASId, data: localUserData) };
var task = LobbyService.Instance.JoinLobbyByIdAsync(lobbyId, joinOptions);
AsyncRequestLobby.Instance.DoRequest(task, onComplete);
}
public static void QuickJoinLobbyAsync(string requesterUASId, List<QueryFilter> filters, Dictionary<string, PlayerDataObject> localUserData, Action<Lobby> onComplete)
{
var joinRequest = new QuickJoinLobbyOptions
{
Filter = filters,
Player = new Player(id: requesterUASId, data: localUserData)
};
var task = LobbyService.Instance.QuickJoinLobbyAsync(joinRequest);
AsyncRequestLobby.Instance.DoRequest(task, onComplete);
}
public static void LeaveLobbyAsync(string requesterUASId, string lobbyId, Action onComplete)
{
var task = LobbyService.Instance.RemovePlayerAsync(lobbyId, requesterUASId);
AsyncRequestLobby.Instance.DoRequest(task, onComplete);
}
/// <summary>
/// Uupdates custom data to the lobby, for all to see.
/// </summary>
public static void UpdateLobbyAsync(string lobbyId, Dictionary<string, DataObject> data, bool shouldLock, Action<Lobby> onComplete)
{
UpdateLobbyOptions updateOptions = new UpdateLobbyOptions { Data = data, IsLocked = shouldLock };
var task = LobbyService.Instance.UpdateLobbyAsync(lobbyId, updateOptions);
AsyncRequestLobby.Instance.DoRequest(task, onComplete);
}
public static void UpdatePlayerAsync(string lobbyId, string playerId, Dictionary<string, PlayerDataObject> data, Action<Lobby> onComplete, string allocationId, string connectionInfo)
{
UpdatePlayerOptions updateOptions = new UpdatePlayerOptions
{
Data = data,
AllocationId = allocationId,
ConnectionInfo = connectionInfo
};
var task = LobbyService.Instance.UpdatePlayerAsync(lobbyId, playerId, updateOptions);
AsyncRequestLobby.Instance.DoRequest(task, onComplete);
}*/
}
}
正在加载...
取消
保存