privatePlayerDatam_localUserData;// This has an ID that's not necessarily the OwnerClientId, since all clients will see all spawned objects regardless of ownership.
publicActiononGameBeginning;
Actionm_onConnectionVerified,m_onGameEnd;
privateint
m_expectedPlayerCount;// Used by the host, but we can't call the RPC until the network connection completes.
Locator.Get.Provide(this);// Simplifies access since some networked objects can't easily communicate locally (e.g. the host might call a ClientRpc without that client knowing where the call originated).
NetworkObjectplayerCursor=Instantiate(m_playerCursorPrefab);// Note that the client will not receive the cursor object reference, so the cursor must handle initializing itself.
playerCursor.SpawnWithOwnership(clientData.id);
// Note that the client will not receive the cursor object reference, so the cursor must handle initializing itself.
boolareAllPlayersConnected=NetworkManager.Singleton.ConnectedClients.Count>=m_expectedPlayerCount;// The game will begin at this point, or else there's a timeout for booting any unconnected players.
// The game will begin at this point, or else there's a timeout for booting any unconnected players.
Locator.Get.Messenger.OnReceiveMessage(MessageType.EndGame,null);// We only send this message if the game completes, since the player remains in the lobby in that case. If the player leaves with the back button, that instead sends them to the menu.
/// Handles selecting the randomized sequence of symbols to spawn, choosing a subset to be the ordered target sequence that each player needs to select.
/// This also handles selecting randomized positions for the symbols, and it sets up the target sequence animation for the instruction sequence.
privateList<int>m_fullSequence=newList<int>();// This is owned by the host, and each index is assigned as a NetworkVariable to each SymbolObject.
privateNetworkList<int>m_targetSequence;// This is owned by the host but needs to be available to all clients, so it's a NetworkedList here.
privateDictionary<ulong,int>m_targetSequenceIndexPerPlayer=newDictionary<ulong,int>();// Each player's current target. Also owned by the host, indexed by client ID.
// This is owned by the host, and each index is assigned as a NetworkVariable to each SymbolObject.
List<int>m_FullSequenceServer=newList<int>();
// This is owned by the host but needs to be available to all clients, so it's a NetworkedList here.
NetworkList<int>m_targetSequence;
// Each player's current target. Also owned by the host, indexed by client ID.
intnumTargetSequences=(int)(k_symbolCount*2/3f)/3;// About 2/3 of the symbols will be definitely part of the target sequence.
intnumTargetSequences=
(int)(symbolCount*2/3f)/
3;// About 2/3 of the symbols will be definitely part of the target sequence.
m_fullSequence.Add(m_targetSequence[2]);// We want a List instead of a Queue or Stack for faster insertion, but we will remove indices backwards so as to not resize other entries.
m_fullSequence.Add(m_targetSequence[1]);
m_fullSequence.Add(m_targetSequence[0]);
m_FullSequenceServer.Add(
m_targetSequence[
2]);// We want a List instead of a Queue or Stack for faster insertion, but we will remove indices backwards so as to not resize other entries.
m_FullSequenceServer.Add(m_targetSequence[1]);
m_FullSequenceServer.Add(m_targetSequence[0]);
// Then, fill in with a good mix of the remaining symbols.
/// This holds the logic and data for an individual symbol, which can be "clicked" if the server detects the collision with a player who sends a click input.
/// This holds the logic and data for an individual symbolIndex, which can be "clicked" if the server detects the collision with a player who sends a click input.
/// </summary>
publicclassSymbolObject:NetworkBehaviour
{
privateAnimatorm_animator;
publicboolClicked{get;privateset;}
[HideInInspector]
publicNetworkVariable<int>symbolIndex;// The index into SymbolData, not the index of this object.
publicintSymbolIndex{get;privateset;}
publicoverridevoidOnNetworkSpawn()
publicvoidSetSymbolIndex_Server(intsymbolIndex)
symbolIndex.OnValueChanged+=OnSymbolIndexSet;
SetSymbolSprite(symbolIndex);
SetSymbolIndex_ClientRpc(symbolIndex);
/// <summary>
/// Because of the need to distinguish host vs. client calls, we use the symbolIndex NetworkVariable to learn what symbol to display.
// Actually destroying the symbol objects can cause garbage collection and other delays that might lead to desyncs.
// Actually destroying the symbolIndex objects can cause garbage collection and other delays that might lead to desyncs.
// Disabling the networked object can also cause issues, so instead, just move the object, and it will be cleaned up once the NetworkManager is destroyed.
// (If we used object pooling, this is where we would instead return it to the pool.)
//The animation calls RemoveSymbol(only for server
//It's easier to have the post-animation symbol "deletion" happen entirely in server world rather than depend on client-side animation triggers.
//It's easier to have the post-animation symbolIndex "deletion" happen entirely in server world rather than depend on client-side animation triggers.