protected override void OnUpdate() { for (int i = 0; i < rigidbodyData.Length; ++i) { var rigidbody = rigidbodyData.Rigidbody[i]; var transformToSend = new TransformToSend { Position = rigidbody.position, Velocity = rigidbody.velocity, Orientation = rigidbody.rotation }; rigidbodyData.TransformToSend[i] = transformToSend; } for (int i = 0; i < transformData.Length; ++i) { var transform = transformData.Transform[i]; var transformToSend = new TransformToSend { Position = transform.position, Velocity = Vector3.zero, Orientation = transform.rotation }; transformData.TransformToSend[i] = transformToSend; } }
public void UpdateLatestTransform(ref TransformToSend transformToSend, Rigidbody rigidbody) { transformToSend = new TransformToSend { Position = rigidbody.position, Velocity = rigidbody.velocity, Orientation = rigidbody.rotation }; }
public void UpdateLatestTransform(ref TransformToSend transformToSend, Rigidbody2D rigidbody) { transformToSend = new TransformToSend { Position = rigidbody.position, Velocity = rigidbody.velocity, Orientation = Quaternion.Euler(0, 0, rigidbody.rotation) }; }
private void UpdateTransformData() { Entities.With(transformGroup).ForEach((ref TransformToSend transformToSend, Transform transform) => { transformToSend = new TransformToSend { Position = transform.position, Velocity = Vector3.zero, Orientation = transform.rotation }; }); }
private void UpdateRigidbodyData() { Entities.With(rigidbodyGroup).ForEach((ref TransformToSend transformToSend, Rigidbody rigidbody) => { transformToSend = new TransformToSend { Position = rigidbody.position, Velocity = rigidbody.velocity, Orientation = rigidbody.rotation }; }); }
protected override void OnUpdate() { for (int i = 0; i < data.Length; ++i) { // Need to split this out into server / client / whatever var transform = data.Transform[i]; var defaultToSet = new TransformToSet { Position = transform.Location.ToUnityVector3() + worker.Origin, Velocity = transform.Velocity.ToUnityVector3(), Orientation = transform.Rotation.ToUnityQuaternion() }; var defaultToSend = new TransformToSend { Position = transform.Location.ToUnityVector3() - worker.Origin, Velocity = transform.Velocity.ToUnityVector3(), Orientation = transform.Rotation.ToUnityQuaternion() }; var previousTransform = new DefferedUpdateTransform { Transform = transform }; 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 = transform }; var lastPosition = new LastPositionSentData { // could set this to the max time if we want to immediately send something TimeSinceLastUpdate = 0.0f, Position = data.Position[i] }; PostUpdateCommands.AddComponent(data.Entity[i], defaultToSet); PostUpdateCommands.AddComponent(data.Entity[i], defaultToSend); PostUpdateCommands.AddComponent(data.Entity[i], previousTransform); PostUpdateCommands.AddComponent(data.Entity[i], ticksSinceLastUpdate); PostUpdateCommands.AddComponent(data.Entity[i], lastPosition); PostUpdateCommands.AddComponent(data.Entity[i], lastTransform); PostUpdateCommands.AddBuffer <BufferedTransform>(data.Entity[i]); } }
private void UpdateTransformData() { var transformArray = transformGroup.GetComponentArray <UnityEngine.Transform>(); var transformToSendArray = transformGroup.GetComponentDataArray <TransformToSend>(); for (int i = 0; i < transformArray.Length; ++i) { var transform = transformArray[i]; var transformToSend = new TransformToSend { Position = transform.position, Velocity = Vector3.zero, Orientation = transform.rotation }; transformToSendArray[i] = transformToSend; } }
private void UpdateRigidbodyData() { var rigidbodyArray = rigidbodyGroup.GetComponentArray <Rigidbody>(); var transformToSendArray = rigidbodyGroup.GetComponentDataArray <TransformToSend>(); for (int i = 0; i < rigidbodyArray.Length; ++i) { var rigidbody = rigidbodyArray[i]; var transformToSend = new TransformToSend { Position = rigidbody.position, Velocity = rigidbody.velocity, Orientation = rigidbody.rotation }; transformToSendArray[i] = transformToSend; } }
private void AddCommonSendComponents(EntityCommandBuffer commandBuffer) { commandBuffer.AddComponent(entity, new GetTransformFromGameObjectTag()); var transformComponent = transformReader.Data; var defaultToSend = new TransformToSend { Position = transformComponent.Location.ToUnityVector() - world.GetExistingSystem <WorkerSystem>().Origin, Velocity = transformComponent.Velocity.ToUnityVector(), Orientation = transformComponent.Rotation.ToUnityQuaternion() }; 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); }