Esempio n. 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);
            }
 protected override void OnCreate()
 {
     Buffer = World.GetOrCreateSystem <PostAttackEntityBuffer>();
 }