浏览代码

WIP : Stopping point

- unified lobby and player custom data parsing in the LobbyManager
- Fixed a bug pushing the Emote CallbackValue instead of the Emote  Value to the lobby
- Currently working on switching to player lists in the UI, and disconnecting them from the Slots in the Cloud
/main/staging/2021_Upgrade/Async_Refactor
UnityJacob 2 年前
当前提交
a494c1ac
共有 15 个文件被更改,包括 257 次插入253 次删除
  1. 155
      Assets/Scripts/GameLobby/Game/GameManager.cs
  2. 71
      Assets/Scripts/GameLobby/Game/LocalLobby.cs
  3. 12
      Assets/Scripts/GameLobby/Game/LocalPlayer.cs
  4. 56
      Assets/Scripts/GameLobby/Lobby/LobbyConverters.cs
  5. 98
      Assets/Scripts/GameLobby/Lobby/LobbyManager.cs
  6. 6
      Assets/Scripts/GameLobby/Lobby/LobbySynchronizer.cs
  7. 8
      Assets/Scripts/GameLobby/NGO/SetupInGame.cs
  8. 8
      Assets/Scripts/GameLobby/Relay/RelayUtpClient.cs
  9. 4
      Assets/Scripts/GameLobby/Relay/RelayUtpHost.cs
  10. 5
      Assets/Scripts/GameLobby/UI/CreateMenuUI.cs
  11. 13
      Assets/Scripts/GameLobby/UI/InLobbyUserUI.cs
  12. 29
      Assets/Scripts/GameLobby/UI/LobbyUserListUI.cs
  13. 6
      Assets/Scripts/GameLobby/UI/ReadyCheckUI.cs
  14. 35
      Assets/Scripts/GameLobby/UI/RecolorForLobbyType.cs
  15. 4
      Assets/Scripts/GameLobby/UI/UserStateVisibilityUI.cs

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


maxPlayers,
isPrivate, m_LocalUser);
if (lobby == null)
{
SetGameState(GameState.JoinMenu);
return;
}
await LobbyManager.SubscribeToLocalLobbyChanges(lobby.Id, m_LocalLobby);
CreateLobby();
await CreateLobby();
Debug.LogError(exception);
Debug.LogError($"Error creating lobby : {exception} ");
}
}

{
var lobby = await LobbyManager.JoinLobbyAsync(lobbyID, lobbyCode,
m_LocalUser);
if (lobby == null)
{
SetGameState(GameState.JoinMenu);
return;
}
await LobbyManager.SubscribeToLocalLobbyChanges(lobby.Id, m_LocalLobby);
JoinLobby();
await JoinLobby();
Debug.LogError(exception);
Debug.LogError($"Error joining lobby : {exception} ");
}
}

if (lobby != null)
{
LobbyConverters.RemoteToLocal(lobby, m_LocalLobby);
JoinLobby();
await JoinLobby();
}
else
{

}
m_LocalUser.DisplayName.Value = name;
SendLocalUserData();
SetUserEmote(m_LocalUser.Index.Value, emote);
m_LocalUser.Emote.Value = emote;
public void SetUserEmote(int playerID, EmoteType emote)
public void SetLocalUserStatus(PlayerStatus status)
var player = m_LocalLobby.GetLocalPlayer(playerID);
if (player == null)
return;
player.Emote.Value = emote;
}
public void SetLocalUserStatus(UserStatus status)
{
SetUserStatus(m_LocalUser.Index.Value, status);
m_LocalUser.UserStatus.Value = status;
public void SetUserStatus(int playerID, UserStatus status)
public void SetLocalLobbyColor(int color)
var player = m_LocalLobby.GetLocalPlayer(playerID);
if (player == null)
return;
player.UserStatus.Value = status;
m_LocalLobby.LocalLobbyColor.Value = (LobbyColor)color;
SendLocalLobbyData();
await LobbyManager.UpdateLobbyDataAsync(LobbyConverters.LocalToRemoteData(m_LocalLobby));
await LobbyManager.UpdateLobbyDataAsync(LobbyConverters.LocalToRemoteLobbyData(m_LocalLobby));
}
public void CompleteCountDown()
{
Debug.Log("CountDown Complete!");
}
public void ChangeMenuState(GameState state)

public void ConfirmIngameState()
//Only Host needs to listen to this and change state.
void OnPlayersReady(int readyCount)
m_setupInGame.ConfirmInGameState();
if (readyCount == m_LocalLobby.PlayerCount &&
m_LocalLobby.LocalLobbyState.Value != LobbyState.CountDown)
{
m_LocalLobby.LocalLobbyState.Value = LobbyState.CountDown;
SendLocalLobbyData();
}
else if (m_LocalLobby.LocalLobbyState.Value == LobbyState.CountDown)
{
m_LocalLobby.LocalLobbyState.Value = LobbyState.Lobby;
SendLocalLobbyData();
}
public void BeginGame()
void OnLobbyStateChanged(LobbyState state)
if (m_LocalUser.IsHost.Value)
m_LocalLobby.Locked.Value = true;
m_LocalLobby.LocalLobbyState.Value = LobbyState.InGame;
m_setupInGame?.MiniGameBeginning();
if (state == LobbyState.Lobby)
CancelCountDown();
if (state == LobbyState.CountDown)
BeginCountDown();
public void EndGame()
{
m_LocalLobby.LocalLobbyState.Value = LobbyState.Lobby;
m_setupInGame?.OnGameEnd();
LocalUserToLobby();
}
public void BeginCountdown()
public void BeginCountDown()
m_LocalLobby.LocalLobbyState.Value = LobbyState.CountDown;
SendLocalLobbyData();
}
public void CancelCountDown()

m_LocalLobby.LocalLobbyState.Value = LobbyState.Lobby;
m_LocalUser.UserStatus.Value = UserStatus.InGame;
m_LocalUser.UserStatus.Value = PlayerStatus.InGame;
public void BeginGame()
{
if (m_LocalUser.IsHost.Value)
{
m_LocalLobby.LocalLobbyState.Value = LobbyState.InGame;
m_LocalLobby.Locked.Value = true;
SendLocalLobbyData();
}
m_setupInGame?.MiniGameBeginning();
}
public void EndGame()
{
if (m_LocalUser.IsHost.Value)
{
m_LocalLobby.LocalLobbyState.Value = LobbyState.Lobby;
m_LocalLobby.Locked.Value = false;
SendLocalLobbyData();
}
m_setupInGame?.OnGameEnd();
SetLobbyView();
}
#region Setup
async void Awake()

var unused = Locator.Get;
var _ = Locator.Get;
#pragma warning restore IDE0059
Application.wantsToQuit += OnWantToQuit;

m_LocalUser.ID.Value = localId;
m_LocalUser.DisplayName.Value = randomName;
m_LocalUser.Index.Value = 0;
m_LocalLobby.AddPlayer(m_LocalUser); // The local LocalPlayer object will be hooked into UI
}
#endregion

bool isLeavingLobby = (state == GameState.Menu || state == GameState.JoinMenu) &&
LocalGameState == GameState.Lobby;
var isLeavingLobby = (state == GameState.Menu || state == GameState.JoinMenu) &&
LocalGameState == GameState.Lobby;
LocalGameState = state;
Debug.Log($"Switching Game State to : {LocalGameState}");
if (isLeavingLobby)

LobbyList.CurrentLobbies = newLobbyDict;
}
void CreateLobby()
async Task CreateLobby()
JoinLobby();
m_LocalLobby.onUserReadyChange = OnPlayersReady;
try
{
await JoinLobby();
}
catch (Exception exception)
{
Debug.LogError($"Couldn't join Lobby: {exception}");
}
void JoinLobby()
async Task JoinLobby()
LocalUserToLobby();
await LobbyManager.BindLocalLobbyToRemote(m_LocalLobby.LobbyID.Value, m_LocalLobby);
m_LocalLobby.LocalLobbyState.onChanged += OnLobbyStateChanged;
SetLobbyView();
StartVivoxJoin();
}

{
yield return new WaitForSeconds(5);
if (m_LocalLobby != null && m_LocalLobby.LobbyID.Value == lobbyId && !string.IsNullOrEmpty(lobbyId)
) // Ensure we didn't leave the lobby during this waiting period.
) // Ensure we didn't leave the lobby during this waiting period.
void LocalUserToLobby()
void SetLobbyView()
SetLocalUserStatus(UserStatus.Lobby);
SetLocalUserStatus(PlayerStatus.Lobby);
m_LocalLobby.AddPlayer(m_LocalUser); // As before, the local player will need to be plugged into UI before the lobby join actually happens.
m_LocalLobby.RelayServer = null;
}

#endregion
}
}
}

71
Assets/Scripts/GameLobby/Game/LocalLobby.cs


[System.Serializable]
public class LocalLobby
{
public bool CanSetChanged = true;
public Action<int> onUserLeft;
Dictionary<int, LocalPlayer> m_LocalPlayers = new Dictionary<int, LocalPlayer>();
#region LocalLobbyData
ServerAddress m_RelayServer;
public Action<int> onUserLeft;
/// <summary>Used only for visual output of the Relay connection info. The obfuscated Relay server IP is obtained during allocation in the RelayUtpSetup.</summary>
public Action<int> onUserReadyChange;
#endregion.
public CallbackValue<string> LobbyID = new CallbackValue<string>();
public CallbackValue<string> LobbyCode = new CallbackValue<string>();

public CallbackValue<ServerAddress> RelayServer = new CallbackValue<ServerAddress>();
public CallbackValue<string> LobbyName = new CallbackValue<string>();
public CallbackValue<bool> Private = new CallbackValue<bool>();
public CallbackValue<int> AvailableSlots = new CallbackValue<int>();

public CallbackValue<long> LastUpdated = new CallbackValue<long>();
public int PlayerCount => m_LocalPlayers.Count;
ServerAddress m_RelayServer;
public List<LocalPlayer> LocalPlayers => m_LocalPlayers;
List<LocalPlayer> m_LocalPlayers = new List<LocalPlayer>();
public void ResetLobby()
{

LocalLobbyColor.Value = LobbyRelaySample.LobbyColor.None;
AvailableSlots.Value = 4;
MaxPlayerCount.Value = 4;
onUserJoined = null;
onUserLeft = null;
}
public LocalLobby()

public LocalPlayer GetLocalPlayer(int index)
{
if (PlayerCount < index)
return m_LocalPlayers[index];
return null;
}
void SetValueChanged()
public void AddPlayer(int index, LocalPlayer user)
if (CanSetChanged)
m_ValuesChanged = true;
Debug.Log($"Adding User: {user.DisplayName.Value} - {user.ID.Value}");
m_LocalPlayers.Insert(index, user);
user.UserStatus.onChanged += OnUserChangedStatus;
onUserJoined?.Invoke(user);
bool m_ValuesChanged;
public LocalPlayer GetLocalPlayer(int index)
public void RemovePlayer(int playerIndex)
return m_LocalPlayers[index];
m_LocalPlayers[playerIndex].UserStatus.onChanged -= OnUserChangedStatus;
m_LocalPlayers.RemoveAt(playerIndex);
onUserLeft?.Invoke(playerIndex);
public void AddPlayer(LocalPlayer user)
void OnUserChangedStatus(PlayerStatus status)
if (m_LocalPlayers.ContainsKey(user.Index.Value))
int readyCount = 0;
foreach (var player in m_LocalPlayers)
Debug.LogError(
$"Cant add player {user.DisplayName.Value}({user.ID.Value}) to lobby: {LobbyID.Value} twice");
return;
if (player.UserStatus.Value == PlayerStatus.Ready)
readyCount++;
Debug.Log($"Adding User: {user.DisplayName.Value} - {user.ID.Value}");
m_LocalPlayers.Add(user.Index.Value, user);
onUserJoined?.Invoke(user);
onUserReadyChange?.Invoke(readyCount);
public void RemovePlayer(int removePlayer)
{
var player = m_LocalPlayers[removePlayer];
m_LocalPlayers.Remove(removePlayer);
onUserLeft?.Invoke(removePlayer);
}
public override string ToString()
{

return sb.ToString();
}
}
}
}

12
Assets/Scripts/GameLobby/Game/LocalPlayer.cs


/// This is a Flags enum to allow for the Inspector to select multiples for various UI features.
/// </summary>
[Flags]
public enum UserStatus
public enum PlayerStatus
{
None = 0,
Connecting = 1, // User has joined a lobby but has not yet connected to Relay.

public CallbackValue<bool> IsHost = new CallbackValue<bool>(false);
public CallbackValue<string> DisplayName = new CallbackValue<string>("");
public CallbackValue<EmoteType> Emote = new CallbackValue<EmoteType>(EmoteType.None);
public CallbackValue<UserStatus> UserStatus = new CallbackValue<UserStatus>((UserStatus)0);
public CallbackValue<PlayerStatus> UserStatus = new CallbackValue<PlayerStatus>((PlayerStatus)0);
public LocalPlayer(string id, int index, bool isHost, string displayName,
EmoteType emote = default, UserStatus status = default)
public LocalPlayer(string id, int index, bool isHost, string displayName = default,
EmoteType emote = default, PlayerStatus status = default)
{
ID.Value = id;
IsHost.Value = isHost;

{
IsHost.Value = false;
Emote.Value = EmoteType.None;
UserStatus.Value = LobbyRelaySample.UserStatus.Menu;
UserStatus.Value = LobbyRelaySample.PlayerStatus.Menu;
}
}

56
Assets/Scripts/GameLobby/Lobby/LobbyConverters.cs


const string key_Userstatus = nameof(LocalPlayer.UserStatus);
const string key_Emote = nameof(LocalPlayer.Emote);
public static Dictionary<string, string> LocalToRemoteData(LocalLobby lobby)
public static Dictionary<string, string> LocalToRemoteLobbyData(LocalLobby lobby)
data.Add(key_LobbyState,
((int)lobby.LocalLobbyState.Value)
.ToString()); // Using an int is smaller than using the enum state's name.
data.Add(key_LobbyState, ((int)lobby.LocalLobbyState.Value).ToString());
data.Add(key_LobbyColor, ((int)lobby.LocalLobbyColor.Value).ToString());
data.Add(key_LastEdit, lobby.LastUpdated.Value.ToString());

if (user == null || string.IsNullOrEmpty(user.ID.Value))
return data;
data.Add(key_Displayname, user.DisplayName.Value);
data.Add(key_Userstatus,
((int)user.UserStatus.Value)
.ToString()); // Cheaper to send the string int of the enum over the string enum
data.Add(key_Emote, (user.Emote).ToString());
data.Add(key_Userstatus, ((int)user.UserStatus.Value).ToString());
data.Add(key_Emote, ((int)user.Emote.Value).ToString());
return data;
}

public static void RemoteToLocal(Lobby remoteLobby, LocalLobby localLobby, bool allowSetLobbyChanged = true)
public static void RemoteToLocal(Lobby remoteLobby, LocalLobby localLobby)
{
if (remoteLobby == null)
{

return;
}
localLobby.CanSetChanged = allowSetLobbyChanged;
localLobby.HostID.Value = remoteLobby.HostId;
localLobby.LobbyName.Value = remoteLobby.Name;
localLobby.LobbyCode.Value = remoteLobby.LobbyCode;
localLobby.Private.Value = remoteLobby.IsPrivate;

//Custom User Data Conversions
List<string> remotePlayerIDs = new List<string>();
int index = 0;
foreach (var player in remoteLobby.Players)
{
var id = player.Id;

? (EmoteType)int.Parse(player.Data[key_Emote].Value)
: EmoteType.None;
var userStatus = player.Data?.ContainsKey(key_Userstatus) == true
? (UserStatus)int.Parse(player.Data[key_Userstatus].Value)
: UserStatus.Lobby;
? (PlayerStatus)int.Parse(player.Data[key_Userstatus].Value)
: PlayerStatus.Lobby;
LocalPlayer localPlayer;
LocalPlayer localPlayer = localLobby.GetLocalPlayer(index);
//See if we have the remote player locally already
// if (localLobby.LocalPlayers.ContainsKey(player.Id))
// {
// localPlayer = localLobby.LocalPlayers[player.Id];
// localPlayer.ID.Value = id;
// localPlayer.DisplayName.Value = displayName;
// localPlayer.Emote.Value = emote;
// localPlayer.UserStatus.Value = userStatus;
// }
// else
// {
// localPlayer = new LocalPlayer(id, isHost, displayName, emote, userStatus);
// localLobby.AddPlayer(localPlayer);
// }
}
if (localPlayer == null)
{
localPlayer = new LocalPlayer(id, index, isHost, displayName, emote, userStatus);
localLobby.AddPlayer(index, localPlayer);
}
else
{
localPlayer.ID.Value = id;
localPlayer.Index.Value = index;
localPlayer.IsHost.Value = isHost;
localPlayer.DisplayName.Value = displayName;
localPlayer.Emote.Value = emote;
localPlayer.UserStatus.Value = userStatus;
}
localLobby.CanSetChanged = true;
index++;
}
}
/// <summary>

return retLst;
}
//This might be heavy handed,
static LocalLobby RemoteToNewLocal(Lobby lobby)
{
LocalLobby data = new LocalLobby();

98
Assets/Scripts/GameLobby/Lobby/LobbyManager.cs


public Lobby CurrentLobby => m_CurrentLobby;
Lobby m_CurrentLobby;
LobbyEventCallbacks m_LobbyEventCallbacks = new LobbyEventCallbacks();
const int k_maxLobbiesToShow = 16; // If more are necessary, consider retrieving paginated results or using filters.
const int
k_maxLobbiesToShow = 16; // If more are necessary, consider retrieving paginated results or using filters.
Task m_HeartBeatTask;

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

return await LobbyService.Instance.QueryLobbiesAsync(queryOptions);
}
public async Task SubscribeToLocalLobbyChanges(string lobbyID, LocalLobby localLobby)
public async Task BindLocalLobbyToRemote(string lobbyID, LocalLobby localLobby)
{
m_LobbyEventCallbacks.LobbyChanged += async changes =>
{

foreach (var change in changes.Data.Value)
{
var changedValue = change.Value;
var changedKey = change.Key;
if (changedValue.Removed)
{
RemoveCustomLobbyData(changedKey);
}
var changedKey = change.Key;
ParseRemoteLobbyData(changedKey, changedValue.Value);
ParseCustomLobbyData(changedKey, changedValue.Value);
void ParseRemoteLobbyData(string changedKey, DataObject playerDataObject)
void ParseCustomLobbyData(string changedKey, DataObject playerDataObject)
{
if (changedKey == key_RelayCode)
localLobby.RelayCode.Value = playerDataObject.Value;

if (changedKey == key_LobbyColor)
localLobby.LocalLobbyColor.Value = (LobbyColor)int.Parse(playerDataObject.Value);
}
void RemoveCustomLobbyData(string changedKey)
{
if (changedKey == key_RelayCode)
localLobby.RelayCode.Value = "";
if (changedKey == key_RelayNGOCode)
localLobby.RelayNGOCode.Value = "";
}
}
void PlayersJoined()

var id = joinedPlayer.Id;
var index = playerChanges.PlayerIndex;
var isHost = localLobby.HostID.Value == id;
var isHost = localLobby.HostID.Value.Equals(id);
var displayName = joinedPlayer.Data?.ContainsKey(key_Displayname) == true
? joinedPlayer.Data[key_Displayname].Value
: default;
var emote = joinedPlayer.Data?.ContainsKey(key_Emote) == true
? (EmoteType)int.Parse(joinedPlayer.Data[key_Emote].Value)
: EmoteType.None;
var userStatus = joinedPlayer.Data?.ContainsKey(key_Userstatus) == true
? (UserStatus)int.Parse(joinedPlayer.Data[key_Userstatus].Value)
: UserStatus.Lobby;
var newPlayer = new LocalPlayer(id, index, isHost);
foreach (var dataEntry in joinedPlayer.Data)
{
var dataObject = dataEntry.Value;
ParseCustomPlayerData(newPlayer, dataEntry.Key, dataObject.Value);
}
var newPlayer = new LocalPlayer(id, index, isHost, displayName, emote, userStatus);
localLobby.AddPlayer(newPlayer);
localLobby.AddPlayer(index, newPlayer);
}
}

{
var lastUpdated = playerChanges.LastUpdatedChanged.Value;
Debug.Log(
$"ConnectionInfo for {localPlayer.DisplayName.Value} changed to {lastUpdated}");
$"LastUpdated for {localPlayer.DisplayName.Value} changed to {lastUpdated}");
}
if (playerChanges.ChangedData.Changed)

{
if (changedValue.Removed)
{
Debug.LogWarning("This Sample does not remove Values currently.");
Debug.LogWarning("This Sample does not remove Player Values currently.");
var changedKey = playerChange.Key;
ParseLocalPlayerData(changedKey, playerDataObject);
ParseCustomPlayerData(localPlayer, playerChange.Key, playerDataObject.Value);
void ParseLocalPlayerData(string dataKey, PlayerDataObject playerDataObject)
{
localPlayer.DisplayName.Value = dataKey == key_Displayname
? playerDataObject.Value
: default;
localPlayer.Emote.Value = dataKey == key_Emote
? (EmoteType)int.Parse(playerDataObject.Value)
: EmoteType.None;
localPlayer.UserStatus.Value = dataKey == key_Userstatus
? (UserStatus)int.Parse(playerDataObject.Value)
: UserStatus.Lobby;
}
}
}
};

Debug.Log($"Lobby Event Changed {lobbyEventConnectionState}");
Debug.Log($"Lobby ConnectionState Changed to {lobbyEventConnectionState}");
};
m_LobbyEventCallbacks.KickedFromLobby += () =>

await LobbyService.Instance.SubscribeToLobbyEventsAsync(lobbyID, m_LobbyEventCallbacks);
}
void ParseCustomPlayerData(LocalPlayer player, string dataKey, string playerDataValue)
{
if (dataKey == key_Emote)
player.Emote.Value = (EmoteType)int.Parse(playerDataValue);
else if (dataKey == key_Userstatus)
player.UserStatus.Value = (PlayerStatus)int.Parse(playerDataValue);
else if (dataKey == key_Displayname)
player.DisplayName.Value = playerDataValue;
}
public async Task<Lobby> GetLobbyAsync(string lobbyId = null)
{

m_CurrentLobby = null;
}
public async Task<Lobby> UpdatePlayerDataAsync(Dictionary<string, string> data)
public async Task UpdatePlayerDataAsync(Dictionary<string, string> data)
return null;
return;
await m_UpdatePlayerCooldown.WaitUntilCooldown();
Debug.Log("Lobby - Updating Player Data");

AllocationId = null,
ConnectionInfo = null
};
return m_CurrentLobby =
await LobbyService.Instance.UpdatePlayerAsync(m_CurrentLobby.Id, playerId, updateOptions);
m_CurrentLobby = await LobbyService.Instance.UpdatePlayerAsync(m_CurrentLobby.Id, playerId, updateOptions);
}
public async Task<Lobby> UpdatePlayerRelayInfoAsync(string lobbyID, string allocationId, string connectionInfo)

return m_CurrentLobby = await LobbyService.Instance.UpdatePlayerAsync(lobbyID, playerId, updateOptions);
}
public async Task<Lobby> UpdateLobbyDataAsync(Dictionary<string, string> data)
public async Task UpdateLobbyDataAsync(Dictionary<string, string> data)
return null;
return;
await m_UpdateLobbyCooldown.WaitUntilCooldown();
Debug.Log("Lobby - Updating Lobby Data");

}
UpdateLobbyOptions updateOptions = new UpdateLobbyOptions { Data = dataCurr, IsLocked = shouldLock };
return m_CurrentLobby = await LobbyService.Instance.UpdateLobbyAsync(m_CurrentLobby.Id, updateOptions);
m_CurrentLobby = await LobbyService.Instance.UpdateLobbyAsync(m_CurrentLobby.Id, updateOptions);
}
public async Task DeleteLobbyAsync()

QueryFilter.OpOptions.EQ));
return filters;
}
//Since the LobbyManager maintains the "connection" to the lobby, we will continue to heartbeat until host leaves.
async Task SendHeartbeatPingAsync()
{

}
}
}
}
}

6
Assets/Scripts/GameLobby/Lobby/LobbySynchronizer.cs


// var areAllusersReady = AreAllUsersReady();
// if (areAllusersReady && m_LocalLobby.LocalLobbyState.Value == LobbyState.Lobby)
// {
// GameManager.Instance.BeginCountdown();
// GameManager.Instance.BeginCountDown();
// }
// else if (!areAllusersReady && m_LocalLobby.LocalLobbyState.Value == LobbyState.CountDown)
// {

//
// if (m_LocalUser.IsHost.Value)
// await m_LobbyManager.UpdateLobbyDataAsync(
// LobbyConverters.LocalToRemoteData(m_LocalLobby));
// LobbyConverters.LocalToRemoteLobbyData(m_LocalLobby));
//
// return await m_LobbyManager.UpdatePlayerDataAsync(
// LobbyConverters.LocalToRemoteUserData(m_LocalUser));

// {
// foreach (var lobbyUser in m_LocalLobby.LocalPlayers.Values)
// {
// if (lobbyUser.UserStatus.Value != UserStatus.Ready)
// if (lobbyUser.PlayerStatus.Value != PlayerStatus.Ready)
// {
// return false;
// }

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


joinAllocation.ConnectionData, joinAllocation.HostConnectionData, isSecure);
}
/// <summary>
/// Determine the server endpoint for connecting to the Relay server, for either an Allocation or a JoinAllocation.
/// If DTLS encryption is available, and there's a secure server endpoint available, use that as a secure connection. Otherwise, just connect to the Relay IP unsecured.

#pragma warning restore 4014
}
public void ConfirmInGameState()
{
}
public void MiniGameBeginning()
{
if (!m_hasConnectedViaNGO)

}
}
}
}
}

8
Assets/Scripts/GameLobby/Relay/RelayUtpClient.cs


}
else if (msgType == MsgType.ReadyState)
{
UserStatus status = (UserStatus)msgContents[0];
m_localLobby.LocalPlayers[id].UserStatus.Value = status;
PlayerStatus status = (PlayerStatus)msgContents[0];
m_localLobby.LocalPlayers[id].PlayerStatus.Value = status;
GameManager.Instance.BeginCountdown();
GameManager.Instance.BeginCountDown();
else if (msgType == MsgType.CancelCountdown)
GameManager.Instance.CancelCountDown();
else if (msgType == MsgType.ConfirmInGame)

// Note that it would be better to send a single message with the full state, but for the sake of shorter code we'll leave that out here.
WriteString(driver, connection, user.ID.Value, MsgType.PlayerName, user.DisplayName.Value);
WriteByte(driver, connection, user.ID.Value, MsgType.Emote, (byte)user.Emote.Value);
WriteByte(driver, connection, user.ID.Value, MsgType.ReadyState, (byte)user.UserStatus.Value);
WriteByte(driver, connection, user.ID.Value, MsgType.ReadyState, (byte)user.PlayerStatus.Value);
}
/// <summary>

4
Assets/Scripts/GameLobby/Relay/RelayUtpHost.cs


// {
// byte value = msgType == MsgType.Emote
// ? (byte)m_localLobby.LocalPlayers[id].Emote.Value
// : (byte)m_localLobby.LocalPlayers[id].UserStatus.Value;
// : (byte)m_localLobby.LocalPlayers[id].PlayerStatus.Value;
// foreach (NetworkConnection otherConn in m_connections)
// {
// if (otherConn == conn)

// bool haveAllReadied = true;
// foreach (var user in m_localLobby.LocalPlayers)
// {
// if (user.Value.UserStatus.Value != UserStatus.Ready)
// if (user.Value.PlayerStatus.Value != PlayerStatus.Ready)
// {
// haveAllReadied = false;
// break;

5
Assets/Scripts/GameLobby/UI/CreateMenuUI.cs


public void OnCreatePressed()
{
//Disabled as it's a one-off butto call
Manager.CreateLobby(m_ServerName, m_IsServerPrivate);
Manager.CreateLobby(m_ServerName, m_IsServerPrivate);
}
}

13
Assets/Scripts/GameLobby/UI/InLobbyUserUI.cs


using TMPro;
using UnityEngine;
using UnityEngine.UI;

m_DisplayNameText.SetText(displayName);
}
void SetUserStatus(UserStatus statusText)
void SetUserStatus(PlayerStatus statusText)
{
m_StatusText.SetText(SetStatusFancy(statusText));
}

}
}
string SetStatusFancy(UserStatus status)
string SetStatusFancy(PlayerStatus status)
case UserStatus.Lobby:
case PlayerStatus.Lobby:
case UserStatus.Ready:
case PlayerStatus.Ready:
case UserStatus.Connecting:
case PlayerStatus.Connecting:
case UserStatus.InGame:
case PlayerStatus.InGame:
return "<color=#005500>In Game</color>"; // Green
default:
return "";

29
Assets/Scripts/GameLobby/UI/LobbyUserListUI.cs


[SerializeField]
List<InLobbyUserUI> m_UserUIObjects = new List<InLobbyUserUI>();
LocalLobby m_LocalLobby;
GameManager.Instance.LocalLobby.onUserJoined += OnUserJoined;
GameManager.Instance.LocalLobby.onUserLeft += OnUserLeft;
m_LocalLobby = GameManager.Instance.LocalLobby;
m_LocalLobby.onUserJoined += OnUserJoined;
m_LocalLobby.onUserLeft += OnUserLeft;
var lobbySlot = m_UserUIObjects[localPlayer.Index.Value];
lobbySlot.SetUser(localPlayer);
SynchPlayerUI();
m_UserUIObjects[i].ResetUI();
SynchPlayerUI();
void SynchPlayerUI()
{
foreach (var ui in m_UserUIObjects)
ui.ResetUI();
for (int i = 0; i < m_LocalLobby.PlayerCount; i++)
{
var lobbySlot = m_UserUIObjects[i];
var player = m_LocalLobby.GetLocalPlayer(i);
if (player == null)
continue;
lobbySlot.SetUser(player);
}
}
}
}

6
Assets/Scripts/GameLobby/UI/ReadyCheckUI.cs


{
public void OnReadyButton()
{
ChangeState(UserStatus.Ready);
ChangeState(PlayerStatus.Ready);
ChangeState(UserStatus.Lobby);
ChangeState(PlayerStatus.Lobby);
void ChangeState(UserStatus status)
void ChangeState(PlayerStatus status)
{
Manager.SetLocalUserStatus(status);
}

35
Assets/Scripts/GameLobby/UI/RecolorForLobbyType.cs


/// </summary>
public class RecolorForLobbyType : MonoBehaviour
{
private static readonly Color s_orangeColor = new Color(0.8352942f, 0.3686275f, 0);
private static readonly Color s_greenColor = new Color(0, 0.6196079f, 0.4509804f);
private static readonly Color s_blueColor = new Color(0.0f, 0.4470589f, 0.6980392f);
private static readonly Color[] s_colorsOrdered = new Color[] { new Color(0.9f, 0.9f, 0.9f, 0.7f), s_orangeColor, s_greenColor, s_blueColor };
static readonly Color s_orangeColor = new Color(0.8352942f, 0.3686275f, 0);
static readonly Color s_greenColor = new Color(0, 0.6196079f, 0.4509804f);
static readonly Color s_blueColor = new Color(0.0f, 0.4470589f, 0.6980392f);
static readonly Color[] s_colorsOrdered = new Color[]
{ new Color(0.9f, 0.9f, 0.9f, 0.7f), s_orangeColor, s_greenColor, s_blueColor };
private Graphic[] m_toRecolor;
private LocalLobby m_lobby;
Graphic[] m_toRecolor;
LocalLobby m_lobby;
public void Start()
void Start()
public void ChangeColors(LobbyColor lobbyColor)
{
Color color = s_colorsOrdered[(int)lobbyColor];
foreach (Graphic graphic in m_toRecolor)
graphic.color = new Color(color.r, color.g, color.b, graphic.color.a);
}
/// <summary>
/// Called in-editor by toggles to set the color of the lobby.
/// Triggers the ChangeColors method above

if (m_lobby != null)
m_lobby.LocalLobbyColor.Value = (LobbyColor)color;
GameManager.Instance.SetLocalLobbyColor(color);
}
void ChangeColors(LobbyColor lobbyColor)
{
Color color = s_colorsOrdered[(int)lobbyColor];
foreach (Graphic graphic in m_toRecolor)
graphic.color = new Color(color.r, color.g, color.b, graphic.color.a);
}
}

4
Assets/Scripts/GameLobby/UI/UserStateVisibilityUI.cs


/// </summary>
public class UserStateVisibilityUI : UIPanelBase
{
public UserStatus ShowThisWhen;
public PlayerStatus ShowThisWhen;
public UserPermission Permissions;
bool m_HasStatusFlags = false;
bool m_HasPermissions;

localUser.UserStatus.onChanged += OnUserStatusChanged;
}
void OnUserStatusChanged(UserStatus observedStatus)
void OnUserStatusChanged(PlayerStatus observedStatus)
{
m_HasStatusFlags = ShowThisWhen.HasFlag(observedStatus);
CheckVisibility();

正在加载...
取消
保存