public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { stream.SendNext(body.position); stream.SendNext(body.velocity); stream.SendNext(body.rotation); stream.SendNext(body.angularVelocity); DRV.FlagReset(); DRQ.FlagReset(); } if (stream.IsReading) { Vector3 newPosition = (Vector3)stream.ReceiveNext(); Vector3 newVelocity = (Vector3)stream.ReceiveNext(); Quaternion newRotation = (Quaternion)stream.ReceiveNext(); Vector3 newAngularVelocity = (Vector3)stream.ReceiveNext(); DRV.NetworkUpdate(newPosition, newVelocity, 0, false); DRQ.NetworkUpdate(newRotation, newAngularVelocity, 0, false); } }
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 FixedUpdate() { colLevel = _colLevel; _colLevel = ColLevel.None; if (body.IsSleeping()) { colLevel = ColLevel.GroundOrSleep; } float E = .5f * body.velocity.sqrMagnitude + .5f * Vector3.Dot(body.angularVelocity, ApplyTensor(body.angularVelocity, body.inertiaTensor, body.rotation * body.inertiaTensorRotation)) / body.mass; if (isActiveAndEnabled && PhotonNetwork.IsConnectedAndReady) { if (isOtherPlayerPickup) { if (isLocalPlayerPickup) { onOtherPlayerTake.Invoke(); } } else if (isLocalPlayerPickup) { //Let Grabable Script handle the all } else if (photonView.IsMine) { if (colLevel == ColLevel.GroundOrSleep) { if (E < Physics.sleepThreshold) { if (!PhotonNetwork.IsMasterClient) { //send stopped body Vector3 position = body.position; Quaternion rotation = body.rotation; ToAttached(ref position, ref rotation); DRV.NetworkUpdate(position, Vector3.zero, 0, true); DRQ.NetworkUpdate(rotation, Vector3.zero, 0, true); useDR = true; TransfreOwnershipBrutal(PhotonNetwork.MasterClient); } } } if (colLevel == ColLevel.OtherOwned) { if (!PhotonNetwork.IsMasterClient) { //send stopped body Vector3 position = body.position; Quaternion rotation = body.rotation; ToAttached(ref position, ref rotation); DRV.NetworkUpdate(position, Vector3.zero, 0, true); DRQ.NetworkUpdate(rotation, Vector3.zero, 0, true); useDR = true; TransfreOwnershipBrutal(PhotonNetwork.MasterClient); } } } else { if (colLevel == ColLevel.LocalPickedup) { TransfreOwnershipBrutal(PhotonNetwork.LocalPlayer); } } } if (photonView.IsMine) { useDR = false; } if (useDR) { if (DRV.isReady && DRQ.isReady) { Vector3 position = DRV.Update(Time.fixedDeltaTime); Quaternion rotation = DRQ.Update(Time.fixedDeltaTime); Vector3 velocity = DRV.velocity; Vector3 angularVelocity = DRQ.angularVelocity; FromAttached(ref position, ref rotation, ref velocity, ref angularVelocity); body.MovePosition(position); body.velocity = velocity; body.MoveRotation(rotation); body.angularVelocity = angularVelocity; } if (body.useGravity) { body.AddForce(-body.mass * Physics.gravity); } } //body.isKinematic = useDR;//TODOTODOTODO Do it after teleportation to wakeup stacked objects //DebugColor(); }