UV-ing a sphere procedurally

So, I am trying to learn more about how to UV something procedurally. The first toy problem I’m trying to solve is how do you UV the default UV on the default Unity sphere.

From left to right - default, planar, and Wikipedia spherical

    for(var i=0;i<uvs.Length;i++){
    	var r = Mathf.Sqrt(vertices.x*vertices.x + vertices.y*vertices.y + vertices_.z*vertices*.z);*_
 	uvs = Vector2(vertices_.z/r,vertices*.x/r);*_
 _*} 	*_

If I am conveying the UV coordinates right, it’s not planar or the Wikipedia sphere UV (code snippet above)…
![alt text][1]
[1]: http://posterous.com/getfile/files.posterous.com/ina-zntvj/ghCW67nwvmMm0TnyFxPaTiLxC4YunGcF4jSH4SwFltVcEgBP4oYJdNCdBRxu/Screen_shot_2011-05-28_at_4.43.png

It’s more like something in the line of:

uvs <em>= Vector2(Mathf.Atan2(vertices<em>.z,vertices_.x)/Mathf.Pi/2,Mathf.Acos(vertices*.y/r)/Mathf.Pi);*_</em></em>