Unity3d Clone 50 Game objects and output JSON-formatted text

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.