コード例 #1
0
        public void CollectState(NetStream stream)
        {
            if (syncPosition == NetBodySyncPosition.Relative)
            {
                NetVector3.Quantize(base.transform.position - relativeTo.position - basePos, posRange, posfull).Write(stream);
            }
            else if (syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World)
            {
                NetVector3.Quantize(((syncPosition != NetBodySyncPosition.Local) ? base.transform.position : base.transform.localPosition) - basePos, posRange, posfull).Write(stream);
            }
            if (syncRotation == NetBodySyncRotation.Relative)
            {
                NetQuaternion netQuaternion = collectedRot = NetQuaternion.Quantize(baseRotInv * Quaternion.Inverse(relativeTo.rotation) * base.transform.rotation, rotfull);
                netQuaternion.Write(stream);
            }
            else if (syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
            {
                NetQuaternion netQuaternion2 = collectedRot = NetQuaternion.Quantize(baseRotInv * ((syncRotation != NetBodySyncRotation.Local) ? base.transform.rotation : base.transform.localRotation), rotfull);
                netQuaternion2.Write(stream);
            }
            else if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
            {
                float value;
                switch (syncRotation)
                {
                case NetBodySyncRotation.EulerX:
                    value = 0f - Math3d.SignedVectorAngle(baseRotInv * base.transform.localRotation * Vector3.up, Vector3.up, Vector3.right);
                    break;

                case NetBodySyncRotation.EulerY:
                    value = 0f - Math3d.SignedVectorAngle(baseRotInv * base.transform.localRotation * Vector3.forward, Vector3.forward, Vector3.up);
                    break;

                case NetBodySyncRotation.EulerZ:
                    value = 0f - Math3d.SignedVectorAngle(baseRotInv * base.transform.localRotation * Vector3.right, Vector3.right, Vector3.forward);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                collectedEuler = value;
                eulerEncoder.CollectState(stream, value);
            }
            if (syncLocalScale)
            {
                NetVector3.Quantize(base.transform.localScale, posRange, posfull).Write(stream);
            }
        }
コード例 #2
0
        public void WriteDelta(NetStream stream, NetStream reference, NetStream fullStream)
        {
            netPos = base.transform.localPosition;
            NetVector3 netVector  = NetVector3.Quantize(netPos, 500f, 18);
            NetVector3 netVector2 = (reference != null) ? NetVector3.Read(reference, 18) : default(NetVector3);

            netRot = base.transform.localRotation;
            NetQuaternion netQuaternion  = NetQuaternion.Quantize(netRot, 9);
            NetQuaternion netQuaternion2 = (reference != null) ? NetQuaternion.Read(reference, 9) : default(NetQuaternion);

            if (netVector != netVector2 || netQuaternion != netQuaternion2)
            {
                stream.Write(v: true);
                NetVector3.Delta(netVector2, netVector, 9).Write(stream, 5, 9, 18);
                NetQuaternion.Delta(netQuaternion2, netQuaternion, 8).Write(stream, 5, 8, 9);
            }
            else
            {
                stream.Write(v: false);
            }
            netVector.Write(fullStream);
            netQuaternion.Write(fullStream);
        }
コード例 #3
0
        public void AddDelta(NetStream state0, NetStream delta, NetStream result, bool readChanged = true)
        {
            NetQuaternion from = (state0 != null) ? NetQuaternion.Read(state0, fullBits) : NetQuaternion.Quantize(startRot, fullBits);

            if (delta == null || (readChanged && !delta.ReadBool()))
            {
                from.Write(result);
                return;
            }
            NetQuaternionDelta delta2 = NetQuaternionDelta.Read(delta, deltaSmall, deltaLarge, fullBits);

            NetQuaternion.AddDelta(from, delta2).Write(result);
        }
コード例 #4
0
        public bool CalculateWorstCaseDelta(NetStream state0, NetStream state1, NetStream delta, bool writeChanged = true)
        {
            NetQuaternion from = (state0 != null) ? NetQuaternion.Read(state0, fullBits) : NetQuaternion.Quantize(startRot, fullBits);
            NetQuaternion to   = (state1 != null) ? NetQuaternion.Read(state1, fullBits) : NetQuaternion.Quantize(startRot, fullBits);

            if (writeChanged)
            {
                delta.Write(v: true);
            }
            NetQuaternion.WorstCaseDelta(from, to).Write(delta, deltaSmall, deltaLarge, fullBits);
            return(true);
        }
コード例 #5
0
        public bool CalculateDelta(NetStream state0, NetStream state1, NetStream delta, bool writeChanged = true)
        {
            NetQuaternion netQuaternion  = (state0 != null) ? NetQuaternion.Read(state0, fullBits) : NetQuaternion.Quantize(startRot, fullBits);
            NetQuaternion netQuaternion2 = NetQuaternion.Read(state1, fullBits);

            if (netQuaternion == netQuaternion2)
            {
                if (writeChanged)
                {
                    delta.Write(v: false);
                }
                return(false);
            }
            if (writeChanged)
            {
                delta.Write(v: true);
            }
            NetQuaternion.Delta(netQuaternion, netQuaternion2, deltaLarge).Write(delta, deltaSmall, deltaLarge, fullBits);
            return(true);
        }
コード例 #6
0
 public void CollectState(NetStream stream, Quaternion value)
 {
     NetQuaternion.Quantize(value, fullBits).Write(stream);
 }
コード例 #7
0
 public void Start()
 {
     if (!isStarted)
     {
         isStarted = true;
         if (NetGame.isClient)
         {
             hasNetSetActive = (GetComponent <NetSetActive>() != null);
         }
         NetBodyResetOverride component = GetComponent <NetBodyResetOverride>();
         if ((bool)component)
         {
             mResetFramesAdditionalDelay = component.FramesDelay;
         }
         body        = GetComponent <Rigidbody>();
         isKinematic = body.isKinematic;
         if (syncPosition == NetBodySyncPosition.Relative)
         {
             posRange = 10f;
             posfull -= 6;
         }
         if (syncPosition == NetBodySyncPosition.Local)
         {
             posRange = 10f;
             posfull -= 6;
         }
         if (posRangeOverride != 0f)
         {
             posRange = posRangeOverride;
         }
         eulerEncoder.fullBits   = (ushort)(eulerEncoder.fullBits + rotPrecision);
         eulerEncoder.deltaSmall = (ushort)(eulerEncoder.deltaSmall + rotPrecision);
         eulerEncoder.deltaLarge = (ushort)(eulerEncoder.deltaLarge + rotPrecision);
         possmall        = (ushort)(possmall + posPrecision);
         poslarge        = (ushort)(poslarge + posPrecision);
         posfull         = (ushort)(posfull + posPrecision);
         rotfull         = (ushort)(rotfull + rotPrecision);
         rotsmall        = (ushort)(rotsmall + rotPrecision);
         rotlarge        = (ushort)(rotlarge + rotPrecision);
         startPos        = base.transform.position;
         startRot        = base.transform.rotation;
         startLocalScale = base.transform.localScale;
         if (syncPosition == NetBodySyncPosition.Relative)
         {
             basePos = base.transform.position - relativeTo.position;
         }
         else if (syncPosition == NetBodySyncPosition.Absolute)
         {
             basePos = Vector3.zero;
         }
         else
         {
             basePos = ((syncPosition != NetBodySyncPosition.Local) ? base.transform.position : base.transform.localPosition);
         }
         if (syncRotation == NetBodySyncRotation.Relative)
         {
             baseRot = Quaternion.Inverse(relativeTo.rotation) * base.transform.rotation;
         }
         else if (syncRotation == NetBodySyncRotation.Absolute)
         {
             baseRot = Quaternion.identity;
         }
         else
         {
             baseRot = ((syncRotation != NetBodySyncRotation.Local && syncRotation != NetBodySyncRotation.EulerX && syncRotation != NetBodySyncRotation.EulerY && syncRotation != NetBodySyncRotation.EulerZ) ? base.transform.rotation : base.transform.localRotation);
         }
         baseRotInv = Quaternion.Inverse(baseRot);
         zero       = NetVector3.Quantize(Vector3.zero, posRange, posfull);
         identity   = NetQuaternion.Quantize(Quaternion.identity, rotfull);
         if (!disableSleep)
         {
             sleep = new NetBodySleep(body);
         }
     }
 }