Beispiel #1
0
        protected override void OnUpdate()
        {
            var random = new Unity.Mathematics.Random((uint)Random.Range(1, 100000));
            var buffer = PostAttackEntityBuffer.CreateCommandBuffer().AsParallelWriter();

            Dependency = Entities.ForEach(
                (Entity e, int entityInQueryIndex, in Attack attack, in Instigator attacker, in Target target, in BeamEffectStyle style, in HitLocation hitLoc, in SourceLocation sourceLoc) =>
            {
                var laserEffect = new BeamEffect()
                {
                    start    = sourceLoc.Position,
                    end      = hitLoc.Position,
                    lifetime = 0.2f
                };

                if (attack.Result == Attack.eResult.Miss)
                {
                    var delta       = new Unity.Mathematics.float3(random.NextFloat() - 0.5f, 0f, random.NextFloat() - 0.5f);
                    laserEffect.end = laserEffect.end + 6f * delta;
                }

                Entity effect = buffer.CreateEntity(entityInQueryIndex);
                buffer.AddComponent(entityInQueryIndex, effect, laserEffect);
                buffer.AddComponent(entityInQueryIndex, effect, style);
                buffer.AddComponent(entityInQueryIndex, effect, attacker);
                buffer.AddComponent(entityInQueryIndex, effect, target);
            }
Beispiel #2
0
        protected override void OnUpdate()
        {
            uint seed     = (uint)UnityEngine.Random.Range(1, 100000);
            var  commands = _commandBufferSystem.CreateCommandBuffer().AsParallelWriter();

            Entities
            .WithName("CreateBeamEffects")
            .ForEach((
                         Entity e,
                         int entityInQueryIndex,
                         in Attack attack,
                         in Instigator attacker,
                         in Target target,
                         in BeamEffectStyle style,
                         in HitLocation hitLoc,
                         in SourceLocation sourceLoc
                         ) =>
            {
                var laserEffect = new BeamEffect()
                {
                    start    = sourceLoc.Position,
                    end      = hitLoc.Position,
                    lifetime = 0.2f
                };

                if (attack.Result == Attack.eResult.Miss)
                {
                    var rnd         = new Random(seed + (uint)(entityInQueryIndex * 1000));
                    var delta       = new float3(rnd.NextFloat() - 0.5f, 0f, rnd.NextFloat() - 0.5f);
                    laserEffect.end = laserEffect.end + 6f * delta;
                }

                Entity effect = commands.CreateEntity(entityInQueryIndex);
                commands.AddComponent(entityInQueryIndex, effect, laserEffect);
                commands.AddComponent(entityInQueryIndex, effect, style);
                commands.AddComponent(entityInQueryIndex, effect, attacker);
                commands.AddComponent(entityInQueryIndex, effect, target);
            })