I have a struct like this
[System.Serializable]
public class PlayerInfo
{
public int ConnId;
public int TeamIndex;
public int PlayerIndex;
}
[System.Serializable]
public class TeamInfo
{
public int TeamIndex;
public List<PlayerInfo> Player;
public TeamInfo(int teamIndex, List<PlayerInfo> player = null)
{
TeamIndex = teamIndex;
Player = new List<PlayerInfo>();
}
public TeamInfo() { }
}
//...
public readonly SyncList<TeamInfo> TheTeamInfo = new SyncList<TeamInfo>();
public override void OnStartServer()
{
base.OnStartServer();
// init teaminfo, two teams
for (int i = 0; i < 2; i++)
{
TheTeamInfo.Add(new TeamInfo(i));
}
}
//...
[Command]
public void CmdAddPlayerToTeam(int teamIndex, int playerIndex, NetworkConnectionToClient conn = null)
{
PlayerInfo newPlayer = new PlayerInfo
{
ConnId = conn.connectionId,
TeamIndex = teamIndex,
PlayerIndex = playerIndex
};
// to make Mirror detect the change and sync
var teamRef = TheTeamInfo[teamIndex];
teamRef.Player.Add(newPlayer);
TheTeamInfo[teamIndex] = teamRef;
}
when I called the function CmdAddPlayerToTeam to change the TheTeamInfo, the client did not sync that, is me miss something? some one could help me?