Protfolio-Emanuel-Polsky / Assets / _Project / Code / TransfromSync / TransformSyncSystem.cs
TransformSyncSystem.cs
Raw
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<SyncTransform>();
        }

        [BurstCompile]
        public void OnUpdate(ref SystemState state)
        {

            state.Dependency = new TransformSyncJob()
            {
                LocalTransformLookup = SystemAPI.GetComponentLookup<LocalTransform>(true),
            }.Schedule(state.Dependency);
        }

        public partial struct TransformSyncJob : IJobEntity
        {
            [ReadOnly] public ComponentLookup<LocalTransform> 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;
                
            }
        }
    }
}