- Home /
converting Photon stream to JS
could someone help me convert this code to javascript?
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
stream.SendNext(position);
stream.SendNext(movespeed);
stream.SendNext(up);
stream.SendNext(down);
stream.SendNext(left);
stream.SendNext(right);
}
else {
position = (Transform)stream.ReceiveNext();
movespeed = (int)stream.ReceiveNext();
up = (bool)stream.ReceiveNext();
down = (bool)stream.ReceiveNext();
left = (bool)stream.ReceiveNext();
right = (bool)stream.ReceiveNext();
}
}
i have tryed many different ways and i just cant seem to get it right!
TTHANK YOU,
mewhy
Answer by Bunny83 · Mar 04, 2013 at 10:35 PM
// UnityScript
function OnPhotonSerializeView(stream : PhotonStream, info : PhotonMessageInfo)
{
if(stream.isWriting)
{
stream.SendNext(position);
stream.SendNext(movespeed);
stream.SendNext(up);
stream.SendNext(down);
stream.SendNext(left);
stream.SendNext(right);
}
else
{
position = stream.ReceiveNext();
movespeed = stream.ReceiveNext();
up = stream.ReceiveNext();
down = stream.ReceiveNext();
left = stream.ReceiveNext();
right = stream.ReceiveNext();
}
}
Actually i think that the C# code you've posted makes no sense. I don't think you can serialize "Transform" components. Also the variable name is position, so i guess it's a Vector3.
In UnityScript there is no c-style cast. Usually the compiler will cast automatically, at least the value-types.
do you know how to add the class Photon.$$anonymous$$onoBehaviour??
What do you mean by "add"? I never used Photon, but i guess you should derive your own class from this type
This worked perfect for me thanks! Sorry I don't have the rep to thumbs up you, but this was exactly what I needed.