ECS Tags Tutorial – https://youtu.be/buRowWj1aW4

Home   »   ECS Tags Tutorial – https://youtu.be/buRowWj1aW4

using Unity.Entities;
using Unity.Transforms;

namespace TMG.Tags
{
    public class MoveRedCubes : SystemBase
    {
        private EndSimulationEntityCommandBufferSystem _endSimulationEntityCommandBufferSystem;

        protected override void OnCreate()
        {
            _endSimulationEntityCommandBufferSystem = World.GetOrCreateSystem();
        }

        protected override void OnUpdate()
        {
            var ecb = _endSimulationEntityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter();
            var deltaTime = Time.DeltaTime;
            
            Entities
                .WithAll()
                .ForEach((Entity e, int entityInQueryIndex, ref Translation translation) =>
                {
                    translation.Value.y += 0.25f * deltaTime;
                    ecb.SetComponent(entityInQueryIndex, e, translation);
                }).ScheduleParallel();
            
            _endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(this.Dependency);
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *