Synchronising multiple object's values in OnPhotonSerializeView?
Options
I've got a kind of redstone circuit setup, and i'd like to synchronise this by sending the values of all the power sources, and their ID so I can find and set them on the other end. I'm doing this by doing a foreach loop, checking if it's a source, and then sending over its ID and its power level. For some reason this isn't working, any help on how I should do this?
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { stream.SendNext(active); if (active) { foreach(PoweredBlock block in poweredParts) { if(block.isSource && block.dynamic) { Vector2 blockInfo = new Vector2(block.blockID, block.currentPower); stream.SendNext(blockInfo); } } } } if (stream.isReading) { active = (bool)stream.ReceiveNext(); if(active) { foreach (PoweredBlock block in poweredParts) { Vector2 blockInfo = (Vector2)stream.ReceiveNext(); if (block.blockID == blockInfo.x) block.currentPower = blockInfo.y; } } } }
0
Comments
-
Bump
0 -
At a glace you have an if statement on your write side that will create asymmetry with the read side. You have a write inside of your if block, and the read outside of the if block.0
-
ah, yes i'll fix that. Is a foreach statement allowed when sending data? Or does that mean it might break0