protected override void OnUpdate() { float deltaTime = Time.DeltaTime; EntityCommandBuffer.ParallelWriter commandBuffer = entityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter(); Entities .WithAll <GooBomberData, Translation>() .WithBurst(FloatMode.Default, FloatPrecision.Standard, true) .ForEach((int entityInQueryIndex, ref GooBomberData gooBomberData, in Translation translation) => { gooBomberData.timeSinceLastDrop += deltaTime; if (gooBomberData.timeSinceLastDrop > gooBomberData.cooldown) { gooBomberData.timeSinceLastDrop -= gooBomberData.cooldown; Entity bomb = commandBuffer.Instantiate(entityInQueryIndex, gooBomberData.bombEntityTemplate); Translation bombTranslation = new Translation(); bombTranslation.Value = new float3 { x = translation.Value.x, y = translation.Value.y, z = translation.Value.z }; GooBombData bombData = new GooBombData { bombSize = gooBomberData.bombSize }; commandBuffer.SetComponent <Translation>(entityInQueryIndex, bomb, bombTranslation); commandBuffer.SetComponent <GooBombData>(entityInQueryIndex, bomb, bombData); } }).ScheduleParallel(); entityCommandBufferSystem.AddJobHandleForProducer(Dependency); }
public void Execute(CollisionEvent collisionEvent) { Entity entityA = collisionEvent.EntityA; Entity entityB = collisionEvent.EntityB; bool isBodyAProjectile = innerProjectileGroup.HasComponent(entityA); bool isBodyBProjectile = innerProjectileGroup.HasComponent(entityB); bool isBodyACube = innerCubeGroup.HasComponent(entityA); bool isBodyBCube = innerCubeGroup.HasComponent(entityB); Entity projectile, cube; if (isBodyAProjectile && isBodyBCube) { projectile = entityA; cube = entityB; } else if (isBodyBProjectile && isBodyACube) { projectile = entityB; cube = entityA; } else { bool isBodyAGround = innerGroundGroup.HasComponent(entityA); bool isBodyBGround = innerGroundGroup.HasComponent(entityB); bool isBodyABomb = innerBombGroup.HasComponent(entityA); bool isBodyBBomb = innerBombGroup.HasComponent(entityB); Entity bomb; if (isBodyAGround && isBodyBBomb) { bomb = entityB; } else if (isBodyBGround && isBodyABomb) { bomb = entityA; } else { return; } GooBombData bombData = innerBombGroup[bomb]; bombData.hitGround = true; innerBombGroup[bomb] = bombData; return; } ProjectileData projectileData = innerProjectileGroup[projectile]; PurpleGooCubeData cubeData = innerCubeGroup[cube]; if (projectileData.hitsLeft > 0 && cubeData.pendingDamage < cubeData.height) { cubeData.pendingDamage += 5; innerCubeGroup[cube] = cubeData; projectileData.hitsLeft -= 1; innerProjectileGroup[projectile] = projectileData; } }