#if MODULE_ENTITIES using Unity.Burst; using Unity.Collections; using Unity.Entities; using Unity.Mathematics; using Unity.Transforms; using UnityEngine.Jobs; namespace Pathfinding.ECS { [BurstCompile] struct JobSyncEntitiesToTransforms : IJobParallelForTransform { [ReadOnly] public NativeArray entities; [ReadOnly] public ComponentLookup entityPositions; [ReadOnly] public ComponentLookup movementState; [ReadOnly] public ComponentLookup syncPositionWithTransform; [ReadOnly] public ComponentLookup syncRotationWithTransform; [ReadOnly] public ComponentLookup orientationYAxisForward; public void Execute (int index, TransformAccess transform) { var entity = entities[index]; if (!entityPositions.HasComponent(entity)) return; float3 offset = float3.zero; if (movementState.TryGetComponent(entity, out var ms)) { offset = ms.positionOffset; } var tr = entityPositions.GetRefRO(entity); if (syncPositionWithTransform.HasComponent(entity)) transform.position = tr.ValueRO.Position + offset; if (syncRotationWithTransform.HasComponent(entity)) { if (orientationYAxisForward.HasComponent(entity)) { // Y axis forward transform.rotation = math.mul(tr.ValueRO.Rotation, SyncTransformsToEntitiesSystem.ZAxisForwardToYAxisForward); } else { // Z axis forward transform.rotation = tr.ValueRO.Rotation; } } } } } #endif