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); }
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); } }
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); }