Unity3d Optimization Summary

Source: Internet
Author: User
Tags mathematical functions

Welcome to Unity Learning,Unity Training,UnityEnterprise TrainingEducation Area, there are manyu3d Resources,u3d Training Video,u3d Tutorials,U3d Frequently Asked questions,u3d Project Source code, the "Dog Planing Learning Network" Unity's Ultimate Academy, dedicated to building the industryUnity3dTraining, learning the first brand.
1. When using arrays or ArrayList objects, you should pay attention to
   [CSharp]View Plaincopy
Length=myarray.length;
for (inti=0;ilength;i++)
{
}
Avoid
   [CSharp]View Plaincopy
for (inti=0;imyarray.length;i++)
{
}
2, if it is not necessary to process each frame, it can be processed every few frames
   [CSharp]View Plaincopy
Voidupdate () {if (time.framecount%6==0) {dosomething ()}}
3, timed repeat call can be implemented using the Invokerepeating function, for example, 0.5 seconds after the start of every 1 seconds to execute the dosomething function:
   [CSharp]View Plaincopy
Voidstart ()
{
Invokerepeating ("DoSomething", 0.5f,1.0f);
}
4, less use of temporary variables, especially in the update Ongui, such as real-time call functions.
   [CSharp]View Plaincopy
Voidupdate ()
{
Vector3pos;
Pos=transform.position;
}
Can be changed to:
   [CSharp]View Plaincopy
Privatevector3pos;
Voidupdate ()
{
Pos=transform.position;
}
5, the active garbage collection
   [CSharp]View Plaincopy
Voidupdate ()
{
if (time.framecount%50==0)
{
System.GC.Collection ();
}
}
6, optimization of mathematical operations, to avoid the use of float, and use of int, especially in mobile games, as little as possible with complex mathematical functions, such as Sin,cos functions. Divide/Multiply, for example: Use x*0.5f instead of x/2.0f.
7. Compressed Mesh
After importing a 3D model, it is a good idea to open meshcompression without affecting the display effect. Off,low,medium,high These options can be selected as appropriate. It is best to use one material for a single mesh.
8. Minimize Tris and Drawcalls during operation
When previewing, you can open stats to see the overhead of drawing rendering. Pay particular attention to the two parameters Tris and Drawcalls. In general, to achieve: Tris remain below 7.5k, Drawcalls remain below 35.
9. Avoid a lot of built-in mesh with Unity's own sphere
Unity built-in mesh, the number of polygons is larger, if the object is not required to be particularly smooth, can be imported into other simple 3D model instead.
10, if possible, will gameobject unnecessary script disable off. If you have a big scene in your game and the enemy's location is thousands of meters unexpectedly, this is where you can disable your enemy AI scripts until they are close to the camera. A good way to turn on or off Gameobject is to use setactiverecursively (false), and the spherical or box-type collider is set to trigger.
11. Delete the empty Update method. When you create a new script from the assets directory, the script includes an Update method that deletes it when you are not using it.
12. Refer to the most logical component of a game object. Some people may write somegameobject.transform,gameobject.rigidbody.transform.gameobject.rigidbody.transform, but do some unnecessary work, you can in the first place to lead Use it, like this:
Privatetransform Mytrans;
void Start ()
{
Mytrans=transform;
}
13, Synergy is a good way. You can use a synergistic program instead of a method that does not have to be executed per frame. (There are also invokerepeating methods that are a good alternative to update).
14, try not to update or fixedupdate using the search method (such as Gameobject.find ()), you can get it in the Start method as before.
15, do not use methods such as SendMessage, he is 100 times times slower than the direct call method, you can directly invoke or through the C # Delegate to achieve.
16, when using JavaScript or boo language, you'd better determine the type of the variable, do not use the dynamic type, which will reduce the efficiency, you can use #pragmastrict at the beginning of the script to check, so that when you compile your game there will be no inexplicable error.


For more information, please visit the "Dog Planing Learning Network" Unity Ultimate Academy Http://unity.gopedu.com


  

Unity3d Optimization Summary

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.