Пример #1
0
        protected override void OnUpdate()
        {
            var buffer = m_EntityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter();

            Entities
            .ForEach(
                (
                    Entity entity,
                    int entityInQueryIndex,
                    ref LocalToWorld localToWorld,
                    ref AircraftHangar hangar,
                    ref Team team,
                    ref Cooldown cooldown
                ) =>
            {
                if (!cooldown.IsReady())
                {
                    return;
                }

                cooldown.Timer = cooldown.Duration;

                var ship = buffer.Instantiate(entityInQueryIndex, hangar.Archetype);
                buffer.SetComponent(entityInQueryIndex, ship, new Translation {
                    Value = localToWorld.Position - new float3(0f, -0.1f, 0f)
                });
                buffer.SetComponent(entityInQueryIndex, ship, new Rotation {
                    Value = new quaternion(localToWorld.Value)
                });
                buffer.SetComponent(entityInQueryIndex, ship, team);
                buffer.AddComponent(entityInQueryIndex, ship, new Escort {
                    Target = entity
                });
            })
            .ScheduleParallel();

            m_EntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
        }