private void UpdateRigidbodyData()
        {
            Entities.With(rigidbodyGroup).ForEach(
                (Entity entity, DynamicBuffer <BufferedTransform> buffer,
                 ref TicksSinceLastTransformUpdate ticksSinceLastTransformUpdate,
                 ref TransformInternal.Component transformInternal,
                 ref SpatialEntityId spatialEntityId) =>
            {
                if (updateSystem
                    .GetAuthorityChangesReceived(spatialEntityId.EntityId, TransformInternal.ComponentId)
                    .Count == 0)
                {
                    return;
                }

                var rigidbody = EntityManager.GetComponentObject <Rigidbody>(entity);
                rigidbody.MovePosition(TransformUtils.ToUnityVector3(transformInternal.Location) + worker.Origin);
                rigidbody.MoveRotation(TransformUtils.ToUnityQuaternion(transformInternal.Rotation));
                rigidbody.AddForce(TransformUtils.ToUnityVector3(transformInternal.Velocity) - rigidbody.velocity,
                                   ForceMode.VelocityChange);

                buffer.Clear();
                ticksSinceLastTransformUpdate = new TicksSinceLastTransformUpdate();
            });
        }
 private static BufferedTransform ToBufferedTransformAtTick(TransformInternal.Component component, uint tick)
 {
     return(new BufferedTransform
     {
         Position = TransformUtils.ToUnityVector3(component.Location),
         Velocity = TransformUtils.ToUnityVector3(component.Velocity),
         Orientation = TransformUtils.ToUnityQuaternion(component.Rotation),
         PhysicsTick = tick
     });
 }
 private static BufferedTransform ToBufferedTransform(TransformInternal.Component transform)
 {
     return(new BufferedTransform
     {
         Position = TransformUtils.ToUnityVector3(transform.Location),
         Velocity = TransformUtils.ToUnityVector3(transform.Velocity),
         Orientation = TransformUtils.ToUnityQuaternion(transform.Rotation),
         PhysicsTick = transform.PhysicsTick
     });
 }
        protected override void OnUpdate()
        {
            Entities.With(transformGroup).ForEach(
                (ref TransformToSet transformToSet, ref SpatialEntityId spatialEntityId,
                 ref TransformInternal.Component transformInternal) =>
            {
                var updates =
                    updateSystem.GetEntityComponentUpdatesReceived <TransformInternal.Update>(spatialEntityId.EntityId);

                if (updates.Count == 0)
                {
                    return;
                }

                transformToSet = new TransformToSet
                {
                    Position    = TransformUtils.ToUnityVector3(transformInternal.Location) + worker.Origin,
                    Velocity    = TransformUtils.ToUnityVector3(transformInternal.Velocity),
                    Orientation = TransformUtils.ToUnityQuaternion(transformInternal.Rotation)
                };
            });
        }
        private void AddCommonSendComponents(EntityCommandBuffer commandBuffer)
        {
            commandBuffer.AddComponent(entity, new GetTransformFromGameObjectTag());

            var transformComponent = transformReader.Data;

            var defaultToSend = new TransformToSend
            {
                Position    = TransformUtils.ToUnityVector3(transformComponent.Location) - world.GetExistingSystem <WorkerSystem>().Origin,
                Velocity    = TransformUtils.ToUnityVector3(transformComponent.Velocity),
                Orientation = TransformUtils.ToUnityQuaternion(transformComponent.Rotation)
            };

            var ticksSinceLastUpdate = new TicksSinceLastTransformUpdate
            {
                NumberOfTicks = 0
            };

            var lastTransform = new LastTransformSentData
            {
                // could set this to the max time if we want to immediately send something
                TimeSinceLastUpdate = 0.0f,
                Transform           = transformComponent
            };

            var position     = entityManager.GetComponentData <Position.Component>(entity);
            var lastPosition = new LastPositionSentData
            {
                // could set this to the max time if we want to immediately send something
                TimeSinceLastUpdate = 0.0f,
                Position            = position
            };

            commandBuffer.AddComponent(entity, defaultToSend);
            commandBuffer.AddComponent(entity, ticksSinceLastUpdate);
            commandBuffer.AddComponent(entity, lastPosition);
            commandBuffer.AddComponent(entity, lastTransform);
        }
        private void UpdateTransformData()
        {
            Entities.With(transformGroup).ForEach((Entity entity,
                                                   DynamicBuffer <BufferedTransform> buffer,
                                                   ref TicksSinceLastTransformUpdate ticksSinceLastTransformUpdate,
                                                   ref TransformInternal.Component transformInternal,
                                                   ref SpatialEntityId spatialEntityId) =>
            {
                if (updateSystem
                    .GetAuthorityChangesReceived(spatialEntityId.EntityId, TransformInternal.ComponentId)
                    .Count == 0)
                {
                    return;
                }

                var unityTransform      = EntityManager.GetComponentObject <UnityEngine.Transform>(entity);
                unityTransform.position = TransformUtils.ToUnityVector3(transformInternal.Location) + worker.Origin;
                unityTransform.rotation = TransformUtils.ToUnityQuaternion(transformInternal.Rotation);

                buffer.Clear();
                ticksSinceLastTransformUpdate = new TicksSinceLastTransformUpdate();
            });
        }
        private void AddCommonReceiveComponents(EntityCommandBuffer commandBuffer)
        {
            commandBuffer.AddComponent(entity, new SetTransformToGameObjectTag());

            var transformComponent = transformReader.Data;

            var defaultToSet = new TransformToSet
            {
                Position              = TransformUtils.ToUnityVector3(transformComponent.Location) + world.GetExistingSystem <WorkerSystem>().Origin,
                Velocity              = TransformUtils.ToUnityVector3(transformComponent.Velocity),
                Orientation           = TransformUtils.ToUnityQuaternion(transformComponent.Rotation),
                ApproximateRemoteTick = 0
            };

            var previousTransform = new DeferredUpdateTransform
            {
                Transform = transformComponent
            };

            commandBuffer.AddComponent(entity, defaultToSet);
            commandBuffer.AddComponent(entity, previousTransform);
            commandBuffer.AddBuffer <BufferedTransform>(entity);
        }