Unity interview summary-optimization

1. What should I pay attention to when optimizing other people's systems?

  • Make changes based on other people's systems as much as possible, and don't move other people's code drastically.

2. How to reduce drawCall?

  • Drawcall: The CPU prepares the rendering object, loads the rendering object from the hard disk to the memory, and then loads it from the memory to the flash memory, sets the rendering state, material, texture, shader, etc. of each object, and then the CPU sends the DrawCall command to the GPU and renders The primitives are passed to the GPU. Too much DrawCall causes a large amount of CPU calculations, which affects efficiency
  • Only objects of the same material can be batch processed, and materials and objects can be reused in the program as much as possible.
  • If dynamic objects share the same material, unity will automatically perform batch processing.
  • For complex static scenes, occlusion culling algorithms can be used.
  • Pack the gallery. Closely related pictures are packed together, and the atlas should not be too large.
  • After the special effect is played, if active is not set to false, the drawcall will continue to be occupied, and it must be cleared in time.

3. How to lower DrawCall on UI?

  • Minimize the use of masks. The ui inside and outside the mask cannot be rendered at one time, if you don’t need it, you don’t need to, or use a picture with channels instead of the mask function of the mask
  • The specification of atlas collation. Batch processing is based on the atlas. Put an atlas for commonly used pictures, an atlas for independent interfaces, etc.
  • ui placement reduces crossover. img -img-text two drawcalls image-text-image three drawcalls
  • Dynamic and static separation
  • Minimize the use of raycasttarget
  • richtext

5. The reason why the phone is hot? How to deal with it?

  • The cpu calculation is too high.
  • Phone configuration is not working
  • Many background programs
  • Long running time
  • The signal is weak, the mobile phone automatically increases the transmit power

6. How GC works, how to reduce GC?

  • Don't explicitly call system.gc(); it will trigger the main GC and increase the gc frequency
  • Reduce the use of temporary objects
  • Frequent string changes use stringbuilder
  • Reduce the use of static variables

7. Unity optimization.

Guess you like

Origin blog.csdn.net/wang_lvril/article/details/109543238