Quantcast
Channel: Recent Discussions — Photon Engine
Viewing all articles
Browse latest Browse all 15755

Using selectively OnPhotonSerializeView

$
0
0
I want to send/recieve in method OnPhotonSerializeView() only those players, who have some customProperty to reduce data traffic/ping.

Every player has customProperties "positionX" and "positionY". I try smth like that:
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext... //send data
...
}
else
{
object val;
if (PhotonNetwork.player.customProperties.TryGetValue("PositionX", out val) == true)
{
int posX = (int)(float)PhotonNetwork.player.customProperties["PositionX"];
int posY = (int)(float)PhotonNetwork.player.customProperties["PositionY"]; //get own client position

Vector3 myPosition = new Vector3(posX, posY);
Vector3 hisPosition = transform.position;

if (Vector3.Distance(hisPosition , myPosition ) > 200) //check if distance between us is big
{
return; //dont recieve data -> we don't waste some traffic to get data (is it true?)
}
}

stream.ReceiveNext... //continue getting data
...
}

Am I on right way? Or this won't reduce data traffic/ping?

Thanks a lot :)

UPD: This works (doesn't recieve data if distance is big), but I don't know how to check if this reduces client's traffic.

Viewing all articles
Browse latest Browse all 15755

Trending Articles