Using player.CustomProperties to store Colors and Materials
Options
Hello everyone!
Setting up a sample project to test a few of the networking packages that are available and so far I've had success getting Photon set up. I'm building a lobby and have reached the part where I need to start sending and updating data between the players. The first thing I've tried to do is set up a custom property for which color the player has selected, and placed the R, G, B, A values into a Hashtable.
public void SetColor() {
localUserColor = new Color ();
localUserColor.r = 0;
localUserColor.g = 0;
localUserColor.b = 0;
localUserColor.a = 1;
Hashtable colorHash = new Hashtable();
colorHash.Add("R", localUserColor.r);
colorHash.Add("G", localUserColor.g);
colorHash.Add("B", localUserColor.b);
colorHash.Add("A", localUserColor.a);
PhotonNetwork.player.SetCustomProperties(colorHash);
}
I had planned to update the player color for all players under a foreach loop:
public void OnPhotonPlayerPropertiesChanged () {
foreach (PhotonPlayer player in PhotonNetwork.playerList) {
}
}
Problem is I'm having issues solving how to access the values of the hash table to plug them back into the image's Color. I combed the documentation but it doesn't seem to work the way I think it does.
Totally new to Networked games, any advice is wonderful.
Thank you,
Setting up a sample project to test a few of the networking packages that are available and so far I've had success getting Photon set up. I'm building a lobby and have reached the part where I need to start sending and updating data between the players. The first thing I've tried to do is set up a custom property for which color the player has selected, and placed the R, G, B, A values into a Hashtable.
public void SetColor() {
localUserColor = new Color ();
localUserColor.r = 0;
localUserColor.g = 0;
localUserColor.b = 0;
localUserColor.a = 1;
Hashtable colorHash = new Hashtable();
colorHash.Add("R", localUserColor.r);
colorHash.Add("G", localUserColor.g);
colorHash.Add("B", localUserColor.b);
colorHash.Add("A", localUserColor.a);
PhotonNetwork.player.SetCustomProperties(colorHash);
}
I had planned to update the player color for all players under a foreach loop:
public void OnPhotonPlayerPropertiesChanged () {
foreach (PhotonPlayer player in PhotonNetwork.playerList) {
}
}
Problem is I'm having issues solving how to access the values of the hash table to plug them back into the image's Color. I combed the documentation but it doesn't seem to work the way I think it does.
Totally new to Networked games, any advice is wonderful.
Thank you,
0
Comments
-
Sorry if this has been posted elsewhere, can anyone point me in the right direction to utilizing these hash tables?0
-
Hi @CuirassEntertainment,
accessing Hashtables is mostly the same as accessing arrays. Let's assume that 'ht' is your already set up Hashtable and you want to access a stored value, in this case we are using 'R'.float r = (float) ht["R"]; // do the others as well localUserColor = new Color(r, g, b, a);
There also is a callback which notifies you about changed player properties. It isOnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
. you can read about this one over here.0