UnityJacob
3 年前
当前提交
d7613e86
共有 76 个文件被更改,包括 383 次插入 和 636 次删除
-
4Assets/Prefabs/UI/JoinContent.prefab
-
7Assets/Prefabs/UI/LobbyButtonUI.prefab
-
22Assets/Prefabs/UI/LobbyGameCanvas.prefab
-
42Assets/Prefabs/UI/LobbyUserList.prefab
-
4Assets/Prefabs/UI/PlayerInteractionPanel.prefab
-
17Assets/Prefabs/UI/RelayCodeCanvas.prefab
-
232Assets/Scenes/mainScene.unity
-
2Assets/Scripts/Auth/Identity.cs
-
2Assets/Scripts/Auth/SubIdentity_Authentication.cs
-
68Assets/Scripts/Entities/GameStateManager.cs
-
2Assets/Scripts/Entities/LobbyServiceData.cs
-
14Assets/Scripts/Entities/LobbyUser.cs
-
2Assets/Scripts/Entities/LocalLobby.cs
-
2Assets/Scripts/Infrastructure/UpdateSlow.cs
-
4Assets/Scripts/Lobby/LobbyContentHeartbeat.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
-
3Assets/Scripts/UI/CountdownUI.cs
-
3Assets/Scripts/UI/CreateMenuUI.cs
-
3Assets/Scripts/UI/EmoteButtonUI.cs
-
5Assets/Scripts/UI/EndGameButtonUI.cs
-
3Assets/Scripts/UI/ExitButtonUI.cs
-
3Assets/Scripts/UI/GameStateVisibilityUI.cs
-
38Assets/Scripts/UI/JoinMenuUI.cs
-
5Assets/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
-
17README.md
-
5Assets/Scripts/Auth/NameGenerator.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
-
11Assets/Scripts/UI/RelayCodeUI.cs.meta
-
5Assets/Scripts/UI/SerializedValueEvents.cs
-
11Assets/Scripts/UI/SerializedValueEvents.cs.meta
-
12Assets/Scripts/UI/StartLobbyButton.cs
-
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
-
8Assets/Scripts/Utilities.meta
-
11Assets/TempDeleteAllRooms.cs.meta
-
33Assets/TempDeleteAllRooms.cs
-
0/Assets/Scripts/UI/JoinCreateLobbyUI.cs.meta
-
0/Assets/Scripts/UI/ShowWhenLobbyStateUI.cs.meta
-
0/Assets/Scripts/UI/InLobbyUserUI.cs.meta
-
0/Assets/Scripts/UI/InLobbyUserList.cs.meta
-
0/Assets/Scripts/UI/DisplayCodeUI.cs.meta
-
0/Assets/Scripts/UI/RelayAddressUI.cs.meta
-
0/Assets/Scripts/UI/LobbyNameUI.cs.meta
-
0/Assets/Scripts/UI/StartLobbyButtonUI.cs.meta
-
0/Assets/Scripts/UI/JoinCreateLobbyUI.cs
-
0/Assets/Scripts/UI/InLobbyUserUI.cs
-
0/Assets/Scripts/LobbyRelaySample.asmdef.meta
-
0/Assets/Scripts/LobbyRelaySample.asmdef
-
0/Assets/Scripts/Lobby/ReadyCheck.cs
-
0/Assets/Scripts/Lobby/ReadyCheck.cs.meta
-
0/Assets/Scripts/Auth/NameGenerator.cs
-
0/Assets/Scripts/Auth/NameGenerator.cs.meta
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Observer UI panel base class, for UI panels that need hiding, and hookup to observerBehaviours
|
|||
/// Observer UI panel base class. This allows UI elements to be shown or hidden based on an Observed element.
|
|||
/// <typeparam name="T"></typeparam>
|
|||
|
|||
|
|||
} |
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// The panel that holds the room joining and creation panels.
|
|||
/// </summary>
|
|||
public class JoinCreateRoomUI : ObserverPanel<LocalGameState> |
|||
{ |
|||
public override void ObservedUpdated(LocalGameState observed) |
|||
{ |
|||
if (observed.State == GameState.JoinMenu) |
|||
{ |
|||
Show(); |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.QueryLobbies, null); |
|||
} |
|||
else |
|||
{ |
|||
Hide(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// The panel that holds the lobby joining and creation panels.
|
|||
/// </summary>
|
|||
public class JoinCreateLobbyUI : ObserverPanel<LocalGameState> |
|||
{ |
|||
public override void ObservedUpdated(LocalGameState observed) |
|||
{ |
|||
if (observed.State == GameState.JoinMenu) |
|||
{ |
|||
Show(); |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.QueryLobbies, null); |
|||
} |
|||
else |
|||
{ |
|||
Hide(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using TMPro; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Watches a lobby or relay code for updates, displaying the current code to lobby members.
|
|||
/// </summary>
|
|||
public class DisplayCodeUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
public enum CodeType { Lobby = 0, Relay = 1 } |
|||
|
|||
[SerializeField] |
|||
TMP_InputField m_outputText; |
|||
[SerializeField] |
|||
CodeType m_codeType; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
string code = m_codeType == CodeType.Lobby ? observed.LobbyCode : observed.RelayCode; |
|||
|
|||
if (!string.IsNullOrEmpty(code)) |
|||
{ |
|||
m_outputText.text = code; |
|||
Show(); |
|||
} |
|||
else |
|||
{ |
|||
Hide(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Contains the InLobbyUserUI instances while showing the UI for a lobby.
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(LocalLobbyObserver))] |
|||
public class InLobbyUserList : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
List<InLobbyUserUI> m_UserUIObjects = new List<InLobbyUserUI>(); |
|||
List<string> m_CurrentUsers = new List<string>(); // Just for keeping track more easily of which users are already displayed.
|
|||
|
|||
/// <summary>
|
|||
/// When the observed data updates, we need to detect changes to the list of players.
|
|||
/// </summary>
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
for (int id = m_CurrentUsers.Count - 1; id >= 0; id--) // We might remove users if they aren't in the new data, so iterate backwards.
|
|||
{ |
|||
string userId = m_CurrentUsers[id]; |
|||
if (!observed.LobbyUsers.ContainsKey(userId)) |
|||
{ |
|||
foreach (var ui in m_UserUIObjects) |
|||
{ |
|||
if (ui.UserId == userId) |
|||
{ |
|||
ui.OnUserLeft(); |
|||
OnUserLeft(userId); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
foreach (var lobbyUserKvp in observed.LobbyUsers) // If there are new players, we need to hook them into the UI.
|
|||
{ |
|||
if (m_CurrentUsers.Contains(lobbyUserKvp.Key)) |
|||
continue; |
|||
m_CurrentUsers.Add(lobbyUserKvp.Key); |
|||
|
|||
foreach (var pcu in m_UserUIObjects) |
|||
{ |
|||
if (pcu.IsAssigned) |
|||
continue; |
|||
pcu.SetUser(lobbyUserKvp.Value); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void OnUserLeft(string userID) |
|||
{ |
|||
if (!m_CurrentUsers.Contains(userID)) |
|||
return; |
|||
m_CurrentUsers.Remove(userID); |
|||
} |
|||
} |
|||
} |
|
|||
using TMPro; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Displays the name of the lobby.
|
|||
/// </summary>
|
|||
public class LobbyNameUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
TMP_Text m_lobbyNameText; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
m_lobbyNameText.SetText(observed.LobbyName); |
|||
} |
|||
} |
|||
} |
|
|||
using TMPro; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Displays the IP when connected to Relay.
|
|||
/// </summary>
|
|||
public class RelayAddressUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
TMP_Text m_IPAddressText; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
m_IPAddressText.SetText(observed.RelayServer?.ToString()); |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// UI element that is displayed when the lobby is in a particular state (e.g. counting down, in-game).
|
|||
/// </summary>
|
|||
public class ShowWhenLobbyStateUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
private LobbyState m_ShowThisWhen; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
if (m_ShowThisWhen.HasFlag(observed.State)) |
|||
Show(); |
|||
else |
|||
Hide(); |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample |
|||
{ |
|||
/// <summary>
|
|||
/// Main menu start button.
|
|||
/// </summary>
|
|||
public class StartLobbyButtonUI : MonoBehaviour |
|||
{ |
|||
public void ToJoinMenu() |
|||
{ |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.ChangeGameState, GameState.JoinMenu); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9a70bc1b6f999ee43974bbbf991a0b6a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Events; |
|||
|
|||
[System.Serializable] |
|||
public class StringEvent : UnityEvent<string> { } |
|
|||
fileFormatVersion: 2 |
|||
guid: 19bfe59f0f446ac4ea431b38580a52cf |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample |
|||
{ |
|||
public class StartLobbyButton : MonoBehaviour |
|||
{ |
|||
public void ToJoinMenu() |
|||
{ |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.ChangeGameState, GameState.JoinMenu); |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
public class LobbyStateVisibilityUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
private LobbyState m_ShowThisWhen; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
if (m_ShowThisWhen.HasFlag(observed.State)) |
|||
Show(); |
|||
else |
|||
Hide(); |
|||
} |
|||
} |
|||
} |
|||
|
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Watches for changes in the Lobby's player List
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(LocalLobbyObserver))] |
|||
public class LobbyUsersUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
List<LobbyUserCardUI> m_PlayerCardSlots = new List<LobbyUserCardUI>(); |
|||
List<string> m_CurrentUsers = new List<string>(); // Just for keeping track more easily of which users are already displayed.
|
|||
|
|||
/// <summary>
|
|||
/// When the observed data updates, we need to detect changes to the list of players.
|
|||
/// </summary>
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
for (int id = m_CurrentUsers.Count - 1; id >= 0; id--) // We might remove users if they aren't in the new data, so iterate backwards.
|
|||
{ |
|||
string userId = m_CurrentUsers[id]; |
|||
if (!observed.LobbyUsers.ContainsKey(userId)) |
|||
{ |
|||
foreach (var card in m_PlayerCardSlots) |
|||
{ |
|||
if (card.UserId == userId) |
|||
{ |
|||
card.OnUserLeft(); |
|||
OnUserLeft(userId); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
foreach (var lobbyUserKvp in observed.LobbyUsers) // If there are new players, we need to hook them into the UI.
|
|||
{ |
|||
if (m_CurrentUsers.Contains(lobbyUserKvp.Key)) |
|||
continue; |
|||
m_CurrentUsers.Add(lobbyUserKvp.Key); |
|||
|
|||
foreach (var pcu in m_PlayerCardSlots) |
|||
{ |
|||
if (pcu.IsAssigned) |
|||
continue; |
|||
pcu.SetUser(lobbyUserKvp.Value); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void OnUserLeft(string userID) |
|||
{ |
|||
if (!m_CurrentUsers.Contains(userID)) |
|||
return; |
|||
m_CurrentUsers.Remove(userID); |
|||
} |
|||
} |
|||
} |
|
|||
using TMPro; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Read Only input field (for copy/paste reasons) Watches for the changes in the lobby's Relay Code
|
|||
/// </summary>
|
|||
public class RelayCodeUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
TMP_InputField relayCodeText; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
if (!string.IsNullOrEmpty(observed.RelayCode)) |
|||
{ |
|||
relayCodeText.text = observed.RelayCode; |
|||
Show(); |
|||
} |
|||
else |
|||
{ |
|||
Hide(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using TMPro; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Read Only input field (for copy/paste reasons) Watches for the changes in the lobby's Room Code
|
|||
/// </summary>
|
|||
public class RoomCodeUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
public TMP_InputField roomCodeText; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
if (!string.IsNullOrEmpty(observed.LobbyCode)) |
|||
{ |
|||
roomCodeText.text = observed.LobbyCode; |
|||
Show(); |
|||
} |
|||
else |
|||
{ |
|||
Hide(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|
|||
using TMPro; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
public class ServerAddressUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
TMP_Text m_IPAddressText; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
m_IPAddressText.SetText(observed.RelayServer?.ToString()); |
|||
} |
|||
} |
|||
} |
|
|||
using TMPro; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
public class ServerNameUI : ObserverPanel<LocalLobby> |
|||
{ |
|||
[SerializeField] |
|||
TMP_Text m_ServerNameText; |
|||
|
|||
public override void ObservedUpdated(LocalLobby observed) |
|||
{ |
|||
m_ServerNameText.SetText(observed.LobbyName); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4e59a0c0ec4227344bcc4a4f79c8ac31 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0e7b1d59375bdf94795f339fd9395761 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
/// <summary>
|
|||
/// Temporary script to allow a user to delete all the rooms they've previously made, so we don't have orphaned empty rooms.
|
|||
/// </summary>
|
|||
public class TempDeleteAllRooms : MonoBehaviour |
|||
{ |
|||
private Queue<Unity.Services.Rooms.Models.Room> m_pendingRooms; |
|||
|
|||
public void OnButton() |
|||
{ |
|||
LobbyRelaySample.Lobby.LobbyAPIInterface.QueryAllLobbiesAsync((qr) => { DoDeletes(qr); }); |
|||
} |
|||
|
|||
private void DoDeletes(Unity.Services.Rooms.Response<Unity.Services.Rooms.Models.QueryResponse> response) |
|||
{ |
|||
if (response != null && response.Status >= 200 && response.Status < 300) |
|||
{ |
|||
StartCoroutine(DeleteCoroutine(response.Result.Results)); |
|||
} |
|||
} |
|||
|
|||
private IEnumerator DeleteCoroutine(List<Unity.Services.Rooms.Models.Room> rooms) |
|||
{ |
|||
foreach (var room in rooms) |
|||
{ |
|||
LobbyRelaySample.Lobby.LobbyAPIInterface.DeleteLobbyAsync(room.Id, null); // The onComplete callback isn't called in some error cases, e.g. a 403 when we don't have permissions, so don't block on it.
|
|||
yield return new WaitForSeconds(1); // We need to wait a little to avoid 429's, but we might not run an onComplete depending on how the delete call fails.
|
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue