using Unity.Burst; using Unity.Collections; using Unity.Entities; using Unity.Transforms; namespace GarmentButton.TransformSync { public partial struct TransformSyncSystem : ISystem { [BurstCompile] public void OnCreate(ref SystemState state) { state.RequireForUpdate(); } [BurstCompile] public void OnUpdate(ref SystemState state) { state.Dependency = new TransformSyncJob() { LocalTransformLookup = SystemAPI.GetComponentLookup(true), }.Schedule(state.Dependency); } public partial struct TransformSyncJob : IJobEntity { [ReadOnly] public ComponentLookup LocalTransformLookup; public void Execute(in SyncTransform syncFrom, ref LocalTransform syncTo) { var localTransform = LocalTransformLookup.GetRefRO(syncFrom.Value); syncTo.Position = localTransform.ValueRO.Position; syncTo.Rotation = localTransform.ValueRO.Rotation; } } } }