The ecology of evolutionary transitions to multicellularity