예제 #1
0
        public override void Deserialize(NetworkReader reader)
        {
            int  sent           = (int)reader.ReadPackedUInt32();
            bool sentPosition   = NetworkUtil.GetBit(sent, 0);
            bool sentRotation   = NetworkUtil.GetBit(sent, 1);
            bool sentScale      = NetworkUtil.GetBit(sent, 2);
            bool sentPhysics    = NetworkUtil.GetBit(sent, 3);
            bool useGravity     = NetworkUtil.GetBit(sent, 4);
            bool freezeRotation = NetworkUtil.GetBit(sent, 5);
            bool isKinematic    = NetworkUtil.GetBit(sent, 6);

            if (sentPosition)
            {
                Vector3 newDesiredPosition = reader.ReadVector3();

                if (this.lastVelocityUpdateTime < 0.0f)
                {
                    this.estimatedVelocity = Vector3.zero;
                }
                else
                {
                    float timeSinceLastUpdate = Time.realtimeSinceStartup - this.lastVelocityUpdateTime;

                    if (timeSinceLastUpdate > 0.01)
                    {
                        this.estimatedVelocity = (newDesiredPosition - this.desiredPosition) / timeSinceLastUpdate;
                    }
                }

                this.desiredPosition        = newDesiredPosition;
                this.lastVelocityUpdateTime = Time.realtimeSinceStartup;
            }

            if (sentRotation)
            {
                this.desiredRotation = reader.ReadQuaternion();
            }

            if (sentScale)
            {
                this.desiredScale = reader.ReadVector3();
            }

            if (sentPhysics)
            {
                this.rigidBody.velocity       = reader.ReadVector3();
                this.rigidBody.useGravity     = useGravity;
                this.rigidBody.freezeRotation = freezeRotation;
                this.rigidBody.isKinematic    = isKinematic;
            }
        }
        public override void Deserialize(NetworkReader reader)
        {
            uint messageVersion = reader.ReadPackedUInt32();

            if (this.version > messageVersion)
            {
                return;
            }

            this.version = messageVersion;

            int  sent           = (int)reader.ReadPackedUInt32();
            bool sentPosition   = NetworkUtil.GetBit(sent, 0);
            bool sentRotation   = NetworkUtil.GetBit(sent, 1);
            bool sentScale      = NetworkUtil.GetBit(sent, 2);
            bool sentPhysics    = NetworkUtil.GetBit(sent, 3);
            bool useGravity     = NetworkUtil.GetBit(sent, 4);
            bool freezeRotation = NetworkUtil.GetBit(sent, 5);
            bool isKinematic    = NetworkUtil.GetBit(sent, 6);

            if (sentPosition)
            {
                Vector3 newDesiredPosition = NetworkTransformAnchor.TransformPosition(reader.ReadVector3());

                if (this.lastVelocityUpdateTime < 0.0f)
                {
                    this.estimatedVelocity = Vector3.zero;
                }
                else
                {
                    float timeSinceLastUpdate = Time.realtimeSinceStartup - this.lastVelocityUpdateTime;

                    if (timeSinceLastUpdate > 0.01)
                    {
                        this.estimatedVelocity = (newDesiredPosition - this.desiredPosition) / timeSinceLastUpdate;
                    }
                }

                this.desiredPosition        = newDesiredPosition;
                this.lastVelocityUpdateTime = Time.realtimeSinceStartup;
            }

            if (sentRotation)
            {
                this.desiredRotation = NetworkTransformAnchor.TransformRotation(reader.ReadQuaternion());
            }

            if (sentScale)
            {
                this.desiredScale = reader.ReadVector3();
            }

            // Early out and don't update physics if we're trying to get ownership of this object
            if (this.Identity.IsRequestingOwnership)
            {
                return;
            }

            if (sentPhysics)
            {
                this.rigidBody.velocity       = reader.ReadVector3();
                this.rigidBody.useGravity     = useGravity;
                this.rigidBody.freezeRotation = freezeRotation;
                this.rigidBody.isKinematic    = isKinematic;
            }
        }