//if we're the main team system, we can push our state to the other clients public override void SyncSystem() { if (client.hostAuthority) { //create the teamallocationdata object TeamAllocationData teamData = new TeamAllocationData(ClientTeams); SendRequest(teamData, (int)TeamSystemRequest.TeamAllocationData); } }
public override void HandleMessage(GameSystemData data) { //get the request type from the first byte in the array TeamSystemRequest request = (TeamSystemRequest)data.D[0]; //then remove that byte from the message to leave it readable data.D = data.D.AsMemory().Slice(1).ToArray(); switch (request) { //we're receiving the state of the teams case TeamSystemRequest.TeamAllocationData: TeamAllocationData teamData = MessagePackSerializer.Deserialize <TeamAllocationData>(data.D); //store the new team setup ClientTeams = teamData.ClientTeams(); //iterate through all of the clients we have data about foreach (int key in ClientTeams.Keys) { //change the team client.gamePlayers[key].team = ClientTeams[key]; if (playerListUI) { playerListUI.AddPlayerToTeamList(client.gamePlayers[key].AsPlayerData(), ClientTeams[key]); } } break; //someone wants to change teams case TeamSystemRequest.ChangeTeamRequest: ChangeTeamRequest teamRequest = MessagePackSerializer.Deserialize <ChangeTeamRequest>(data.D); //see if they have a team entry, if not, give them one, if yes, change the entry if (ClientTeams.TryGetValue(teamRequest.C, out _)) { ClientTeams[teamRequest.C] = teamRequest.R; } else { ClientTeams.Add(teamRequest.C, teamRequest.R); } //change the player's team too client.gamePlayers[teamRequest.C].team = teamRequest.R; //and tell the player list ui to do the same if (playerListUI) { playerListUI.AddPlayerToTeamList(client.gamePlayers[teamRequest.C].AsPlayerData(), teamRequest.R); } //sync the system if we can SyncSystem(); break; //we've been asked to select a team, so we need to ask the player case TeamSystemRequest.SelectTeamRequest: //spawn the correct select team ui depending on the input method LevelSelectUI levelUI; if (client.inputMethod == InputMethod.VR) { Instantiate(SelectTeamPhysicalUI); } else if (levelUI = FindObjectOfType <LevelSelectUI>()) { levelUI.OpenNonVRSelectTeamUI(this); } break; } }