浏览代码

Renamed AuthenticationManager to Auth to avoid conflct with a System API

Reframed the LobbyManager to maintain the life cycle of the remote Lobby.
-Is now responsible for maintaining the reference to the latest cache of the remote Lobby, 
-Will automatically set up the heartbeat for host,
-Also Works to prevent RateLimit Errors by creating cooldowns for each Lobby API Call
-Adjusted Roundtrip tests accordingly.

Moved Data synchronizastion to LobbySynchronizer
-Checks for local and remote changes and pushes/pulls player and lobby data accordingly.
/main/staging/2021_Upgrade/Async_Refactor
当前提交
de17cb80
共有 18 个文件被更改,包括 158 次插入309 次删除
  1. 133
      Assets/Prefabs/GameManager.prefab
  2. 7
      Assets/Prefabs/UI/LobbyCanvas.prefab
  3. 116
      Assets/Scenes/mainScene.unity
  4. 62
      Assets/Scripts/GameLobby/Game/GameManager.cs
  5. 3
      Assets/Scripts/GameLobby/Game/LocalLobbyList.cs
  6. 14
      Assets/Scripts/GameLobby/Game/LocalPlayer.cs
  7. 12
      Assets/Scripts/GameLobby/Infrastructure/Actionvalue.cs
  8. 13
      Assets/Scripts/GameLobby/Lobby/LobbyConverters.cs
  9. 21
      Assets/Scripts/GameLobby/Lobby/LobbyManager.cs
  10. 6
      Assets/Scripts/GameLobby/UI/GameStateVisibilityUI.cs
  11. 3
      Assets/Scripts/GameLobby/UI/InLobbyUserList.cs
  12. 3
      Assets/Scripts/GameLobby/UI/InLobbyUserUI.cs
  13. 4
      Assets/Scripts/GameLobby/UI/LobbyNameUI.cs
  14. 8
      Assets/Scripts/GameLobby/UI/UserNameUI.cs
  15. 40
      Assets/Scripts/GameLobby/UI/UserStateVisibilityUI.cs
  16. 2
      Packages/manifest.json
  17. 16
      Packages/packages-lock.json
  18. 4
      ProjectSettings/ProjectVersion.txt

133
Assets/Prefabs/GameManager.prefab


m_Component:
- component: {fileID: 802462301182945455}
- component: {fileID: 6265861362966661484}
- component: {fileID: 5235782363599194820}
- component: {fileID: 2812013971948110896}
m_Layer: 0
m_Name: SetupInGame
m_TagString: Untagged

m_EditorClassIdentifier:
m_IngameRunnerPrefab: {fileID: 238192747445020667, guid: 73173c97c128d614aa2a1167a2eaea68, type: 3}
m_disableWhileInGame: []
--- !u!114 &5235782363599194820
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5395715167687395500}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70dfc2fde0a9ef04eaff29a138f0bf45, type: 3}
m_Name:
m_EditorClassIdentifier:
OnObservedUpdated:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 6265861362966661484}
m_TargetAssemblyTypeName: LobbyRelaySample.inGame.SetupInGame, LobbyRelaySample
m_MethodName: OnLobbyChange
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &2812013971948110896
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5395715167687395500}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a03b37d5b8df06948b36dfbc430a1ea5, type: 3}
m_Name:
m_EditorClassIdentifier:
OnObservedUpdated:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 6265861362966661484}
m_TargetAssemblyTypeName: LobbyRelaySample.inGame.SetupInGame, LobbyRelaySample
m_MethodName: OnLocalUserChange
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!1 &6398156408753789057
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7186897169282866166}
- component: {fileID: 472628663792594525}
- component: {fileID: 8721980719610883967}
- component: {fileID: 2066355358714747406}
m_Layer: 0
m_Name: Countdown
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7186897169282866166
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6398156408753789057}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 693.65497, y: 426.1525, z: 1.3733984}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 7716713811812636911}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!225 &472628663792594525
CanvasGroup:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6398156408753789057}
m_Enabled: 1
m_Alpha: 1
m_Interactable: 1
m_BlocksRaycasts: 1
m_IgnoreParentGroups: 0
--- !u!114 &8721980719610883967
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6398156408753789057}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5b3b588e7ae40ec4ca35fdb9404513ab, type: 3}
m_Name:
m_EditorClassIdentifier:
m_onVisibilityChange:
m_PersistentCalls:
m_Calls: []
m_CountDownText: {fileID: 0}
--- !u!114 &2066355358714747406
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6398156408753789057}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d125c6cac111c6442ac5b07a1f313fa4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &7716713811812636896
GameObject:
m_ObjectHideFlags: 0

m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 802462301182945455}
- {fileID: 7186897169282866166}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_LocalLobbyObservers: []
m_LocalUserObservers: []
m_setupInGame: {fileID: 6265861362966661484}
m_countdown: {fileID: 2066355358714747406}
m_countdown: {fileID: 0}
m_vivoxUserHandlers: []
--- !u!114 &5193415626965589893
MonoBehaviour:

7
Assets/Prefabs/UI/LobbyCanvas.prefab


propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 6887166789349504240, guid: 2ff073ec9c74c8942bd90a541dc41bfc, type: 3}
- {fileID: 3235578093204888586, guid: 2ff073ec9c74c8942bd90a541dc41bfc, type: 3}
- {fileID: 2586128159150077185, guid: 2ff073ec9c74c8942bd90a541dc41bfc, type: 3}
- {fileID: 2853056286508716223, guid: 2ff073ec9c74c8942bd90a541dc41bfc, type: 3}
- {fileID: 8850815072349184999, guid: 2ff073ec9c74c8942bd90a541dc41bfc, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 2ff073ec9c74c8942bd90a541dc41bfc, type: 3}
--- !u!224 &3566036481622844614 stripped
RectTransform:

116
Assets/Scenes/mainScene.unity


m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &151543605 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 2812013971948110896, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
m_PrefabInstance: {fileID: 7716713812904700119}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a03b37d5b8df06948b36dfbc430a1ea5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &203192673
GameObject:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SendPointerHoverToParent: 1
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit

m_CorrespondingSourceObject: {fileID: 3513144941912357516, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
m_PrefabInstance: {fileID: 8628454959146822954}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1217229506 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 6326316181187829680, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
m_PrefabInstance: {fileID: 8628454959146822954}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a03b37d5b8df06948b36dfbc430a1ea5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1439850645 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7716713811812636910, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}

objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 35249394896e31643ba0641c2a6f8e8d, type: 3}
--- !u!114 &1511612118 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 8895314912834654425, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
m_PrefabInstance: {fileID: 8628454959146822954}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70dfc2fde0a9ef04eaff29a138f0bf45, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1583737884 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 6399412716226000571, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
m_PrefabInstance: {fileID: 8628454959146822954}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a03b37d5b8df06948b36dfbc430a1ea5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1793980663 stripped
--- !u!114 &1818474178 stripped
m_CorrespondingSourceObject: {fileID: 6680128790398423813, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
m_CorrespondingSourceObject: {fileID: 7029468144569480209, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
m_Script: {fileID: 11500000, guid: a03b37d5b8df06948b36dfbc430a1ea5, type: 3}
m_Script: {fileID: 11500000, guid: d125c6cac111c6442ac5b07a1f313fa4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1853015249

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1853015249}
m_CullTransparentMesh: 1
--- !u!114 &1969944515 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 2646044666659190602, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
m_PrefabInstance: {fileID: 8628454959146822954}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a03b37d5b8df06948b36dfbc430a1ea5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &2003557942 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1683469940080917438, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 78d292f3bd9f1614cb744dcb4fe3ac12, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &2637199315837045699 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 142122066828140637, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
m_PrefabInstance: {fileID: 8628454959146822954}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a03b37d5b8df06948b36dfbc430a1ea5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &2637199315837045700 stripped

value: 0
objectReference: {fileID: 0}
- target: {fileID: 7716713811812636910, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
propertyPath: m_countdown
value:
objectReference: {fileID: 1818474178}
- target: {fileID: 7716713811812636910, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
propertyPath: m_vivoxUserHandlers.Array.size
value: 4
objectReference: {fileID: 0}

- target: {fileID: 7716713811812636910, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
propertyPath: m_LocalUserObservers.Array.data[0]
value:
objectReference: {fileID: 1217229506}
objectReference: {fileID: 0}
objectReference: {fileID: 1969944515}
objectReference: {fileID: 0}
objectReference: {fileID: 1583737884}
objectReference: {fileID: 0}
objectReference: {fileID: 1793980663}
objectReference: {fileID: 0}
objectReference: {fileID: 2637199315837045699}
objectReference: {fileID: 0}
objectReference: {fileID: 151543605}
objectReference: {fileID: 0}
- target: {fileID: 7716713811812636910, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
propertyPath: m_LocalUserObservers.Array.data[6]
value:

- target: {fileID: 7716713811812636910, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
propertyPath: m_LocalLobbyObservers.Array.data[4]
value:
objectReference: {fileID: 1511612118}
objectReference: {fileID: 0}
objectReference: {fileID: 7716713812904700120}
objectReference: {fileID: 0}
objectReference: {fileID: 7716713812904700120}
objectReference: {fileID: 0}
objectReference: {fileID: 7716713812904700120}
objectReference: {fileID: 0}
objectReference: {fileID: 1511612118}
objectReference: {fileID: 0}
objectReference: {fileID: 1511612118}
objectReference: {fileID: 0}
- target: {fileID: 7716713811812636910, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
propertyPath: m_LobbyServerObservers.Array.data[0]
value:

objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
--- !u!114 &7716713812904700120 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5235782363599194820, guid: f80fc24bab3dcda459a2669321e2e5a4, type: 3}
m_PrefabInstance: {fileID: 7716713812904700119}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70dfc2fde0a9ef04eaff29a138f0bf45, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &8628454959146822954
PrefabInstance:
m_ObjectHideFlags: 0

objectReference: {fileID: 0}
- target: {fileID: 1282422528845055840, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
propertyPath: m_AnchoredPosition.x
value: -0.000004887581
value: 0.0000015571713
value: -0.0000111372065
value: 0.0000036023557
objectReference: {fileID: 0}
- target: {fileID: 1386321973193631240, guid: 9aae991127b410c45a001ecd7f75311d, type: 3}
propertyPath: m_AnchorMax.x

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


/// </summary>
public class GameManager : MonoBehaviour, IReceiveMessages
{
#region UI elements that observe the local state. These should be assigned the observers in the scene during Start.
/// <summary>
/// The Observer/Observed Pattern is great for keeping the UI in Sync with the actual Values.
/// Each list below represents a single Observed class that gets updated by other parts of the code, and will
/// trigger the list of Observers that are looking for changes in that class.
///
/// The list is serialized, so you can navigate to the Observers via the Inspector to see who's watching.
/// </summary>
[SerializeField]
List<LocalLobbyObserver> m_LocalLobbyObservers = new List<LocalLobbyObserver>();
[SerializeField]
List<LobbyUserObserver> m_LocalUserObservers = new List<LobbyUserObserver>();
#endregion
public LocalPlayer LocalUser => m_LocalUser;
public Action<GameState> onGameStateChanged;
public LocalLobbyList LobbyList { get; private set; } = new LocalLobbyList();

if (lobby != null)
{
LobbyConverters.RemoteToLocal(lobby, m_LocalLobby);
try
{
LobbyConverters.RemoteToLocal(lobby, m_LocalLobby);
}
catch(Exception exception)
{
Debug.LogError(exception);
}
Debug.Log("Found Lobby");
Debug.Log("Didnt find Lobby");
SetGameState(GameState.JoinMenu);
}
}

Application.wantsToQuit += OnWantToQuit;
LobbyManager = new LobbyManager();
m_LobbySynchronizer = new LobbySynchronizer(LobbyManager);
InitLocalInstances();
m_LocalUser = new LocalPlayer("", false, "LocalPlayer");
m_LocalLobby = new LocalLobby { LocalLobbyState = { Value = LobbyState.Lobby } };
InitLocalPlayerId();
AuthenticatePlayer();
BeginObservers();
}
async Task InitializeServices()

await Auth.Authenticate(serviceProfileName);
}
void InitLocalInstances()
{
m_LocalLobby = new LocalLobby { LocalLobbyState = { Value = LobbyState.Lobby } };
}
void InitLocalPlayerId()
void AuthenticatePlayer()
m_LocalUser = new LocalPlayer(localId, false, randomName);
m_LocalUser.ID.Value = localId;
m_LocalUser.DisplayName.Value = randomName;
void BeginObservers()
public async Task<LocalPlayer> LocalUserInitialized()
foreach (var lobbyObs in m_LocalLobbyObservers)
lobbyObs.BeginObserving(m_LocalLobby);
foreach (var userObs in m_LocalUserObservers)
userObs.BeginObserving(m_LocalUser);
while (m_LocalUser == null)
await Task.Delay(100);
return m_LocalUser;
}
#endregion

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

void CreateLobby()
{
Debug.Log("Creating Lobby");
m_LocalUser.IsHost.Value = true;
JoinLobby();
}

Debug.Log("Joining Lobby");
m_LobbySynchronizer.StartSynch(m_LocalLobby, m_LocalUser);
SetUserLobbyState();
StartVivoxJoin();

void SetUserLobbyState()
{
Debug.Log($"Setting Lobby user state {GameState.Lobby}");
SetGameState(GameState.Lobby);
OnReceiveMessage(MessageType.LobbyUserStatus, UserStatus.Lobby);
}

#endregion
}
}
}

3
Assets/Scripts/GameLobby/Game/LocalLobbyList.cs


using System;
using System.Collections.Generic;
using UnityEngine.Serialization;
namespace LobbyRelaySample
{

}
}
}
}
}

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


using System;
using Unity.Services.Lobbies.Models;
using UnityEngine;
namespace LobbyRelaySample
{

[Serializable]
public class LocalPlayer : Observed<LocalPlayer>
{
public CallbackValue<bool> IsHost = new CallbackValue<bool>();
public CallbackValue<string> DisplayName = new CallbackValue<string>();
public CallbackValue<EmoteType> Emote = new CallbackValue<EmoteType>();
public CallbackValue<UserStatus> UserStatus = new CallbackValue<UserStatus>();
public CallbackValue<string> ID = new CallbackValue<string>();
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<string> ID = new CallbackValue<string>("");
public LocalPlayer(string id, bool isHost, string displayName,
EmoteType emote = default, UserStatus status = default)

OnChanged(this);
}
}
}
}

12
Assets/Scripts/GameLobby/Infrastructure/Actionvalue.cs


{
public Action<T> onChanged;
public CallbackValue()
{
}
public CallbackValue(T cachedValue)
{
m_CachedValue = cachedValue;
}
public T Value
{
get => m_CachedValue;

T m_CachedValue = default;
}
}
}

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


using System.Collections.Generic;
using Unity.Services.Lobbies.Models;
using UnityEngine;
namespace LobbyRelaySample.lobby
{

/// </summary>
public static void RemoteToLocal(Lobby remoteLobby, LocalLobby localLobby, bool allowSetLobbyChanged = true)
{
if (remoteLobby == null)
{
Debug.LogError("Remote lobby is null, cannot convert.");
return;
}
if (localLobby == null)
{
Debug.LogError("Local Lobby is null, cannot convert");
return;
}
localLobby.CanSetChanged = allowSetLobbyChanged;
localLobby.LobbyID.Value = remoteLobby.Id;
localLobby.LobbyName.Value = remoteLobby.Name;

return data;
}
}
}
}

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


public Lobby CurrentLobby => m_CurrentLobby;
Lobby m_CurrentLobby;
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;
public enum RequestType
{
Query = 0,

}
await m_CreateCooldown.WaitUntilCooldown();
Debug.Log("Lobby - Creating");
try

Player = new Player(id: uasId, data: CreateInitialPlayerData(localUser))
};
m_CurrentLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, createOptions);
#pragma warning disable 4014
HeartBeatLoop();
#pragma warning restore 4014
StartHeartBeat();
return m_CurrentLobby;
}
catch (Exception ex)

public void Dispose()
{
m_CurrentLobby = null;
m_HeartBeatTask.Dispose();
}
#region HeartBeat

await LobbyService.Instance.SendHeartbeatPingAsync(m_CurrentLobby.Id);
}
void StartHeartBeat()
{
#pragma warning disable 4014
m_HeartBeatTask = HeartBeatLoop();
#pragma warning restore 4014
}
async Task HeartBeatLoop()
{
while (m_CurrentLobby != null)

}
}
}
}
}

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


if (!ShowThisWhen.HasFlag(state))
Hide();
else
{
}
Debug.Log($"GameStateChanged for {gameObject.name} : {state}");
}
public override void Start()

Manager.onGameStateChanged -= GameStateChanged;
}
}
}
}

3
Assets/Scripts/GameLobby/UI/InLobbyUserList.cs


public override void Start()
{
base.Start();
GameManager.Instance.LocalLobby.onUserListChanged += OnUsersChanged;
}

m_CurrentUsers.Remove(userID);
}
}
}
}

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


public void SetUser(LocalPlayer myLocalPlayer)
{
Show();
m_localPlayer = myLocalPlayer;
SubscribeToPlayerUpdates();
UserId = myLocalPlayer.ID.Value;

}
}
}
}
}

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


[SerializeField]
TMP_Text m_lobbyNameText;
public void Start()
public override void Start()
}
}

8
Assets/Scripts/GameLobby/UI/UserNameUI.cs


[SerializeField]
TMP_Text m_TextField;
public override void Start()
public override async void Start()
GameManager.Instance.LocalUser.DisplayName.onChanged += SetText;
var localUser = await GameManager.Instance.LocalUserInitialized();
localUser.DisplayName.onChanged += SetText;
}
void SetText(string text)

}
}
}

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


/// <summary>
/// Shows the UI when the LocalPlayer matches some conditions, including having the target permissions.
/// </summary>
[RequireComponent(typeof(LobbyUserObserver))]
public class UserStateVisibilityUI : ObserverPanel<LocalPlayer>
public class UserStateVisibilityUI : UIPanelBase
bool m_HasStatusFlags = false;
bool m_HasPermissions;
public override void ObservedUpdated(LocalPlayer observed)
public override async void Start()
var hasStatusFlags = ShowThisWhen.HasFlag(observed.UserStatus.Value);
base.Start();
var localUser = await Manager.LocalUserInitialized();
localUser.IsHost.onChanged += OnUserHostChanged;
var hasPermissions = false;
localUser.UserStatus.onChanged += OnUserStatusChanged;
}
if (Permissions.HasFlag(UserPermission.Host) && observed.IsHost.Value)
void OnUserStatusChanged(UserStatus observedStatus)
{
m_HasStatusFlags = ShowThisWhen.HasFlag(observedStatus);
CheckVisibility();
}
void OnUserHostChanged(bool isHost)
{
m_HasPermissions = false;
if (Permissions.HasFlag(UserPermission.Host) && isHost)
hasPermissions = true;
m_HasPermissions = true;
else if (Permissions.HasFlag(UserPermission.Client) && !observed.IsHost.Value)
else if (Permissions.HasFlag(UserPermission.Client) && !isHost)
hasPermissions = true;
m_HasPermissions = true;
if (hasStatusFlags && hasPermissions)
CheckVisibility();
}
void CheckVisibility()
{
if (m_HasStatusFlags && m_HasPermissions)
}
}

2
Packages/manifest.json


"com.unity.ide.vscode": "1.2.5",
"com.unity.netcode.gameobjects": "1.0.2",
"com.unity.nuget.newtonsoft-json": "3.0.2",
"com.unity.render-pipelines.universal": "12.1.7",
"com.unity.render-pipelines.universal": "12.1.6",
"com.unity.services.authentication": "2.2.0",
"com.unity.services.core": "1.4.2",
"com.unity.services.lobby": "1.0.3",

16
Packages/packages-lock.json


"dependencies": {}
},
"com.unity.burst": {
"version": "1.7.3",
"version": "1.6.6",
"depth": 1,
"source": "registry",
"dependencies": {

"url": "https://packages.unity.com"
},
"com.unity.render-pipelines.core": {
"version": "12.1.7",
"version": "12.1.6",
"depth": 1,
"source": "builtin",
"dependencies": {

}
},
"com.unity.render-pipelines.universal": {
"version": "12.1.7",
"version": "12.1.6",
"com.unity.burst": "1.7.3",
"com.unity.render-pipelines.core": "12.1.7",
"com.unity.shadergraph": "12.1.7"
"com.unity.burst": "1.5.0",
"com.unity.render-pipelines.core": "12.1.6",
"com.unity.shadergraph": "12.1.6"
}
},
"com.unity.searcher": {

"url": "https://packages.unity.com"
},
"com.unity.shadergraph": {
"version": "12.1.7",
"version": "12.1.6",
"com.unity.render-pipelines.core": "12.1.7",
"com.unity.render-pipelines.core": "12.1.6",
"com.unity.searcher": "4.9.1"
}
},

4
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2021.3.9f1
m_EditorVersionWithRevision: 2021.3.9f1 (ad3870b89536)
m_EditorVersion: 2021.2.19f1
m_EditorVersionWithRevision: 2021.2.19f1 (602ecdbb2fb0)
正在加载...
取消
保存