diff --git a/Assets/Prefabs/State/CharSelectState.prefab b/Assets/Prefabs/State/CharSelectState.prefab index 9e9c2bea6..fe3bad9ee 100644 --- a/Assets/Prefabs/State/CharSelectState.prefab +++ b/Assets/Prefabs/State/CharSelectState.prefab @@ -86,6 +86,7 @@ MonoBehaviour: autoRun: 1 autoInjectGameObjects: [] m_NetcodeHooks: {fileID: 8494646029522094751} + m_NetworkCharSelection: {fileID: 3565665953789623673} m_AnimationTriggerOnCharSelect: BeginRevive m_AnimationTriggerOnCharChosen: BeginRevive m_PlayerSeats: diff --git a/Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs b/Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs index 07e810ea4..8cf7a3465 100644 --- a/Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs +++ b/Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs @@ -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")] @@ -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(); m_NetcodeHooks.OnNetworkSpawnHook += OnNetworkSpawn; m_NetcodeHooks.OnNetworkDespawnHook += OnNetworkDespawn; @@ -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; } } @@ -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; } } @@ -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 = "" + count + " " + pstr + " connected"; } @@ -201,9 +200,9 @@ void OnLobbyPlayerStateChanged(NetworkListEvent(); - m_ClassInfoBox.ConfigureForClass(networkCharSelection.AvatarConfiguration[seatIdx].CharacterClass); + m_ClassInfoBox.ConfigureForClass(m_NetworkCharSelection.AvatarConfiguration[seatIdx].CharacterClass); } } if (state == NetworkCharSelection.SeatState.LockedIn && !m_HasLocalPlayerLockedIn) @@ -277,7 +276,7 @@ void UpdateCharacterSelection(NetworkCharSelection.SeatState state, int seatIdx // 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) @@ -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! @@ -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); } } } @@ -415,9 +414,9 @@ void ConfigureUIForLobbyMode(LobbyMode mode) /// 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); } } @@ -426,10 +425,10 @@ public void OnPlayerClickedSeat(int seatIdx) /// 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); } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 462bfc1f3..a314a1f67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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