GitHub
4 年前
当前提交
a41d97a0
共有 127 个文件被更改,包括 6015 次插入 和 5290 次删除
-
3.gitignore
-
4Assets/Prefabs/UI/JoinContent.prefab
-
7Assets/Prefabs/UI/LobbyButtonUI.prefab
-
16Assets/Prefabs/UI/LobbyCodeCanvas.prefab
-
22Assets/Prefabs/UI/LobbyGameCanvas.prefab
-
42Assets/Prefabs/UI/LobbyUserList.prefab
-
4Assets/Prefabs/UI/PlayerInteractionPanel.prefab
-
17Assets/Prefabs/UI/RelayCodeCanvas.prefab
-
283Assets/Scenes/mainScene.unity
-
2Assets/Scripts/Auth/Identity.cs
-
2Assets/Scripts/Auth/SubIdentity_Authentication.cs
-
159Assets/Scripts/Entities/GameStateManager.cs
-
6Assets/Scripts/Entities/LobbyServiceData.cs
-
14Assets/Scripts/Entities/LobbyUser.cs
-
542Assets/Scripts/Entities/LocalLobby.cs
-
24Assets/Scripts/Tests/Editor/LobbyTests.cs
-
6Assets/Scripts/Tests/Editor/ObserverTests.cs
-
2Assets/Scripts/Tests/Editor/Tests.Editor.asmdef
-
2Assets/Scripts/Tests/PlayMode/Tests.Play.asmdef
-
3Assets/Scripts/UI/BackButtonUI.cs
-
7Assets/Scripts/UI/CountdownUI.cs
-
7Assets/Scripts/UI/CreateMenuUI.cs
-
3Assets/Scripts/UI/EmoteButtonUI.cs
-
5Assets/Scripts/UI/EndGameButtonUI.cs
-
3Assets/Scripts/UI/ExitButtonUI.cs
-
3Assets/Scripts/UI/GameStateVisibilityUI.cs
-
61Assets/Scripts/UI/JoinMenuUI.cs
-
15Assets/Scripts/UI/LobbyButtonUI.cs
-
2Assets/Scripts/UI/MainMenuUI.cs
-
2Assets/Scripts/UI/NameChangeUI.cs
-
5Assets/Scripts/UI/ObserverPanel.cs
-
3Assets/Scripts/UI/PlayerNameUI.cs
-
3Assets/Scripts/UI/ReadyCheckUI.cs
-
3Assets/Scripts/UI/SpinnerUI.cs
-
3Assets/Scripts/UI/UIPanelBase.cs
-
5Assets/Scripts/UI/UserStateVisibilityUI.cs
-
42Assets/Scripts/UI/JoinCreateLobbyUI.cs
-
4Assets/Scripts/UI/InLobbyUserUI.cs
-
2Assets/Scripts/LobbyRelaySample.asmdef
-
61README.md
-
999~Documentation/Images/dashboard1_beta.png
-
999~Documentation/Images/services1.PNG
-
999~Documentation/Images/services2.PNG
-
251~Documentation/Images/tutorial_1_lobbyList.png
-
353~Documentation/Images/tutorial_2_createMenu.png
-
565~Documentation/Images/tutorial_3_HostGame.png
-
352~Documentation/Images/tutorial_4_newLobby.png
-
947~Documentation/Images/tutorial_5_editorCow.png
-
803~Documentation/Images/tutorial_6_countDown.png
-
971~Documentation/Images/tutorial_7_ingame.png
-
200Assets/Scripts/Infrastructure/Locator.cs
-
126Assets/Scripts/Infrastructure/LogHandler.cs
-
176Assets/Scripts/Infrastructure/Messenger.cs
-
5Assets/Scripts/Auth/NameGenerator.cs
-
276Assets/Scripts/Infrastructure/UpdateSlow.cs
-
4Assets/Scripts/Entities/LocalLobbyObserver.cs
-
130Assets/Scripts/Tests/PlayMode/LobbyReadyCheckTests.cs
-
163Assets/Scripts/Tests/PlayMode/LobbyRoundtripTests.cs
-
33Assets/Scripts/UI/DisplayCodeUI.cs
-
60Assets/Scripts/UI/InLobbyUserList.cs
-
19Assets/Scripts/UI/LobbyNameUI.cs
-
19Assets/Scripts/UI/RelayAddressUI.cs
-
22Assets/Scripts/UI/ShowWhenLobbyStateUI.cs
-
15Assets/Scripts/UI/StartLobbyButtonUI.cs
-
108Assets/Scripts/Lobby/LobbyAPIInterface.cs
-
218Assets/Scripts/Lobby/LobbyAsyncRequests.cs
-
109Assets/Scripts/Lobby/LobbyContentHeartbeat.cs
-
23Assets/Scripts/Lobby/LobbyListHeartbeat.cs
-
63Assets/Scripts/Lobby/ReadyCheck.cs
-
89Assets/Scripts/Lobby/ToLocalLobby.cs
-
4Assets/Scripts/Entities/LobbyDataObserver.cs
-
67Assets/Scripts/Entities/LobbyReadyCheck.cs
-
131Assets/Scripts/Tests/PlayMode/ReadyCheckTests.cs
-
163Assets/Scripts/Tests/PlayMode/RoomsRoundtripTests.cs
-
11Assets/Scripts/UI/RelayCodeUI.cs.meta
-
5Assets/Scripts/UI/SerializedValueEvents.cs
-
11Assets/Scripts/UI/SerializedValueEvents.cs.meta
-
19Assets/Scripts/UI/LobbyStateVisibilityUI.cs
-
60Assets/Scripts/UI/LobbyUsersUI.cs
-
27Assets/Scripts/UI/RelayCodeUI.cs
-
26Assets/Scripts/UI/RoomCodeUI.cs
-
16Assets/Scripts/UI/ServerAddressUI.cs
-
16Assets/Scripts/UI/ServerNameUI.cs
-
12Assets/Scripts/UI/StartLobbyButton.cs
-
8Assets/Scripts/Utilities.meta
-
11Assets/TempDeleteAllRooms.cs.meta
-
33Assets/TempDeleteAllRooms.cs
-
167ProjectSettings/SceneTemplateSettings.json
-
16ProjectSettings/BurstAotSettings_StandaloneWindows.json
-
6ProjectSettings/CommonBurstAotSettings.json
-
0/Assets/Scripts/Entities/LocalLobbyObserver.cs.meta
-
0/Assets/Scripts/Entities/LocalLobby.cs.meta
-
0/Assets/Scripts/Entities/LocalLobby.cs
-
0/Assets/Scripts/Tests/PlayMode/LobbyRoundtripTests.cs.meta
-
0/Assets/Scripts/Tests/PlayMode/LobbyReadyCheckTests.cs.meta
-
0/Assets/Scripts/UI/StartLobbyButtonUI.cs.meta
-
0/Assets/Scripts/UI/ShowWhenLobbyStateUI.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample |
|||
{ |
|||
[Flags] |
|||
public enum LobbyState |
|||
{ |
|||
Lobby = 1, |
|||
CountDown = 2, |
|||
InGame = 4 |
|||
} |
|||
|
|||
public struct LobbyInfo |
|||
{ |
|||
public string RoomID { get; set; } |
|||
public string RoomCode { get; set; } |
|||
public string RelayCode { get; set; } |
|||
public string LobbyName { get; set; } |
|||
public bool Private { get; set; } |
|||
public int MaxPlayerCount { get; set; } |
|||
public LobbyState State { get; set; } |
|||
public long? AllPlayersReadyTime { get; set; } |
|||
|
|||
public LobbyInfo(LobbyInfo existing) |
|||
{ |
|||
RoomID = existing.RoomID; |
|||
RoomCode = existing.RoomCode; |
|||
RelayCode = existing.RelayCode; |
|||
LobbyName = existing.LobbyName; |
|||
Private = existing.Private; |
|||
MaxPlayerCount = existing.MaxPlayerCount; |
|||
State = existing.State; |
|||
AllPlayersReadyTime = existing.AllPlayersReadyTime; |
|||
} |
|||
|
|||
public LobbyInfo(string roomCode) |
|||
{ |
|||
RoomID = null; |
|||
RoomCode = roomCode; |
|||
RelayCode = null; |
|||
LobbyName = null; |
|||
Private = false; |
|||
MaxPlayerCount = -1; |
|||
State = LobbyState.Lobby; |
|||
AllPlayersReadyTime = null; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// The local lobby data that the game can observe
|
|||
/// </summary>
|
|||
[System.Serializable] |
|||
public class LobbyData : Observed<LobbyData> |
|||
{ |
|||
Dictionary<string, LobbyUser> m_LobbyUsers = new Dictionary<string, LobbyUser>(); |
|||
public Dictionary<string, LobbyUser> LobbyUsers => m_LobbyUsers; |
|||
|
|||
#region LocalLobbyData
|
|||
private LobbyInfo m_data; |
|||
public LobbyInfo Data |
|||
{ |
|||
get { return new LobbyInfo(m_data); } |
|||
} |
|||
|
|||
float m_CountDownTime; |
|||
|
|||
public float CountDownTime |
|||
{ |
|||
get { return m_CountDownTime; } |
|||
set |
|||
{ |
|||
m_CountDownTime = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
DateTime m_TargetEndTime; |
|||
|
|||
public DateTime TargetEndTime |
|||
{ |
|||
get => m_TargetEndTime; |
|||
set |
|||
{ |
|||
m_TargetEndTime = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
ServerAddress m_relayServer; |
|||
|
|||
public ServerAddress RelayServer |
|||
{ |
|||
get => m_relayServer; |
|||
set |
|||
{ |
|||
m_relayServer = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
public void AddPlayer(LobbyUser user) |
|||
{ |
|||
if (m_LobbyUsers.ContainsKey(user.ID)) |
|||
{ |
|||
Debug.LogError($"Cant add player {user.DisplayName}({user.ID}) to room: {RoomID} twice"); |
|||
return; |
|||
} |
|||
|
|||
DoAddPlayer(user); |
|||
OnChanged(this); |
|||
} |
|||
|
|||
private void DoAddPlayer(LobbyUser user) |
|||
{ |
|||
m_LobbyUsers.Add(user.ID, user); |
|||
user.onChanged += OnChangedUser; |
|||
} |
|||
|
|||
public void RemovePlayer(LobbyUser user) |
|||
{ |
|||
DoRemoveUser(user); |
|||
OnChanged(this); |
|||
} |
|||
|
|||
private void DoRemoveUser(LobbyUser user) |
|||
{ |
|||
if (!m_LobbyUsers.ContainsKey(user.ID)) |
|||
{ |
|||
Debug.LogWarning($"Player {user.DisplayName}({user.ID}) does not exist in room: {RoomID}"); |
|||
return; |
|||
} |
|||
|
|||
m_LobbyUsers.Remove(user.ID); |
|||
user.onChanged -= OnChangedUser; |
|||
} |
|||
|
|||
private void OnChangedUser(LobbyUser user) |
|||
{ |
|||
OnChanged(this); |
|||
} |
|||
|
|||
public string RoomID |
|||
{ |
|||
get => m_data.RoomID; |
|||
set |
|||
{ |
|||
m_data.RoomID = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public string RoomCode |
|||
{ |
|||
get => m_data.RoomCode; |
|||
set |
|||
{ |
|||
m_data.RoomCode = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public string RelayCode |
|||
{ |
|||
get => m_data.RelayCode; |
|||
set |
|||
{ |
|||
m_data.RelayCode = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public string LobbyName |
|||
{ |
|||
get => m_data.LobbyName; |
|||
set |
|||
{ |
|||
m_data.LobbyName = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public LobbyState State |
|||
{ |
|||
get => m_data.State; |
|||
set |
|||
{ |
|||
m_data.State = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public bool Private |
|||
{ |
|||
get => m_data.Private; |
|||
set |
|||
{ |
|||
m_data.Private = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public int PlayerCount => m_LobbyUsers.Count; |
|||
|
|||
public int MaxPlayerCount |
|||
{ |
|||
get => m_data.MaxPlayerCount; |
|||
set |
|||
{ |
|||
m_data.MaxPlayerCount = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public long? AllPlayersReadyTime => m_data.AllPlayersReadyTime; |
|||
|
|||
/// <summary>
|
|||
/// Checks if we have n players that have the Status.
|
|||
/// -1 Count means you need all Lobbyusers
|
|||
/// </summary>
|
|||
/// <returns>True if enough players are of the input status.</returns>
|
|||
public bool PlayersOfState(UserStatus status, int playersCount = -1) |
|||
{ |
|||
var statePlayers = m_LobbyUsers.Values.Count(user => user.UserStatus == status); |
|||
|
|||
if (playersCount < 0) |
|||
return statePlayers == m_LobbyUsers.Count; |
|||
return statePlayers == playersCount; |
|||
} |
|||
|
|||
public void CopyObserved(LobbyInfo info, Dictionary<string, LobbyUser> oldUsers) |
|||
{ |
|||
m_data = info; |
|||
if (oldUsers == null) |
|||
m_LobbyUsers = new Dictionary<string, LobbyUser>(); |
|||
else |
|||
{ |
|||
List<LobbyUser> toRemove = new List<LobbyUser>(); |
|||
foreach (var user in m_LobbyUsers) |
|||
{ |
|||
if (oldUsers.ContainsKey(user.Key)) |
|||
user.Value.CopyObserved(oldUsers[user.Key]); |
|||
else |
|||
toRemove.Add(user.Value); |
|||
} |
|||
|
|||
foreach (var remove in toRemove) |
|||
{ |
|||
DoRemoveUser(remove); |
|||
} |
|||
|
|||
foreach (var oldUser in oldUsers) |
|||
{ |
|||
if (!m_LobbyUsers.ContainsKey(oldUser.Key)) |
|||
DoAddPlayer(oldUser.Value); |
|||
} |
|||
} |
|||
|
|||
OnChanged(this); |
|||
} |
|||
|
|||
public override void CopyObserved(LobbyData oldObserved) |
|||
{ |
|||
CopyObserved(oldObserved.Data, oldObserved.m_LobbyUsers); |
|||
} |
|||
} |
|||
} |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample |
|||
{ |
|||
[Flags] |
|||
public enum LobbyState |
|||
{ |
|||
Lobby = 1, |
|||
CountDown = 2, |
|||
InGame = 4 |
|||
} |
|||
|
|||
public struct LobbyInfo |
|||
{ |
|||
public string LobbyID { get; set; } |
|||
public string LobbyCode { get; set; } |
|||
public string RelayCode { get; set; } |
|||
public string LobbyName { get; set; } |
|||
public bool Private { get; set; } |
|||
public int MaxPlayerCount { get; set; } |
|||
public LobbyState State { get; set; } |
|||
public long? AllPlayersReadyTime { get; set; } |
|||
|
|||
public LobbyInfo(LobbyInfo existing) |
|||
{ |
|||
LobbyID = existing.LobbyID; |
|||
LobbyCode = existing.LobbyCode; |
|||
RelayCode = existing.RelayCode; |
|||
LobbyName = existing.LobbyName; |
|||
Private = existing.Private; |
|||
MaxPlayerCount = existing.MaxPlayerCount; |
|||
State = existing.State; |
|||
AllPlayersReadyTime = existing.AllPlayersReadyTime; |
|||
} |
|||
|
|||
public LobbyInfo(string lobbyCode) |
|||
{ |
|||
LobbyID = null; |
|||
LobbyCode = lobbyCode; |
|||
RelayCode = null; |
|||
LobbyName = null; |
|||
Private = false; |
|||
MaxPlayerCount = -1; |
|||
State = LobbyState.Lobby; |
|||
AllPlayersReadyTime = null; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// A local wrapper around a lobby's remote data, with additional functionality for providing that data to UI elements and tracking local player objects.
|
|||
/// </summary>
|
|||
[System.Serializable] |
|||
public class LocalLobby : Observed<LocalLobby> |
|||
{ |
|||
Dictionary<string, LobbyUser> m_LobbyUsers = new Dictionary<string, LobbyUser>(); |
|||
public Dictionary<string, LobbyUser> LobbyUsers => m_LobbyUsers; |
|||
|
|||
#region LocalLobbyData
|
|||
private LobbyInfo m_data; |
|||
public LobbyInfo Data |
|||
{ |
|||
get { return new LobbyInfo(m_data); } |
|||
} |
|||
|
|||
float m_CountDownTime; |
|||
|
|||
public float CountDownTime |
|||
{ |
|||
get { return m_CountDownTime; } |
|||
set |
|||
{ |
|||
m_CountDownTime = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
DateTime m_TargetEndTime; |
|||
|
|||
public DateTime TargetEndTime |
|||
{ |
|||
get => m_TargetEndTime; |
|||
set |
|||
{ |
|||
m_TargetEndTime = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
ServerAddress m_relayServer; |
|||
|
|||
public ServerAddress RelayServer |
|||
{ |
|||
get => m_relayServer; |
|||
set |
|||
{ |
|||
m_relayServer = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
public void AddPlayer(LobbyUser user) |
|||
{ |
|||
if (m_LobbyUsers.ContainsKey(user.ID)) |
|||
{ |
|||
Debug.LogError($"Cant add player {user.DisplayName}({user.ID}) to lobby: {LobbyID} twice"); |
|||
return; |
|||
} |
|||
|
|||
DoAddPlayer(user); |
|||
OnChanged(this); |
|||
} |
|||
|
|||
private void DoAddPlayer(LobbyUser user) |
|||
{ |
|||
m_LobbyUsers.Add(user.ID, user); |
|||
user.onChanged += OnChangedUser; |
|||
} |
|||
|
|||
public void RemovePlayer(LobbyUser user) |
|||
{ |
|||
DoRemoveUser(user); |
|||
OnChanged(this); |
|||
} |
|||
|
|||
private void DoRemoveUser(LobbyUser user) |
|||
{ |
|||
if (!m_LobbyUsers.ContainsKey(user.ID)) |
|||
{ |
|||
Debug.LogWarning($"Player {user.DisplayName}({user.ID}) does not exist in lobby: {LobbyID}"); |
|||
return; |
|||
} |
|||
|
|||
m_LobbyUsers.Remove(user.ID); |
|||
user.onChanged -= OnChangedUser; |
|||
} |
|||
|
|||
private void OnChangedUser(LobbyUser user) |
|||
{ |
|||
OnChanged(this); |
|||
} |
|||
|
|||
public string LobbyID |
|||
{ |
|||
get => m_data.LobbyID; |
|||
set |
|||
{ |
|||
m_data.LobbyID = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public string LobbyCode |
|||
{ |
|||
get => m_data.LobbyCode; |
|||
set |
|||
{ |
|||
m_data.LobbyCode = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
|||
public string RelayCode |
|||
{ |
|||
get => m_data.RelayCode; |
|||
set |
|||
{ |
|||
m_data.RelayCode = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
|
<