コード例 #1
0
        public void CalculateDelta(NetStream state0, NetStream state1, NetStream delta)
        {
            bool          flag           = false;
            NetVector3    netVector      = default(NetVector3);
            NetVector3    netVector2     = default(NetVector3);
            NetQuaternion netQuaternion  = default(NetQuaternion);
            NetQuaternion netQuaternion2 = default(NetQuaternion);

            if (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World || syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
            {
                if (syncPosition != 0)
                {
                    netVector  = ((state0 != null) ? NetVector3.Read(state0, posfull) : zero);
                    netVector2 = NetVector3.Read(state1, posfull);
                    flag      |= (netVector2 != netVector);
                }
                if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
                {
                    netQuaternion  = ((state0 != null) ? NetQuaternion.Read(state0, rotfull) : identity);
                    netQuaternion2 = NetQuaternion.Read(state1, rotfull);
                    flag          |= (netQuaternion2 != netQuaternion);
                }
                if (flag)
                {
                    delta.Write(v: true);
                    if (syncPosition != 0)
                    {
                        NetVector3.Delta(netVector, netVector2, poslarge).Write(delta, possmall, poslarge, posfull);
                    }
                    if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
                    {
                        NetQuaternion.Delta(netQuaternion, netQuaternion2, rotlarge).Write(delta, rotsmall, rotlarge, rotfull);
                    }
                }
                else
                {
                    delta.Write(v: false);
                }
            }
            if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
            {
                eulerEncoder.CalculateDelta(state0, state1, delta);
            }
            if (syncLocalScale)
            {
                NetVector3 netVector3 = default(NetVector3);
                NetVector3 netVector4 = default(NetVector3);
                netVector3 = ((state0 != null) ? NetVector3.Read(state0, posfull) : zero);
                netVector4 = NetVector3.Read(state1, posfull);
                if (netVector4 != netVector3)
                {
                    delta.Write(v: true);
                    NetVector3.Delta(netVector3, netVector4, poslarge).Write(delta, possmall, poslarge, posfull);
                }
                else
                {
                    delta.Write(v: false);
                }
            }
        }
コード例 #2
0
 public void ApplyState(NetStream state)
 {
     if (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World)
     {
         Vector3 target = NetVector3.Read(state, posfull).Dequantize(posRange);
         ApplyPositionState(target);
     }
     if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
     {
         NetQuaternion netQuaternion = appliedRot = NetQuaternion.Read(state, rotfull);
         Quaternion    target2       = netQuaternion.Dequantize();
         ApplyQuaternionState(target2);
     }
     else if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
     {
         float diff = eulerEncoder.ApplyState(state);
         ApplyEulerState(diff);
     }
     if (body != null)
     {
         Rigidbody rigidbody = body;
         Vector3   vector    = Vector3.zero;
         body.velocity             = vector;
         rigidbody.angularVelocity = vector;
     }
     if (syncLocalScale)
     {
         Vector3 localScale = NetVector3.Read(state, posfull).Dequantize(posRange);
         base.transform.localScale = localScale;
     }
 }
コード例 #3
0
        public Quaternion ApplyLerpedState(NetStream state0, NetStream state1, float mix)
        {
            Quaternion a = NetQuaternion.Read(state0, fullBits).Dequantize();
            Quaternion b = NetQuaternion.Read(state1, fullBits).Dequantize();

            return(Quaternion.Slerp(a, b, mix));
        }
コード例 #4
0
        public static NetQuaternionDelta Delta(NetQuaternion from, NetQuaternion to, ushort bitlarge)
        {
            int num  = to.x - from.x;
            int num2 = to.y - from.y;
            int num3 = to.z - from.z;
            int num4 = 1 << bitlarge - 1;

            if (num < -num4 || num >= num4 || num2 < -num4 || num2 >= num4 || num3 < -num4 || num3 >= num4)
            {
                NetQuaternionDelta result = default(NetQuaternionDelta);
                result.isRelative = false;
                result.sel        = to.sel;
                result.x          = to.x;
                result.y          = to.y;
                result.z          = to.z;
                return(result);
            }
            NetQuaternionDelta result2 = default(NetQuaternionDelta);

            result2.isRelative = true;
            result2.sel        = to.sel;
            result2.x          = num;
            result2.y          = num2;
            result2.z          = num3;
            return(result2);
        }
コード例 #5
0
 public static NetQuaternion AddDelta(NetQuaternion from, NetQuaternionDelta delta)
 {
     if (delta.isRelative)
     {
         return(new NetQuaternion(delta.sel, from.x + delta.x, from.y + delta.y, from.z + delta.z, from.bits));
     }
     return(new NetQuaternion(delta.sel, delta.x, delta.y, delta.z, from.bits));
 }
コード例 #6
0
        public void ApplySnapshot(NetStream stream)
        {
            NetVector3    netVector     = NetVector3.Read(stream, 18);
            NetQuaternion netQuaternion = NetQuaternion.Read(stream, 9);

            netPos = netVector.Dequantize(500f);
            netRot = netQuaternion.Dequantize();
            base.transform.localPosition = netPos;
            base.transform.localRotation = netRot;
        }
コード例 #7
0
        public static NetQuaternionDelta WorstCaseDelta(NetQuaternion from, NetQuaternion to)
        {
            NetQuaternionDelta result = default(NetQuaternionDelta);

            result.isRelative = false;
            result.sel        = to.sel;
            result.x          = to.x;
            result.y          = to.y;
            result.z          = to.z;
            return(result);
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
 public void AddDelta(NetStream state0, NetStream delta, NetStream result)
 {
     if (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World || syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
     {
         if (delta.ReadBool())
         {
             if (syncPosition != 0)
             {
                 NetVector3      from   = (state0 != null) ? NetVector3.Read(state0, posfull) : zero;
                 NetVector3Delta delta2 = NetVector3Delta.Read(delta, possmall, poslarge, posfull);
                 NetVector3.AddDelta(from, delta2).Write(result);
             }
             if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
             {
                 NetQuaternion      from2  = (state0 != null) ? NetQuaternion.Read(state0, rotfull) : identity;
                 NetQuaternionDelta delta3 = NetQuaternionDelta.Read(delta, rotsmall, rotlarge, rotfull);
                 NetQuaternion.AddDelta(from2, delta3).Write(result);
             }
         }
         else
         {
             if (syncPosition != 0)
             {
                 ((state0 != null) ? NetVector3.Read(state0, posfull) : zero).Write(result);
             }
             if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
             {
                 ((state0 != null) ? NetQuaternion.Read(state0, rotfull) : identity).Write(result);
             }
         }
     }
     if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
     {
         eulerEncoder.AddDelta(state0, delta, result);
     }
     if (syncLocalScale)
     {
         if (delta.ReadBool())
         {
             NetVector3      from3  = (state0 != null) ? NetVector3.Read(state0, posfull) : zero;
             NetVector3Delta delta4 = NetVector3Delta.Read(delta, possmall, poslarge, posfull);
             NetVector3.AddDelta(from3, delta4).Write(result);
         }
         else
         {
             ((state0 != null) ? NetVector3.Read(state0, posfull) : zero).Write(result);
         }
     }
 }
コード例 #11
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);
            }
        }
コード例 #12
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);
        }
コード例 #13
0
 public void ApplyLerpedState(NetStream state0, NetStream state1, float mix)
 {
     if (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World)
     {
         Vector3 a      = NetVector3.Read(state0, posfull).Dequantize(posRange);
         Vector3 vector = NetVector3.Read(state1, posfull).Dequantize(posRange);
         if ((a - vector).sqrMagnitude > 15f)
         {
             a = vector;
         }
         Vector3 target = Vector3.Lerp(a, vector, mix);
         ApplyPositionState(target);
     }
     if (syncRotation == NetBodySyncRotation.Relative || syncRotation == NetBodySyncRotation.Absolute || syncRotation == NetBodySyncRotation.Local || syncRotation == NetBodySyncRotation.World)
     {
         Quaternion    a2            = NetQuaternion.Read(state0, rotfull).Dequantize();
         NetQuaternion netQuaternion = appliedRot = NetQuaternion.Read(state1, rotfull);
         Quaternion    b             = netQuaternion.Dequantize();
         Quaternion    target2       = Quaternion.Slerp(a2, b, mix);
         ApplyQuaternionState(target2);
     }
     else if (syncRotation == NetBodySyncRotation.EulerX || syncRotation == NetBodySyncRotation.EulerY || syncRotation == NetBodySyncRotation.EulerZ)
     {
         float diff = eulerEncoder.ApplyLerpedState(state0, state1, mix);
         ApplyEulerState(diff);
     }
     if (body != null)
     {
         Rigidbody rigidbody = body;
         Vector3   vector2   = Vector3.zero;
         body.velocity             = vector2;
         rigidbody.angularVelocity = vector2;
     }
     if (syncLocalScale && (syncPosition == NetBodySyncPosition.Relative || syncPosition == NetBodySyncPosition.Absolute || syncPosition == NetBodySyncPosition.Local || syncPosition == NetBodySyncPosition.World))
     {
         Vector3 a3         = NetVector3.Read(state0, posfull).Dequantize(posRange);
         Vector3 b2         = NetVector3.Read(state1, posfull).Dequantize(posRange);
         Vector3 localScale = Vector3.Lerp(a3, b2, mix);
         base.transform.localScale = localScale;
     }
 }
コード例 #14
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);
        }
コード例 #15
0
        public void ReadDelta(NetStream stream, NetStream reference, NetStream fullStream)
        {
            bool          flag          = stream.ReadBool();
            NetVector3    netVector     = (reference != null) ? NetVector3.Read(reference, 18) : default(NetVector3);
            NetQuaternion netQuaternion = (reference != null) ? NetQuaternion.Read(reference, 9) : default(NetQuaternion);
            NetVector3    netVector2;
            NetQuaternion netQuaternion2;

            if (flag)
            {
                NetVector3Delta delta = NetVector3Delta.Read(stream, 5, 9, 18);
                netVector2 = NetVector3.AddDelta(netVector, delta);
                NetQuaternionDelta delta2 = NetQuaternionDelta.Read(stream, 5, 8, 9);
                netQuaternion2 = NetQuaternion.AddDelta(netQuaternion, delta2);
            }
            else
            {
                netVector2     = netVector;
                netQuaternion2 = netQuaternion;
            }
            netVector2.Write(fullStream);
            netQuaternion2.Write(fullStream);
        }
コード例 #16
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);
         }
     }
 }
コード例 #17
0
 public Quaternion ApplyState(NetStream state)
 {
     return(NetQuaternion.Read(state, fullBits).Dequantize());
 }
コード例 #18
0
 public void CollectState(NetStream stream, Quaternion value)
 {
     NetQuaternion.Quantize(value, fullBits).Write(stream);
 }