@@ -26,7 +26,9 @@ public class ClientCharSelectState : GameStateBehaviour
26
26
NetcodeHooks m_NetcodeHooks ;
27
27
28
28
public override GameState ActiveState { get { return GameState . CharSelect ; } }
29
- public NetworkCharSelection networkCharSelection { get ; private set ; }
29
+
30
+ [ SerializeField ]
31
+ NetworkCharSelection m_NetworkCharSelection ;
30
32
31
33
[ SerializeField ]
32
34
[ Tooltip ( "This is triggered when the player chooses a character" ) ]
@@ -116,9 +118,6 @@ protected override void Awake()
116
118
base . Awake ( ) ;
117
119
Instance = this ;
118
120
119
- // TODO inject or find another way to find CharSelectData
120
- // TODO CharSelectData should directly be in ServerCharSelectState
121
- networkCharSelection = FindObjectOfType < NetworkCharSelection > ( ) ;
122
121
m_NetcodeHooks . OnNetworkSpawnHook += OnNetworkSpawn ;
123
122
m_NetcodeHooks . OnNetworkDespawnHook += OnNetworkDespawn ;
124
123
@@ -155,10 +154,10 @@ protected override void Start()
155
154
156
155
void OnNetworkDespawn ( )
157
156
{
158
- if ( networkCharSelection )
157
+ if ( m_NetworkCharSelection )
159
158
{
160
- networkCharSelection . IsLobbyClosed . OnValueChanged -= OnLobbyClosedChanged ;
161
- networkCharSelection . LobbyPlayers . OnListChanged -= OnLobbyPlayerStateChanged ;
159
+ m_NetworkCharSelection . IsLobbyClosed . OnValueChanged -= OnLobbyClosedChanged ;
160
+ m_NetworkCharSelection . LobbyPlayers . OnListChanged -= OnLobbyPlayerStateChanged ;
162
161
}
163
162
}
164
163
@@ -170,8 +169,8 @@ void OnNetworkSpawn()
170
169
}
171
170
else
172
171
{
173
- networkCharSelection . IsLobbyClosed . OnValueChanged += OnLobbyClosedChanged ;
174
- networkCharSelection . LobbyPlayers . OnListChanged += OnLobbyPlayerStateChanged ;
172
+ m_NetworkCharSelection . IsLobbyClosed . OnValueChanged += OnLobbyClosedChanged ;
173
+ m_NetworkCharSelection . LobbyPlayers . OnListChanged += OnLobbyPlayerStateChanged ;
175
174
}
176
175
}
177
176
@@ -186,7 +185,7 @@ void OnAssignedPlayerNumber(int playerNum)
186
185
187
186
void UpdatePlayerCount ( )
188
187
{
189
- int count = networkCharSelection . LobbyPlayers . Count ;
188
+ int count = m_NetworkCharSelection . LobbyPlayers . Count ;
190
189
var pstr = ( count > 1 ) ? "players" : "player" ;
191
190
m_NumPlayersText . text = "<b>" + count + "</b> " + pstr + " connected" ;
192
191
}
@@ -201,9 +200,9 @@ void OnLobbyPlayerStateChanged(NetworkListEvent<NetworkCharSelection.LobbyPlayer
201
200
202
201
// now let's find our local player in the list and update the character/info box appropriately
203
202
int localPlayerIdx = - 1 ;
204
- for ( int i = 0 ; i < networkCharSelection . LobbyPlayers . Count ; ++ i )
203
+ for ( int i = 0 ; i < m_NetworkCharSelection . LobbyPlayers . Count ; ++ i )
205
204
{
206
- if ( networkCharSelection . LobbyPlayers [ i ] . ClientId == NetworkManager . Singleton . LocalClientId )
205
+ if ( m_NetworkCharSelection . LobbyPlayers [ i ] . ClientId == NetworkManager . Singleton . LocalClientId )
207
206
{
208
207
localPlayerIdx = i ;
209
208
break ;
@@ -216,17 +215,17 @@ void OnLobbyPlayerStateChanged(NetworkListEvent<NetworkCharSelection.LobbyPlayer
216
215
// this can happen for various reasons, such as the lobby being full and us not getting a seat.
217
216
UpdateCharacterSelection ( NetworkCharSelection . SeatState . Inactive ) ;
218
217
}
219
- else if ( networkCharSelection . LobbyPlayers [ localPlayerIdx ] . SeatState == NetworkCharSelection . SeatState . Inactive )
218
+ else if ( m_NetworkCharSelection . LobbyPlayers [ localPlayerIdx ] . SeatState == NetworkCharSelection . SeatState . Inactive )
220
219
{
221
220
// we haven't chosen a seat yet (or were kicked out of our seat by someone else)
222
221
UpdateCharacterSelection ( NetworkCharSelection . SeatState . Inactive ) ;
223
222
// make sure our player num is properly set in Lobby UI
224
- OnAssignedPlayerNumber ( networkCharSelection . LobbyPlayers [ localPlayerIdx ] . PlayerNumber ) ;
223
+ OnAssignedPlayerNumber ( m_NetworkCharSelection . LobbyPlayers [ localPlayerIdx ] . PlayerNumber ) ;
225
224
}
226
225
else
227
226
{
228
227
// we have a seat! Note that if our seat is LockedIn, this function will also switch the lobby mode
229
- UpdateCharacterSelection ( networkCharSelection . LobbyPlayers [ localPlayerIdx ] . SeatState , networkCharSelection . LobbyPlayers [ localPlayerIdx ] . SeatIdx ) ;
228
+ UpdateCharacterSelection ( m_NetworkCharSelection . LobbyPlayers [ localPlayerIdx ] . SeatState , m_NetworkCharSelection . LobbyPlayers [ localPlayerIdx ] . SeatIdx ) ;
230
229
}
231
230
}
232
231
@@ -258,7 +257,7 @@ void UpdateCharacterSelection(NetworkCharSelection.SeatState state, int seatIdx
258
257
// change character preview when selecting a new seat
259
258
if ( isNewSeat )
260
259
{
261
- var selectedCharacterGraphics = GetCharacterGraphics ( networkCharSelection . AvatarConfiguration [ seatIdx ] ) ;
260
+ var selectedCharacterGraphics = GetCharacterGraphics ( m_NetworkCharSelection . AvatarConfiguration [ seatIdx ] ) ;
262
261
263
262
if ( m_CurrentCharacterGraphics )
264
263
{
@@ -269,15 +268,15 @@ void UpdateCharacterSelection(NetworkCharSelection.SeatState state, int seatIdx
269
268
m_CurrentCharacterGraphics = selectedCharacterGraphics ;
270
269
m_CurrentCharacterGraphicsAnimator = m_CurrentCharacterGraphics . GetComponent < Animator > ( ) ;
271
270
272
- m_ClassInfoBox . ConfigureForClass ( networkCharSelection . AvatarConfiguration [ seatIdx ] . CharacterClass ) ;
271
+ m_ClassInfoBox . ConfigureForClass ( m_NetworkCharSelection . AvatarConfiguration [ seatIdx ] . CharacterClass ) ;
273
272
}
274
273
}
275
274
if ( state == NetworkCharSelection . SeatState . LockedIn && ! m_HasLocalPlayerLockedIn )
276
275
{
277
276
// the local player has locked in their seat choice! Rearrange the UI appropriately
278
277
// the character should act excited
279
278
m_CurrentCharacterGraphicsAnimator . SetTrigger ( m_AnimationTriggerOnCharChosen ) ;
280
- ConfigureUIForLobbyMode ( networkCharSelection . IsLobbyClosed . Value ? LobbyMode . LobbyEnding : LobbyMode . SeatChosen ) ;
279
+ ConfigureUIForLobbyMode ( m_NetworkCharSelection . IsLobbyClosed . Value ? LobbyMode . LobbyEnding : LobbyMode . SeatChosen ) ;
281
280
m_HasLocalPlayerLockedIn = true ;
282
281
}
283
282
else if ( m_HasLocalPlayerLockedIn && state == NetworkCharSelection . SeatState . Active )
@@ -307,7 +306,7 @@ void UpdateSeats()
307
306
// But until a seat is locked in, we need to display each seat as being used by the latest player to choose it.
308
307
// So we go through all players and figure out who should visually be shown as sitting in that seat.
309
308
NetworkCharSelection . LobbyPlayerState [ ] curSeats = new NetworkCharSelection . LobbyPlayerState [ m_PlayerSeats . Count ] ;
310
- foreach ( NetworkCharSelection . LobbyPlayerState playerState in networkCharSelection . LobbyPlayers )
309
+ foreach ( NetworkCharSelection . LobbyPlayerState playerState in m_NetworkCharSelection . LobbyPlayers )
311
310
{
312
311
if ( playerState . SeatIdx == - 1 || playerState . SeatState == NetworkCharSelection . SeatState . Inactive )
313
312
continue ; // this player isn't seated at all!
@@ -344,7 +343,7 @@ void OnLobbyClosedChanged(bool wasLobbyClosed, bool isLobbyClosed)
344
343
else
345
344
{
346
345
ConfigureUIForLobbyMode ( LobbyMode . SeatChosen ) ;
347
- m_ClassInfoBox . ConfigureForClass ( networkCharSelection . AvatarConfiguration [ m_LastSeatSelected ] . CharacterClass ) ;
346
+ m_ClassInfoBox . ConfigureForClass ( m_NetworkCharSelection . AvatarConfiguration [ m_LastSeatSelected ] . CharacterClass ) ;
348
347
}
349
348
}
350
349
}
@@ -415,9 +414,9 @@ void ConfigureUIForLobbyMode(LobbyMode mode)
415
414
/// <param name="seatIdx"></param>
416
415
public void OnPlayerClickedSeat ( int seatIdx )
417
416
{
418
- if ( networkCharSelection . IsSpawned )
417
+ if ( m_NetworkCharSelection . IsSpawned )
419
418
{
420
- networkCharSelection . ChangeSeatServerRpc ( NetworkManager . Singleton . LocalClientId , seatIdx , false ) ;
419
+ m_NetworkCharSelection . ChangeSeatServerRpc ( NetworkManager . Singleton . LocalClientId , seatIdx , false ) ;
421
420
}
422
421
}
423
422
@@ -426,10 +425,10 @@ public void OnPlayerClickedSeat(int seatIdx)
426
425
/// </summary>
427
426
public void OnPlayerClickedReady ( )
428
427
{
429
- if ( networkCharSelection . IsSpawned )
428
+ if ( m_NetworkCharSelection . IsSpawned )
430
429
{
431
430
// request to lock in or unlock if already locked in
432
- networkCharSelection . ChangeSeatServerRpc ( NetworkManager . Singleton . LocalClientId , m_LastSeatSelected , ! m_HasLocalPlayerLockedIn ) ;
431
+ m_NetworkCharSelection . ChangeSeatServerRpc ( NetworkManager . Singleton . LocalClientId , m_LastSeatSelected , ! m_HasLocalPlayerLockedIn ) ;
433
432
}
434
433
}
435
434
0 commit comments