As a publisher I can say this, "If you were to ask if you can write in world with our settings, we would ask for a royalty (small) if you were selling."
Many other publishers I know feel the same way. A letter of intent, or query to write can move mountains, and keep you out of copywrite court. I have asked and been turned down very politely before, and at other times I was given the greenlight, as long as I made sure to reference the company/IP owner and give proper attribution. Many company sites have these terms listed in the FAQ or designated webpage.
It can get a bit dicey if you try and write for published fiction, computer games, and the like.
***Shameless plug*** We are generally easy going when it comes to rights and fan fiction/games/settings.