x


Synchronize whole class and build a list of objects

Hey guys, okay i'm looking for days and cant find a solution: I have a server which has a list of alle connected Players. I have designed my own Players with the basic information like team, nation, color and stuff like that. Each player is able to modiefy the settings of his own player. So the problem is, i have no idea how to synchronize this list. I need the list on every client to show some kind of multiplayer-lobby like in warcraft3.

So basicly there are 2 questions:

1) How is it possible to create such a list?
2) How can I syncronize the data of each player? there are more complex structures in it.
I'm using c# so i have lots of different classes to synchronize.

more ▼

asked May 23 '12 at 05:46 PM

markus_hadinger gravatar image

markus_hadinger
0 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I really shouldn't do this

[RequireComponent(typeof(NetworkView))]

public class ProfileService : MonoBehaviour {

public class Profile {
    public string GamerTag;
    public string Team;
}

public string GamerName;

public string Team;

public Dictionary<NetworkPlayer, Profile> NetworkProfiles = new Dictionary<NetworkPlayer, Profile>();

void OnConnectedToServer()
{
    networkView.RPC("OnProfile", RPCMode.AllBuffered, networkView.owner, GamerName, Team);
}

void OnPlayerDisconnected(NetworkPlayer player)
{
    networkView.RPC("OnRemove", RPCMode.AllBuffered, player);

}

[RPC]
void OnProfile(NetworkPlayer player, string gName, string gTeam)
{
    NetworkProfiles.Add(player, new Profile { GamerTag = gName, Team = gTeam });
}

[RPC]
void OnRemove(NetworkPlayer player)
{
    NetworkProfiles.Remove(player);
}

}

more ▼

answered May 23 '12 at 06:15 PM

nventimiglia gravatar image

nventimiglia
277 7 13 16

You should make a check if the player is already in the dictionary and update it when it exists, because i'm pretty sure the profiles should be able to be updated ;)

Besides that, everything is fine

May 23 '12 at 06:23 PM Bunny83
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4139
x32
x9

asked: May 23 '12 at 05:46 PM

Seen: 435 times

Last Updated: May 23 '12 at 06:23 PM