Unity Development-What you need to know about optimization recommendations

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/leonwei/article/details/18042603

Recently research u3d Development, personally think, proficient in a new technology, the fastest and best way is to look at its document, and personal habits do not like to see the information of Chinese, the original thing is the most correct, a translation come a lot of things are not so accurate. So read through the unity of the official Manuel, the last few chapters are the essence, which gives very very many official optimization advice, especially to do mobile platform development, these recommendations are very important. I refined some of the chapters behind the official Manuel Advanced and summed up some of these optimization tips:

1 is not a technology supported by every major mobile phone (that is, if you can not use it or have alternatives)

Screen effects

Dynamic pixel illumination calculations (e.g. normals)

Real-time shading

2 Optimization Recommendation 2.1 rendering

1. Do not use or use light mapping and light probes (illumination probe) without using or using less dynamic illumination.

2. Do not use normal map (or only in the main character), static objects as far as possible to render normal to the map

3. Not suitable for dense particles, use UV animations as much as possible

4. Do not use fog, use a gradient patch (refer to Shadow gun)

5. Do not use alpha–test (such as those cutout shader), use Alpha-blend instead

6. Use as few material as possible, using as few passes and render times as you do with reflections, shadows

7. If necessary, use per-layer cull distances,camera.layerculldistances

8. Use only those presets in the mobile group shader

9. Using occlusion culling

11. Objects in the distance are drawn on the Skybox

12. Use Drawcall batching:

For adjacent dynamic objects: If you use the same shader, merge the texture

For static objects, batching requirements are high, see Unity manual>advanced>optimizing Graphics Performance>draw Call batching

Specification limit

1. Use only one skinned mesh renderer per model

2. Do not exceed 3 material per mesh

3. Do not exceed 30 bone count

4. The number of faces within 1500 will be good efficiency

2.2 Physics

1. Real physical (rigid body) is consumed, not easy to use, try to use your own code to imitate fake physics

2. Do not use real physical collisions and rigid bodies for projectiles, and use your own code to handle

3. Do not use mesh collider

4. Increase the Fixedtimestep (real physical frame rate) in Edit->project setting->time to reduce CPU loss

2.3 Scripting

1. Try not to dynamically instantiate and destroy object, using the object pool

2. Try not to do complex calculations in the update function, and if necessary, you can calculate the interval of n frames

3. Do not dynamically generate strings, such as Debug.Log ("Boo" + "hoo"), and try to create these string resources in advance.

4.cache something, in the update, try to avoid search, such as Gameobject.findwithtag (""), getcomponent such a call, can be stored in start in advance

5. Minimize the function call stack with x = (x > 0? x:-X), instead of × = Mathf.abs (x)

6. The following code is a few GC "nightmares"

The addition of string, which frequently requests memory and releases, causes the GC to be frequent, using System.Text.StringBuilder instead

function Concatexample (intarray:int[]) {

var line = intarray[0]. ToString ();

for (i = 1; i < intarray.length; i++) {

Line + = "," + intarray[i]. ToString ();

}

return line;

}

In the function of the dynamic new array, it is best to change an array, pass into the function

function Randomlist (numelements:int) {
var result = new Float[numelements];
for (i = 0; i < numelements; i++) {
Result[i] = Random.value;
}
return result;
}

2.4 Shader writing

1. Data type

fixed / lowp -for colors, lighting information and normals,

half / mediump -for texture UV coordinates,

float / highp -Avoid in pixel shaders, fine to use with vertex shader for position calculations.

2. Less-used functions:pow,sin,cos, etc.

2.4 GUI

1. Do not use the built-in onguii function to process the GUI, using other schemes such as Ngui

3. Format

1. Map compression format: Use Pvrtc,android on iOS as much as possible

Unity Development-What you need to know about optimization recommendations

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.