"Code Optimization" Unity leaks the vacancy

Source: Internet
Author: User

1.XML:

Parse XML files using open source scripting (JS language) in the Unity Community, URL: http://dev.grumpyferret.com/unity/, packaged xmlparser.unitypackage, saved in plugins\ In the Xmlparser directory. Network address: Http://pan.baidu.com/s/1i3hCd0L

How to use:

1     //Read XML2     voidReadXML ()3     {4M_enemylist =NewList<spawndata>();5 spawndata data;6 7Xmlparser Xmlparse =NewXmlparser ();8XMLNode node =Xmlparse. Parse (m_xmldata.text);9 TenXmlNodeList nodelist = node. Getnodelist ("root>0>table"); One          for(inti =0; I < NodeList. Count; i++) A         { -data =NewSpawndata (); -Data.wave =int. Parse (node. GetValue ("root>0>table>"+ i +"> @wave")); thedata.enemyname = node. GetValue ("root>0>table>"+ i +"> @enemyname"); -Data.level =int. Parse (node. GetValue ("root>0>table>"+ i +"> @level")); -Data.wait =float. Parse (node. GetValue ("root>0>table>"+ i +"> @wait")); - m_enemylist.add (data); +         } -}

Not used. NET provides XML functionality because it makes the game more bulky, and unity does not recommend using it.

There is a file Mono.Xml.zip under the Unity4 installation directory Editor\data\documentation\html\en\uploads\main, which is a lite Xml parsing script (C # language) that is officially provided by unity.

The file is under the Unity5 installation directory Editor\data\documentation\en\uploads\main.

2.transform:

Using Transform directly in the script is equivalent to calling getcomponent<transform> (). If you need to use transform repeatedly in update (), you can mitigate performance consumption by declaring components and invoking references.

  

1  Public classMovecontrol:monobehaviour2 {3      Public floatMovespeed =10F;4     PrivateTransform thist;5 6     voidAwake ()7     {8Thist = This. Getcomponent<transform>();9     }Ten  One     voidUpdate () A     { -Thist.translate (NewVector3 (Input.getaxis ("Horizontal"), Input.getaxis ("Vertical"),0) * Time.deltatime *movespeed); -     } the}

"Code Optimization" Unity leaks the vacancy

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.