浏览代码

Apparently the manual list of connected players wasn't updating, so I've switched to just use the NetworkManager's list instead.

/main/staging/ngo_minigame_structure
nathaniel.buck@unity3d.com 3 年前
当前提交
834f705a
共有 2 个文件被更改,包括 15 次插入18 次删除
  1. 17
      Assets/Scripts/Game/InGame/InGameRunner.cs
  2. 16
      Assets/Scripts/Game/InGame/SetupInGame.cs

17
Assets/Scripts/Game/InGame/InGameRunner.cs


private Queue<Vector2> m_pendingSymbolPositions = new Queue<Vector2>();
private float m_symbolSpawnTimer = 0.5f; // Initial time buffer to ensure connectivity before loading objects.
[SerializeField] private NetworkObject m_playerCursorPrefab;
[SerializeField] private NetworkObject m_symbolContainerPrefab;
[SerializeField] private NetworkObject m_playerCursorPrefab = default;
[SerializeField] private NetworkObject m_symbolContainerPrefab = default;
[SerializeField] private NetworkObject m_symbolObjectPrefab;
[SerializeField] private SequenceSelector m_sequenceSelector;
[SerializeField] private NetworkObject m_symbolObjectPrefab = default;
[SerializeField] private SequenceSelector m_sequenceSelector = default;
private NetworkList<ulong> m_connectedPlayerIds;
private ulong m_localId; // This is not necessarily the same as the OwnerClientId, since all clients will see all spawned objects regardless of ownership.
public void Initialize(Action onConnectionVerified, int expectedPlayerCount)

private void FinishInitialize()
{
if (m_connectedPlayerIds != null)
m_connectedPlayerIds.Clear();
else
m_connectedPlayerIds = new NetworkList<ulong>();
m_symbolContainerInstance = NetworkObject.Instantiate(m_symbolContainerPrefab).transform;
ResetPendingSymbolPositions();
}

playerCursor.SpawnWithOwnership(clientId);
playerCursor.name += clientId;
if (!m_connectedPlayerIds.Contains(clientId))
m_connectedPlayerIds.Add(clientId);
bool areAllPlayersConnected = m_connectedPlayerIds.Count >= m_expectedPlayerCount; // The game will begin at this point, or else there's a timeout for booting any unconnected players.
bool areAllPlayersConnected = NetworkManager.ConnectedClients.Count >= m_expectedPlayerCount; // The game will begin at this point, or else there's a timeout for booting any unconnected players.
VerifyConnectionConfirm_ClientRpc(clientId, areAllPlayersConnected);
}
[ClientRpc]

16
Assets/Scripts/Game/InGame/SetupInGame.cs


private bool m_isHost;
private bool m_doesNeedCleanup = false;
private bool m_hasConnectedViaNGO = false;
// TEMP? Relay stuff
private ServerAddress m_serverAddress;

* --- Need to make RelayUtpClient not an MB so I can freely disable the menus? It is on the GameManager, as it happens, but...
* x Spawn the object with the NetworkManager and allow that to connect.
* - Wait for all players to connect, or boot a player after a few seconds (via Relay) if they did not connect.
* - While waiting, server selects the target sequence, spawns the symbol container, and starts pooling/spawning the symbol objects.
* x While waiting, server selects the target sequence, spawns the symbol container, and starts pooling/spawning the symbol objects.
* - Once all players are in, show the target sequence and instructions, and then the server starts moving the symbol container and listening to click events.
* - After the symbols are all passed (I guess tracking the symbol container position or a timeout), finish the game (set the winner flag).
* x Clients clean up and return to the lobby screen. Host sets the lobby back to the regular state.

private void OnConnectionVerified()
{
// TODO: Anything here?
m_hasConnectedViaNGO = true;
}
public void SetRelayAddress(LocalLobby changed)

else if (type == MessageType.GameBeginning)
{
// If this player hasn't successfully connected via NGO, get booted.
Locator.Get.Messenger.OnReceiveMessage(MessageType.DisplayErrorPopup, "Failed to join the game.");
// TODO: Need to handle both failing to connect and connecting but failing to initialize.
// I.e. cleaning up networked objects *might* be necessary.
if (!m_hasConnectedViaNGO)
{
// If this player hasn't successfully connected via NGO, get booted.
Locator.Get.Messenger.OnReceiveMessage(MessageType.DisplayErrorPopup, "Failed to join the game.");
// TODO: Need to handle both failing to connect and connecting but failing to initialize.
// I.e. cleaning up networked objects *might* be necessary.
}
}
else if (type == MessageType.ChangeGameState)

正在加载...
取消
保存