Http://wenku.baidu.com/link?url=tl8q_ Aj1n-u267xkktszisaw6jkj1woh4cjkdur1awezllsav7p0r7cawxxsydvxnf6mjkzaxr15xix3tkl8xcrmcxtgkpe2p3fsdnvfedg
usingUnityengine;usingSystem.Collections;usingLitjson;usingSystem.Text;usingSystem.IO; Public classprefabs:monobehaviour{ PublicGameobject Cube; Publicgameobject[] Cubeprefabs; Public inti; Public intj =0; //Use this for initialization voidStart () {//cubeprefabs = new GAMEOBJECT[50];gamecopy (); } //Update is called once per frame voidUpdate () {}voidgamecopy () {Cubeprefabs=Newgameobject[ -]; stringfilepath = Application.datapath +@"/streamingassets/json.txt"; FileInfo T=NewFileInfo (filepath); if(!file.exists (filepath)) {file.delete (filepath); } StreamWriter SW=T.createtext (); for(i =0; I < -; i++) {Cubeprefabs[j]= Instantiate (Cube,NewVector3 (i *1.5f,0,0), quaternion.identity) asGameobject; //Debug.Log ("Position" + cubeprefabs[j].transform.position); //Debug.Log ("Rotation" +cubeprefabs[j].transform.rotation); //Debug.Log ("scale" + Cubeprefabs[j].transform.localscale);J + +; } foreach(Gameobject objinchcubeprefabs) {StringBuilder SB=NewStringBuilder (); Jsonwriter writer=NewJsonwriter (SB); Writer. Writeobjectstart (); Writer. Writepropertyname ("name"); Writer. Write (Obj.name); Writer. Writepropertyname ("Position"); Writer. Writearraystart (); Writer. Writeobjectstart (); Writer. Writepropertyname ("X"); Writer. Write (obj.transform.position.x); Writer. Writepropertyname ("Y"); Writer. Write (OBJ.TRANSFORM.POSITION.Y); Writer. Writepropertyname ("Z"); Writer. Write (OBJ.TRANSFORM.POSITION.Z); Writer. Writeobjectend (); Writer. Writearrayend (); Writer. Writepropertyname ("Rotation"); Writer. Writearraystart (); Writer. Writeobjectstart (); Writer. Writepropertyname ("X"); Writer. Write (obj.transform.rotation.x); Writer. Writepropertyname ("Y"); writer. Write (OBJ.TRANSFORM.ROTATION.Y); Writer. Writepropertyname ("Z"); Writer. Write (OBJ.TRANSFORM.ROTATION.Z); Writer. Writeobjectend (); Writer. Writearrayend (); Writer. Writepropertyname (" Scale"); Writer. Writearraystart (); Writer. Writeobjectstart (); Writer. Writepropertyname ("X"); Writer. Write (obj.transform.localscale.x); Writer. Writepropertyname ("Y"); Writer. Write (OBJ.TRANSFORM.LOCALSCALE.Y); Writer. Writepropertyname ("Z"); Writer. Write (OBJ.TRANSFORM.LOCALSCALE.Z); Writer. Writeobjectend (); Writer. Writearrayend (); Writer. Writeobjectend (); Debug.Log (SB); Sw. WriteLine (sb.) ToString ()); } SW. Close (); Sw. Dispose (); }
Unity3d Clone 50 Game objects and output JSON-formatted text