void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { float sendInterval = 1.0f / PhotonNetwork.SerializationRate; float lag = Mathf.Max(0, (float)(PhotonNetwork.Time - info.SentServerTime)); if (stream.IsWriting) { Vector3 playerPosition = attachedTransform ? attachedTransform.InverseTransformPoint(playerRoot.position) : playerRoot.position; Quaternion playerRotation = attachedTransform ? Quaternion.Inverse(attachedTransform.rotation) * playerRoot.rotation : playerRoot.rotation; stream.SendNext(attachedPhotonViewID); stream.SendNext(playerPosition); stream.SendNext(DRPlayerRootV.EstimateVelocity(playerPosition, sendInterval, firstTake)); stream.SendNext(playerRotation); stream.SendNext(DRPlayerRootQ.EstimateVelocity(playerRotation, sendInterval, firstTake)); for (int i = 0; i < riggingTransforms.Length; ++i) { stream.SendNext(toLocal(riggingTransforms[i].position)); stream.SendNext(DRRiggingV[i].EstimateVelocity(toLocal(riggingTransforms[i].position), sendInterval, firstTake)); stream.SendNext(toLocal(riggingTransforms[i].rotation)); stream.SendNext(DRRiggingQ[i].EstimateVelocity(toLocal(riggingTransforms[i].rotation), sendInterval, firstTake)); } for (int i = 0; i < animators.Length; ++i) { var anim = animators[i]; foreach (var s in anim.floats) { stream.SendNext(anim.animator.GetFloat(s)); } foreach (var s in anim.bools) { stream.SendNext(anim.animator.GetBool(s)); } foreach (var s in anim.integers) { stream.SendNext(anim.animator.GetInteger(s)); } } } else { Transform oldAttachedTransform = attachedTransform; attachedPhotonViewID = (int)stream.ReceiveNext(); if (attachedPhotonViewID == 0) { attachedTransform = null; } else { attachedTransform = PhotonView.Find(attachedPhotonViewID).transform; } if (oldAttachedTransform != attachedTransform) { MarkTeleport(); } DRPlayerRootV.NetworkUpdate((Vector3)stream.ReceiveNext(), (Vector3)stream.ReceiveNext(), lag, firstTake); DRPlayerRootQ.NetworkUpdate((Quaternion)stream.ReceiveNext(), (Vector3)stream.ReceiveNext(), lag, firstTake); for (int i = 0; i < riggingTransforms.Length; ++i) { DRRiggingV[i].NetworkUpdate((Vector3)stream.ReceiveNext(), (Vector3)stream.ReceiveNext(), lag, firstTake); DRRiggingQ[i].NetworkUpdate((Quaternion)stream.ReceiveNext(), (Vector3)stream.ReceiveNext(), lag, firstTake); } for (int i = 0; i < animators.Length; ++i) { var anim = animators[i]; foreach (var s in anim.floats) { anim.animator.SetFloat(s, (float)stream.ReceiveNext()); } foreach (var s in anim.bools) { anim.animator.SetBool(s, (bool)stream.ReceiveNext()); } foreach (var s in anim.integers) { anim.animator.SetInteger(s, (int)stream.ReceiveNext()); } } } firstTake = false; }
void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { float sendInterval = 1.0f / PhotonNetwork.SerializationRate; if (stream.IsWriting) { byte statCode = 0; if (isLocalPlayerPickup) { statCode |= 0x1; } if (isLocalPlayerPickup) { statCode |= 0x2; } if (colLevel == ColLevel.GroundOrSleep) { statCode |= 0x2; } if (colLevel == ColLevel.LocalOwned) { statCode |= 0x2; } if (colLevel == ColLevel.LocalPickedup) { statCode |= 0x2; } Vector3 position = body.position; Quaternion rotation = body.rotation; Vector3 velocity = body.velocity; Vector3 angularVelocity = body.angularVelocity; if (useDR) { velocity = DRV.EstimateVelocity(position, sendInterval, firstTake); angularVelocity = DRQ.EstimateVelocity(rotation, sendInterval, firstTake); firstTake = false; } ToAttached(ref position, ref rotation, ref velocity, ref angularVelocity); stream.SendNext(statCode); stream.SendNext(attachedPhotonViewID); stream.SendNext(position); stream.SendNext(rotation); stream.SendNext(velocity); stream.SendNext(angularVelocity); DRV.FlagReset(); DRQ.FlagReset(); } if (stream.IsReading && !photonView.IsMine) { byte statCode = (byte)stream.ReceiveNext(); int newAttachedPhotonViewID = (int)stream.ReceiveNext(); isOtherPlayerPickup = (statCode & 0x1) != 0; useDR = (statCode & 0x2) != 0; Vector3 newPosition = (Vector3)stream.ReceiveNext(); Quaternion newRotation = (Quaternion)stream.ReceiveNext(); Vector3 newVelocity = (Vector3)stream.ReceiveNext(); Vector3 newAngularVelocity = (Vector3)stream.ReceiveNext(); SetAttachFromRemote(newAttachedPhotonViewID); if (useDR) { DRV.NetworkUpdate(newPosition, newVelocity, 0, firstTake); DRQ.NetworkUpdate(newRotation, newAngularVelocity, 0, firstTake); } else { FromAttached(ref newPosition, ref newRotation, ref newVelocity, ref newAngularVelocity); //if ((newPosition - body.position).magnitude / sendInterval > 2*Mathf.Max(1, newVelocity.magnitude)) { body.MovePosition(newPosition); body.velocity = newVelocity; } //else//TODO { //body.velocity = newVelocity + (newPosition - body.position) / sendInterval; } body.angularVelocity = newAngularVelocity; body.MoveRotation(newRotation); DRV.FlagReset(); DRQ.FlagReset(); } firstTake = false; } }