Beispiel #1
0
        protected override void OnUpdate()
        {
            var buffer = m_entityBufferSystem.CreateCommandBuffer().AsParallelWriter();

            Entities
            .ForEach((
                         Entity attacker,
                         int entityInQueryIndex,
                         in Target target,
                         in LocalToWorld worldTransform,
                         in TargettedTool tool,
                         in ProjectileWeapon weapon,
                         in Team team
                         ) =>
            {
                if (!tool.Firing)
                {
                    return;
                }

                // Create the projectile
                Entity projectile = buffer.Instantiate(entityInQueryIndex, weapon.Projectile);
                buffer.SetComponent(entityInQueryIndex, projectile, target);
                buffer.SetComponent(entityInQueryIndex, projectile, new Translation {
                    Value = worldTransform.Position
                });
                buffer.SetComponent(entityInQueryIndex, projectile, new Rotation {
                    Value = quaternion.LookRotation(worldTransform.Forward, new float3(0f, 1f, 0f))
                });
                buffer.SetComponent(entityInQueryIndex, projectile, new Instigator()
                {
                    Value = attacker
                });
                buffer.AddComponent(entityInQueryIndex, projectile, team);
            })
        protected override void OnUpdate()
        {
            var buffer     = m_entityBufferSystem.CreateCommandBuffer().AsParallelWriter();
            var transforms = GetComponentDataFromEntity <LocalToWorld>(true);

            Entities.ForEach(
                (
                    Entity attacker,
                    int entityInQueryIndex,
                    in Target target,
                    in LocalToWorld localToWorld,
                    in TargettedTool tool,
                    in InstantEffect effect
                ) =>
            {
                if (!tool.Firing)
                {
                    return;
                }

                if (target.Value == Entity.Null)
                {
                    return;
                }

                // Create the effect
                Entity attack = buffer.Instantiate(entityInQueryIndex, effect.AttackTemplate);
                buffer.AddComponent(entityInQueryIndex, attack, Attack.New(effect.Accuracy));
                buffer.AddComponent(entityInQueryIndex, attack, target);
                buffer.AddComponent(entityInQueryIndex, attack, new Instigator()
                {
                    Value = attacker
                });
                buffer.AddComponent(entityInQueryIndex, attack, new EffectSourceLocation {
                    Value = localToWorld.Position
                });
                buffer.AddComponent(entityInQueryIndex, attack, new Effectiveness {
                    Value = 1f
                });
                buffer.AddComponent(entityInQueryIndex, attack, new SourceLocation {
                    Position = localToWorld.Position
                });
                if (transforms.HasComponent(target.Value))
                {
                    buffer.AddComponent(entityInQueryIndex, attack, new HitLocation {
                        Position = transforms[target.Value].Position
                    });
                }
            }
Beispiel #3
0
        protected override void OnUpdate()
        {
            var   ltwData        = GetComponentDataFromEntity <LocalToWorld>(true);
            var   sizeRadiusData = GetComponentDataFromEntity <SizeRadius>(true);
            float dT             = UnityEngine.Time.fixedDeltaTime;
            var   commands       = CommandBufferSystem.CreateCommandBuffer().AsParallelWriter();

            Entities
            .WithReadOnly(sizeRadiusData)
            .WithReadOnly(ltwData)
            .ForEach((
                         Entity e, int entityInQueryIndex,
                         ref Projectile projectile,
                         in Target target,
                         in LocalToWorld transform,
                         in Speed speed,
                         in TurnSpeed turnSpeed
                         ) =>
            {
                if (!ltwData.HasComponent(target.Value))
                {
                    return;     // Target does not exist?
                }
                var tPos  = ltwData[target.Value].Position;
                var delta = (tPos - transform.Position);

                var projectileDistance = speed.Value * dT;

                float radius = (sizeRadiusData.HasComponent(target.Value)) ? sizeRadiusData[target.Value].Value : 0f;

                // If target out of range, return
                if (math.length(delta) - radius > projectileDistance)
                {
                    return;
                }

                // Projectile has reached the target.
                projectile.ReachedTarget = true;

                commands.AddComponent(entityInQueryIndex, e, new Delete());
                var effect = commands.Instantiate(entityInQueryIndex, projectile.AttackEntity);
                commands.AddComponent(entityInQueryIndex, effect, target);
                commands.AddComponent(entityInQueryIndex, effect, new Instigator {
                    Value = e
                });
            })
Beispiel #4
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);
        }