private void SerializeMode3D(P2PNetworkWriter writer)
 {
     if (base.gameObject.activeSelf)
     {
         writer.Write(this.m_RigidBody3D.worldCenterOfMass);
     }
     else
     {
         writer.Write(base.transform.position);
     }
     ReplicatedTransform.SerializeVelocity3D(writer, this.m_RigidBody3D.velocity, ReplicatedTransform.CompressionSyncMode.None);
     if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
     {
         if (base.gameObject.activeSelf)
         {
             ReplicatedTransform.SerializeRotation3D(writer, this.m_RigidBody3D.rotation, this.syncRotationAxis, this.rotationSyncCompression);
         }
         else
         {
             ReplicatedTransform.SerializeRotation3D(writer, base.transform.rotation, this.syncRotationAxis, this.rotationSyncCompression);
         }
     }
     if (this.m_SyncSpin)
     {
         ReplicatedTransform.SerializeSpin3D(writer, this.m_RigidBody3D.angularVelocity, this.syncRotationAxis, this.rotationSyncCompression);
     }
     this.m_PrevPosition = (base.gameObject.activeSelf ? this.m_RigidBody3D.position : base.transform.position);
     this.m_PrevRotation = (base.gameObject.activeSelf ? this.m_RigidBody3D.rotation : base.transform.rotation);
     this.m_PrevVelocity = this.m_RigidBody3D.velocity.sqrMagnitude;
 }
 private void UnserializeModeCharacterController(P2PNetworkReader reader, bool initial_state)
 {
     if (this.m_MoveCallback3D != null)
     {
         Vector3    targetSyncPosition   = reader.ReadVector3();
         Quaternion targetSyncRotation3D = Quaternion.identity;
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             targetSyncRotation3D = ReplicatedTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
         }
         Vector3 targetSyncVelocity = (this.m_CharacterController != null) ? this.m_CharacterController.velocity : Vector3.zero;
         if (!this.m_MoveCallback3D(ref targetSyncPosition, ref targetSyncVelocity, ref targetSyncRotation3D))
         {
             return;
         }
         this.m_TargetSyncPosition = targetSyncPosition;
         this.m_TargetSyncVelocity = targetSyncVelocity;
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_TargetSyncRotation3D = targetSyncRotation3D;
         }
     }
     else
     {
         this.m_TargetSyncPosition = reader.ReadVector3();
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_TargetSyncRotation3D = ReplicatedTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
         }
     }
     if (this.m_CharacterController != null)
     {
         if (initial_state || this.ReplGetReplicationInterval() <= 0f)
         {
             base.transform.position = this.m_TargetSyncPosition;
             if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
             {
                 base.transform.rotation = this.m_TargetSyncRotation3D;
             }
             this.m_FixedPosDiff = Vector3.zero;
             return;
         }
         Vector3 a = (this.m_TargetSyncPosition - base.transform.position) / this.ReplGetReplicationInterval();
         this.m_FixedPosDiff = a * Time.fixedDeltaTime;
         if ((base.transform.position - this.m_TargetSyncPosition).magnitude > this.snapThreshold)
         {
             base.transform.position = this.m_TargetSyncPosition;
             this.m_FixedPosDiff     = Vector3.zero;
         }
         if (this.interpolateRotation == 0f && this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             base.transform.rotation = this.m_TargetSyncRotation3D;
         }
         if (this.m_InterpolateMovement == 0f)
         {
             base.transform.position = this.m_TargetSyncPosition;
         }
     }
 }
 private void SerializeModeCharacterController(P2PNetworkWriter writer)
 {
     writer.Write(base.transform.position);
     if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
     {
         ReplicatedTransform.SerializeRotation3D(writer, base.transform.rotation, this.syncRotationAxis, this.rotationSyncCompression);
     }
     this.m_PrevPosition = base.transform.position;
     this.m_PrevRotation = base.transform.rotation;
     this.m_PrevVelocity = 0f;
 }
    public static Quaternion UnserializeRotation3D(P2PNetworkReader reader, ReplicatedTransform.AxisSyncMode mode, ReplicatedTransform.CompressionSyncMode compression)
    {
        Quaternion identity = Quaternion.identity;
        Vector3    zero     = Vector3.zero;

        switch (mode)
        {
        case ReplicatedTransform.AxisSyncMode.AxisX:
            zero.Set(ReplicatedTransform.ReadAngle(reader, compression), 0f, 0f);
            identity.eulerAngles = zero;
            break;

        case ReplicatedTransform.AxisSyncMode.AxisY:
            zero.Set(0f, ReplicatedTransform.ReadAngle(reader, compression), 0f);
            identity.eulerAngles = zero;
            break;

        case ReplicatedTransform.AxisSyncMode.AxisZ:
            zero.Set(0f, 0f, ReplicatedTransform.ReadAngle(reader, compression));
            identity.eulerAngles = zero;
            break;

        case ReplicatedTransform.AxisSyncMode.AxisXY:
            zero.Set(ReplicatedTransform.ReadAngle(reader, compression), ReplicatedTransform.ReadAngle(reader, compression), 0f);
            identity.eulerAngles = zero;
            break;

        case ReplicatedTransform.AxisSyncMode.AxisXZ:
            zero.Set(ReplicatedTransform.ReadAngle(reader, compression), 0f, ReplicatedTransform.ReadAngle(reader, compression));
            identity.eulerAngles = zero;
            break;

        case ReplicatedTransform.AxisSyncMode.AxisYZ:
            zero.Set(0f, ReplicatedTransform.ReadAngle(reader, compression), ReplicatedTransform.ReadAngle(reader, compression));
            identity.eulerAngles = zero;
            break;

        case ReplicatedTransform.AxisSyncMode.AxisXYZ:
            zero.Set(ReplicatedTransform.ReadAngle(reader, compression), ReplicatedTransform.ReadAngle(reader, compression), ReplicatedTransform.ReadAngle(reader, compression));
            identity.eulerAngles = zero;
            break;
        }
        return(identity);
    }
    public static void SerializeSpin3D(P2PNetworkWriter writer, Vector3 angularVelocity, ReplicatedTransform.AxisSyncMode mode, ReplicatedTransform.CompressionSyncMode compression)
    {
        switch (mode)
        {
        case ReplicatedTransform.AxisSyncMode.None:
            break;

        case ReplicatedTransform.AxisSyncMode.AxisX:
            ReplicatedTransform.WriteAngle(writer, angularVelocity.x, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisY:
            ReplicatedTransform.WriteAngle(writer, angularVelocity.y, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisZ:
            ReplicatedTransform.WriteAngle(writer, angularVelocity.z, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisXY:
            ReplicatedTransform.WriteAngle(writer, angularVelocity.x, compression);
            ReplicatedTransform.WriteAngle(writer, angularVelocity.y, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisXZ:
            ReplicatedTransform.WriteAngle(writer, angularVelocity.x, compression);
            ReplicatedTransform.WriteAngle(writer, angularVelocity.z, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisYZ:
            ReplicatedTransform.WriteAngle(writer, angularVelocity.y, compression);
            ReplicatedTransform.WriteAngle(writer, angularVelocity.z, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisXYZ:
            ReplicatedTransform.WriteAngle(writer, angularVelocity.x, compression);
            ReplicatedTransform.WriteAngle(writer, angularVelocity.y, compression);
            ReplicatedTransform.WriteAngle(writer, angularVelocity.z, compression);
            break;

        default:
            return;
        }
    }
    public static void SerializeRotation3D(P2PNetworkWriter writer, Quaternion rot, ReplicatedTransform.AxisSyncMode mode, ReplicatedTransform.CompressionSyncMode compression)
    {
        switch (mode)
        {
        case ReplicatedTransform.AxisSyncMode.None:
            break;

        case ReplicatedTransform.AxisSyncMode.AxisX:
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.x, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisY:
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.y, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisZ:
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.z, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisXY:
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.x, compression);
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.y, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisXZ:
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.x, compression);
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.z, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisYZ:
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.y, compression);
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.z, compression);
            return;

        case ReplicatedTransform.AxisSyncMode.AxisXYZ:
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.x, compression);
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.y, compression);
            ReplicatedTransform.WriteAngle(writer, rot.eulerAngles.z, compression);
            break;

        default:
            return;
        }
    }
    private void UnserializeModeTransform(P2PNetworkReader reader, bool initial_state)
    {
        if (initial_state)
        {
            this.m_TargetSyncPosition = (base.transform.position = reader.ReadVector3());
            if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
            {
                this.m_TargetSyncRotation3D = (base.transform.rotation = ReplicatedTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression));
            }
            this.m_FixedPosDiff = Vector3.zero;
            return;
        }
        this.m_TargetSyncPosition = reader.ReadVector3();
        if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
        {
            this.m_TargetSyncRotation3D = ReplicatedTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
        }
        Vector3 a = (this.m_TargetSyncPosition - base.transform.position) / this.ReplGetReplicationInterval();

        this.m_FixedPosDiff = a * Time.fixedDeltaTime;
    }
 private void SerializeMode2D(P2PNetworkWriter writer)
 {
     writer.Write(this.m_RigidBody2D.position);
     ReplicatedTransform.SerializeVelocity2D(writer, this.m_RigidBody2D.velocity, ReplicatedTransform.CompressionSyncMode.None);
     if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
     {
         float num = this.m_RigidBody2D.rotation % 360f;
         if (num < 0f)
         {
             num += 360f;
         }
         ReplicatedTransform.SerializeRotation2D(writer, num, this.rotationSyncCompression);
     }
     if (this.m_SyncSpin)
     {
         ReplicatedTransform.SerializeSpin2D(writer, this.m_RigidBody2D.angularVelocity, this.rotationSyncCompression);
     }
     this.m_PrevPosition = this.m_RigidBody2D.position;
     this.m_PrevRotation = base.transform.rotation;
     this.m_PrevVelocity = this.m_RigidBody2D.velocity.sqrMagnitude;
 }
    public static Vector3 UnserializeSpin3D(P2PNetworkReader reader, ReplicatedTransform.AxisSyncMode mode, ReplicatedTransform.CompressionSyncMode compression)
    {
        Vector3 zero = Vector3.zero;

        switch (mode)
        {
        case ReplicatedTransform.AxisSyncMode.AxisX:
            zero.Set(ReplicatedTransform.ReadAngle(reader, compression), 0f, 0f);
            break;

        case ReplicatedTransform.AxisSyncMode.AxisY:
            zero.Set(0f, ReplicatedTransform.ReadAngle(reader, compression), 0f);
            break;

        case ReplicatedTransform.AxisSyncMode.AxisZ:
            zero.Set(0f, 0f, ReplicatedTransform.ReadAngle(reader, compression));
            break;

        case ReplicatedTransform.AxisSyncMode.AxisXY:
            zero.Set(ReplicatedTransform.ReadAngle(reader, compression), ReplicatedTransform.ReadAngle(reader, compression), 0f);
            break;

        case ReplicatedTransform.AxisSyncMode.AxisXZ:
            zero.Set(ReplicatedTransform.ReadAngle(reader, compression), 0f, ReplicatedTransform.ReadAngle(reader, compression));
            break;

        case ReplicatedTransform.AxisSyncMode.AxisYZ:
            zero.Set(0f, ReplicatedTransform.ReadAngle(reader, compression), ReplicatedTransform.ReadAngle(reader, compression));
            break;

        case ReplicatedTransform.AxisSyncMode.AxisXYZ:
            zero.Set(ReplicatedTransform.ReadAngle(reader, compression), ReplicatedTransform.ReadAngle(reader, compression), ReplicatedTransform.ReadAngle(reader, compression));
            break;
        }
        return(zero);
    }
예제 #10
0
 private void UnserializeMode2D(P2PNetworkReader reader, bool initialState)
 {
     if (this.m_ClientMoveCallback2D != null)
     {
         Vector2 v  = reader.ReadVector2();
         Vector2 v2 = reader.ReadVector2();
         float   targetSyncRotation2D = 0f;
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             targetSyncRotation2D = ReplicatedTransform.UnserializeRotation2D(reader, this.rotationSyncCompression);
         }
         if (!this.m_ClientMoveCallback2D(ref v, ref v2, ref targetSyncRotation2D))
         {
             return;
         }
         this.m_TargetSyncPosition = v;
         this.m_TargetSyncVelocity = v2;
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_TargetSyncRotation2D = targetSyncRotation2D;
         }
     }
     else
     {
         this.m_TargetSyncPosition = reader.ReadVector2();
         this.m_TargetSyncVelocity = reader.ReadVector2();
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_TargetSyncRotation2D = ReplicatedTransform.UnserializeRotation2D(reader, this.rotationSyncCompression);
         }
     }
     if (this.syncSpin)
     {
         this.m_TargetSyncAngularVelocity2D = ReplicatedTransform.UnserializeSpin2D(reader, this.rotationSyncCompression);
     }
     if (this.m_RigidBody2D != null)
     {
         if (this.ReplGetReplicationInterval() <= 0f)
         {
             base.transform.position     = this.m_TargetSyncPosition;
             this.m_RigidBody2D.velocity = this.m_TargetSyncVelocity;
             if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
             {
                 this.m_RigidBody2D.MoveRotation(this.m_TargetSyncRotation2D);
             }
             if (this.syncSpin)
             {
                 this.m_RigidBody2D.angularVelocity = this.m_TargetSyncAngularVelocity2D;
             }
             return;
         }
         if ((this.m_RigidBody2D.position - this.m_TargetSyncPosition).magnitude > this.snapThreshold)
         {
             this.m_RigidBody2D.position = this.m_TargetSyncPosition;
             this.m_RigidBody2D.velocity = this.m_TargetSyncVelocity;
         }
         if (this.interpolateRotation == 0f && this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_RigidBody2D.rotation = this.m_TargetSyncRotation2D;
             if (this.syncSpin)
             {
                 this.m_RigidBody2D.angularVelocity = this.m_TargetSyncAngularVelocity2D;
             }
         }
         if (this.m_InterpolateMovement == 0f)
         {
             this.m_RigidBody2D.position = this.m_TargetSyncPosition;
         }
         if (initialState)
         {
             this.m_RigidBody2D.rotation = this.m_TargetSyncRotation2D;
         }
     }
 }
예제 #11
0
 private void UnserializeMode3D(P2PNetworkReader reader, bool initial_state)
 {
     if (this.m_MoveCallback3D != null)
     {
         Vector3    targetSyncPosition   = reader.ReadVector3();
         Vector3    targetSyncVelocity   = reader.ReadVector3();
         Quaternion targetSyncRotation3D = Quaternion.identity;
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             targetSyncRotation3D = ReplicatedTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
         }
         if (!this.m_MoveCallback3D(ref targetSyncPosition, ref targetSyncVelocity, ref targetSyncRotation3D))
         {
             return;
         }
         this.m_TargetSyncPosition = targetSyncPosition;
         this.m_TargetSyncVelocity = targetSyncVelocity;
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_TargetSyncRotation3D = targetSyncRotation3D;
         }
     }
     else
     {
         this.m_TargetSyncPosition = reader.ReadVector3();
         if (this.m_RigidBody3D != null)
         {
             this.m_TargetSyncTransformPosition = this.m_RigidBody3D.position - this.m_RigidBody3D.worldCenterOfMass + this.m_TargetSyncPosition;
         }
         else
         {
             Renderer rendererComponent = this.RendererComponent;
             if (rendererComponent != null)
             {
                 this.m_TargetSyncTransformPosition = base.transform.position - rendererComponent.bounds.center + this.m_TargetSyncPosition;
             }
         }
         this.m_TargetSyncVelocity = reader.ReadVector3();
         if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_TargetSyncRotation3D = ReplicatedTransform.UnserializeRotation3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
         }
     }
     if (this.syncSpin)
     {
         this.m_TargetSyncAngularVelocity3D = ReplicatedTransform.UnserializeSpin3D(reader, this.syncRotationAxis, this.rotationSyncCompression);
     }
     if (!base.gameObject.activeSelf || initial_state)
     {
         base.transform.position = this.m_TargetSyncTransformPosition;
         base.transform.rotation = this.m_TargetSyncRotation3D;
     }
     if (this.m_RigidBody3D != null)
     {
         if (this.ReplGetReplicationInterval() <= 0f)
         {
             this.m_RigidBody3D.MovePosition(this.m_TargetSyncTransformPosition);
             this.m_RigidBody3D.velocity = this.m_TargetSyncVelocity;
             if (this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
             {
                 this.m_RigidBody3D.MoveRotation(this.m_TargetSyncRotation3D);
             }
             if (this.syncSpin)
             {
                 this.m_RigidBody3D.angularVelocity = this.m_TargetSyncAngularVelocity3D;
             }
             return;
         }
         if ((this.m_RigidBody3D.worldCenterOfMass - this.m_TargetSyncPosition).magnitude > this.snapThreshold)
         {
             this.m_RigidBody3D.MovePosition(this.m_TargetSyncTransformPosition);
             this.m_RigidBody3D.velocity = this.m_TargetSyncVelocity;
         }
         if (this.interpolateRotation == 0f && this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_RigidBody3D.rotation = this.m_TargetSyncRotation3D;
             if (this.syncSpin)
             {
                 this.m_RigidBody3D.angularVelocity = this.m_TargetSyncAngularVelocity3D;
             }
         }
         if (this.m_InterpolateMovement == 0f)
         {
             this.m_RigidBody3D.position = this.m_TargetSyncTransformPosition;
         }
         if (initial_state && this.syncRotationAxis != ReplicatedTransform.AxisSyncMode.None)
         {
             this.m_RigidBody3D.rotation = this.m_TargetSyncRotation3D;
         }
     }
 }
예제 #12
0
 public static float UnserializeSpin2D(P2PNetworkReader reader, ReplicatedTransform.CompressionSyncMode compression)
 {
     return(ReplicatedTransform.ReadAngle(reader, compression));
 }
예제 #13
0
 public static void SerializeSpin2D(P2PNetworkWriter writer, float angularVelocity, ReplicatedTransform.CompressionSyncMode compression)
 {
     ReplicatedTransform.WriteAngle(writer, angularVelocity, compression);
 }
예제 #14
0
 public static void SerializeRotation2D(P2PNetworkWriter writer, float rot, ReplicatedTransform.CompressionSyncMode compression)
 {
     ReplicatedTransform.WriteAngle(writer, rot, compression);
 }