public override void Deserialize(NetworkReader reader)
        {
            var messageVersion = reader.ReadPackedUInt32();

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

            this.version = messageVersion;
            this.lineRenderer.enabled = reader.ReadBoolean();
            int positionCount = (int)reader.ReadPackedUInt32();

            bool useWorldSpace = this.lineRenderer.useWorldSpace;

            for (int i = 0; i < positionCount; i++)
            {
                Lost.Caching.Vectors[i] = useWorldSpace ? NetworkTransformAnchor.TransformPosition(reader.ReadVector3()) : reader.ReadVector3();
            }

            this.lineRenderer.positionCount = positionCount;
            this.lineRenderer.SetPositions(Lost.Caching.Vectors);

            if (NetworkingManager.PrintDebugOutput)
            {
                Debug.Log($"NetworkLineRenderer {this.GetInstanceID()} deserialized {positionCount} positions.", this);
            }
        }
        public override void Serialize(NetworkWriter writer)
        {
            int  positionCount = this.lineRenderer.GetPositions(Lost.Caching.Vectors);
            bool useWorldSpace = this.lineRenderer.useWorldSpace;

            writer.WritePackedUInt32(++this.version);
            writer.Write(this.lineRenderer.enabled);
            writer.WritePackedUInt32((uint)positionCount);

            for (int i = 0; i < positionCount; i++)
            {
                if (useWorldSpace)
                {
                    writer.Write(NetworkTransformAnchor.InverseTransformPosition(Lost.Caching.Vectors[i]));
                }
                else
                {
                    writer.Write(Lost.Caching.Vectors[i]);
                }
            }

            if (NetworkingManager.PrintDebugOutput)
            {
                Debug.Log($"NetworkLineRenderer {this.GetInstanceID()} serialized {positionCount} positions.", this);
            }
        }
 public void PopulateMessage(NetworkIdentity identity)
 {
     this.NetworkId      = identity.NetworkId;
     this.OwnerId        = identity.OwnerId;
     this.IsEnabled      = identity.gameObject.activeSelf;
     this.ResourceName   = identity.ResourceName;
     this.CanChangeOwner = identity.CanChangeOwner;
     this.Position       = NetworkTransformAnchor.InverseTransformPosition(identity.transform.position);
     this.Rotation       = NetworkTransformAnchor.InverseTransformRotation(identity.transform.rotation);
 }
        public void PopulateNetworkIdentity(NetworkIdentity identity, bool updatePositionAndRotation)
        {
            identity.SetOwner(this.OwnerId, this.CanChangeOwner);
            identity.gameObject.SafeSetActive(this.IsEnabled);
            identity.ResourceName = identity.ResourceName;

            if (updatePositionAndRotation)
            {
                identity.transform.SetPositionAndRotation(
                    NetworkTransformAnchor.TransformPosition(this.Position),
                    NetworkTransformAnchor.TransformRotation(this.Rotation));
            }
        }
        public override void Serialize(NetworkWriter writer)
        {
            bool sendPhysics    = this.rigidBody != null;
            bool useGravity     = sendPhysics && this.rigidBody.useGravity;
            bool freezeRotation = sendPhysics && this.rigidBody.freezeRotation;
            bool isKinematic    = sendPhysics && this.rigidBody.isKinematic;

            int sent = 0;

            NetworkUtil.SetBit(ref sent, 0, this.sendPosition);
            NetworkUtil.SetBit(ref sent, 1, this.sendRotation);
            NetworkUtil.SetBit(ref sent, 2, this.sendScale);
            NetworkUtil.SetBit(ref sent, 3, sendPhysics);
            NetworkUtil.SetBit(ref sent, 4, useGravity);
            NetworkUtil.SetBit(ref sent, 5, freezeRotation);
            NetworkUtil.SetBit(ref sent, 6, isKinematic);

            writer.WritePackedUInt32(++this.version);
            writer.WritePackedUInt32((uint)sent);

            if (this.sendPosition)
            {
                writer.Write(NetworkTransformAnchor.InverseTransformPosition(this.transform.position));
            }

            if (this.sendRotation)
            {
                writer.Write(NetworkTransformAnchor.InverseTransformRotation(this.transform.rotation));
            }

            if (this.sendScale)
            {
                writer.Write(this.transform.localScale);
            }

            if (sendPhysics)
            {
                writer.Write(this.rigidBody.velocity);
            }
        }
        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;
            }
        }