Beispiel #1
0
    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);
        }
    }
Beispiel #2
0
    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;
        }
    }