Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Assets/Prefabs/State/CharSelectState.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ MonoBehaviour:
autoRun: 1
autoInjectGameObjects: []
m_NetcodeHooks: {fileID: 8494646029522094751}
m_NetworkCharSelection: {fileID: 3565665953789623673}
m_AnimationTriggerOnCharSelect: BeginRevive
m_AnimationTriggerOnCharChosen: BeginRevive
m_PlayerSeats:
Expand Down
47 changes: 23 additions & 24 deletions Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class ClientCharSelectState : GameStateBehaviour
NetcodeHooks m_NetcodeHooks;

public override GameState ActiveState { get { return GameState.CharSelect; } }
public NetworkCharSelection networkCharSelection { get; private set; }

[SerializeField]
NetworkCharSelection m_NetworkCharSelection;

[SerializeField]
[Tooltip("This is triggered when the player chooses a character")]
Expand Down Expand Up @@ -116,9 +118,6 @@ protected override void Awake()
base.Awake();
Instance = this;

// TODO inject or find another way to find CharSelectData
// TODO CharSelectData should directly be in ServerCharSelectState
networkCharSelection = FindObjectOfType<NetworkCharSelection>();
m_NetcodeHooks.OnNetworkSpawnHook += OnNetworkSpawn;
m_NetcodeHooks.OnNetworkDespawnHook += OnNetworkDespawn;

Expand Down Expand Up @@ -155,10 +154,10 @@ protected override void Start()

void OnNetworkDespawn()
{
if (networkCharSelection)
if (m_NetworkCharSelection)
{
networkCharSelection.IsLobbyClosed.OnValueChanged -= OnLobbyClosedChanged;
networkCharSelection.LobbyPlayers.OnListChanged -= OnLobbyPlayerStateChanged;
m_NetworkCharSelection.IsLobbyClosed.OnValueChanged -= OnLobbyClosedChanged;
m_NetworkCharSelection.LobbyPlayers.OnListChanged -= OnLobbyPlayerStateChanged;
}
}

Expand All @@ -170,8 +169,8 @@ void OnNetworkSpawn()
}
else
{
networkCharSelection.IsLobbyClosed.OnValueChanged += OnLobbyClosedChanged;
networkCharSelection.LobbyPlayers.OnListChanged += OnLobbyPlayerStateChanged;
m_NetworkCharSelection.IsLobbyClosed.OnValueChanged += OnLobbyClosedChanged;
m_NetworkCharSelection.LobbyPlayers.OnListChanged += OnLobbyPlayerStateChanged;
}
}

Expand All @@ -186,7 +185,7 @@ void OnAssignedPlayerNumber(int playerNum)

void UpdatePlayerCount()
{
int count = networkCharSelection.LobbyPlayers.Count;
int count = m_NetworkCharSelection.LobbyPlayers.Count;
var pstr = (count > 1) ? "players" : "player";
m_NumPlayersText.text = "<b>" + count + "</b> " + pstr + " connected";
}
Expand All @@ -201,9 +200,9 @@ void OnLobbyPlayerStateChanged(NetworkListEvent<NetworkCharSelection.LobbyPlayer

// now let's find our local player in the list and update the character/info box appropriately
int localPlayerIdx = -1;
for (int i = 0; i < networkCharSelection.LobbyPlayers.Count; ++i)
for (int i = 0; i < m_NetworkCharSelection.LobbyPlayers.Count; ++i)
{
if (networkCharSelection.LobbyPlayers[i].ClientId == NetworkManager.Singleton.LocalClientId)
if (m_NetworkCharSelection.LobbyPlayers[i].ClientId == NetworkManager.Singleton.LocalClientId)
{
localPlayerIdx = i;
break;
Expand All @@ -216,17 +215,17 @@ void OnLobbyPlayerStateChanged(NetworkListEvent<NetworkCharSelection.LobbyPlayer
// this can happen for various reasons, such as the lobby being full and us not getting a seat.
UpdateCharacterSelection(NetworkCharSelection.SeatState.Inactive);
}
else if (networkCharSelection.LobbyPlayers[localPlayerIdx].SeatState == NetworkCharSelection.SeatState.Inactive)
else if (m_NetworkCharSelection.LobbyPlayers[localPlayerIdx].SeatState == NetworkCharSelection.SeatState.Inactive)
{
// we haven't chosen a seat yet (or were kicked out of our seat by someone else)
UpdateCharacterSelection(NetworkCharSelection.SeatState.Inactive);
// make sure our player num is properly set in Lobby UI
OnAssignedPlayerNumber(networkCharSelection.LobbyPlayers[localPlayerIdx].PlayerNumber);
OnAssignedPlayerNumber(m_NetworkCharSelection.LobbyPlayers[localPlayerIdx].PlayerNumber);
}
else
{
// we have a seat! Note that if our seat is LockedIn, this function will also switch the lobby mode
UpdateCharacterSelection(networkCharSelection.LobbyPlayers[localPlayerIdx].SeatState, networkCharSelection.LobbyPlayers[localPlayerIdx].SeatIdx);
UpdateCharacterSelection(m_NetworkCharSelection.LobbyPlayers[localPlayerIdx].SeatState, m_NetworkCharSelection.LobbyPlayers[localPlayerIdx].SeatIdx);
}
}

Expand Down Expand Up @@ -258,7 +257,7 @@ void UpdateCharacterSelection(NetworkCharSelection.SeatState state, int seatIdx
// change character preview when selecting a new seat
if (isNewSeat)
{
var selectedCharacterGraphics = GetCharacterGraphics(networkCharSelection.AvatarConfiguration[seatIdx]);
var selectedCharacterGraphics = GetCharacterGraphics(m_NetworkCharSelection.AvatarConfiguration[seatIdx]);

if (m_CurrentCharacterGraphics)
{
Expand All @@ -269,15 +268,15 @@ void UpdateCharacterSelection(NetworkCharSelection.SeatState state, int seatIdx
m_CurrentCharacterGraphics = selectedCharacterGraphics;
m_CurrentCharacterGraphicsAnimator = m_CurrentCharacterGraphics.GetComponent<Animator>();

m_ClassInfoBox.ConfigureForClass(networkCharSelection.AvatarConfiguration[seatIdx].CharacterClass);
m_ClassInfoBox.ConfigureForClass(m_NetworkCharSelection.AvatarConfiguration[seatIdx].CharacterClass);
}
}
if (state == NetworkCharSelection.SeatState.LockedIn && !m_HasLocalPlayerLockedIn)
{
// the local player has locked in their seat choice! Rearrange the UI appropriately
// the character should act excited
m_CurrentCharacterGraphicsAnimator.SetTrigger(m_AnimationTriggerOnCharChosen);
ConfigureUIForLobbyMode(networkCharSelection.IsLobbyClosed.Value ? LobbyMode.LobbyEnding : LobbyMode.SeatChosen);
ConfigureUIForLobbyMode(m_NetworkCharSelection.IsLobbyClosed.Value ? LobbyMode.LobbyEnding : LobbyMode.SeatChosen);
m_HasLocalPlayerLockedIn = true;
}
else if (m_HasLocalPlayerLockedIn && state == NetworkCharSelection.SeatState.Active)
Expand Down Expand Up @@ -307,7 +306,7 @@ void UpdateSeats()
// But until a seat is locked in, we need to display each seat as being used by the latest player to choose it.
// So we go through all players and figure out who should visually be shown as sitting in that seat.
NetworkCharSelection.LobbyPlayerState[] curSeats = new NetworkCharSelection.LobbyPlayerState[m_PlayerSeats.Count];
foreach (NetworkCharSelection.LobbyPlayerState playerState in networkCharSelection.LobbyPlayers)
foreach (NetworkCharSelection.LobbyPlayerState playerState in m_NetworkCharSelection.LobbyPlayers)
{
if (playerState.SeatIdx == -1 || playerState.SeatState == NetworkCharSelection.SeatState.Inactive)
continue; // this player isn't seated at all!
Expand Down Expand Up @@ -344,7 +343,7 @@ void OnLobbyClosedChanged(bool wasLobbyClosed, bool isLobbyClosed)
else
{
ConfigureUIForLobbyMode(LobbyMode.SeatChosen);
m_ClassInfoBox.ConfigureForClass(networkCharSelection.AvatarConfiguration[m_LastSeatSelected].CharacterClass);
m_ClassInfoBox.ConfigureForClass(m_NetworkCharSelection.AvatarConfiguration[m_LastSeatSelected].CharacterClass);
}
}
}
Expand Down Expand Up @@ -415,9 +414,9 @@ void ConfigureUIForLobbyMode(LobbyMode mode)
/// <param name="seatIdx"></param>
public void OnPlayerClickedSeat(int seatIdx)
{
if (networkCharSelection.IsSpawned)
if (m_NetworkCharSelection.IsSpawned)
{
networkCharSelection.ChangeSeatServerRpc(NetworkManager.Singleton.LocalClientId, seatIdx, false);
m_NetworkCharSelection.ChangeSeatServerRpc(NetworkManager.Singleton.LocalClientId, seatIdx, false);
}
}

Expand All @@ -426,10 +425,10 @@ public void OnPlayerClickedSeat(int seatIdx)
/// </summary>
public void OnPlayerClickedReady()
{
if (networkCharSelection.IsSpawned)
if (m_NetworkCharSelection.IsSpawned)
{
// request to lock in or unlock if already locked in
networkCharSelection.ChangeSeatServerRpc(NetworkManager.Singleton.LocalClientId, m_LastSeatSelected, !m_HasLocalPlayerLockedIn);
m_NetworkCharSelection.ChangeSeatServerRpc(NetworkManager.Singleton.LocalClientId, m_LastSeatSelected, !m_HasLocalPlayerLockedIn);
}
}

Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).

## [Unreleased] - yyyy-mm-dd

### Added
*

### Changed
*

### Cleanup
* Removed unnecessary FindObjectOfType usage inside of ClientCharSelectState (#754)

### Fixed
*

## [2.0.0] - 2022-10-06

### Added
Expand Down