当前位置:网站首页>Unity performance optimization scheme arrangement
Unity performance optimization scheme arrangement
2022-07-28 20:36:00 【Xiao language is scattered】
Unity Performance optimization scheme arrangement
Inclusion size optimization
- Android : Update the compression format of opacity map to ETC 4bit, because android Mobile phones in the market GPU There are many kinds of ,
Every family's GPU Supports different compression formats , But they are compatible ETC Format , There are transparent channels ETC2 8bit - Map Compression : Require art to use 16 Bit mapping , We choose rgba16 position , Compress
- For transparent maps , We can only choose RGBA 16bit perhaps RGBA 32bit
CPU performance optimization
Reduce FPS, stay ProjectSetting-> Quality Medium VSync Count Parameters will affect your FPS,EveryVBlank amount to FPS=60,EverySecondVBlank = 30; Neither of these situations is consistent with the game FPS Words , We need to manually adjust FPS, First, turn off the function of vertical synchronization , Then in the code Awake Set manually in the method FPS(Application.targetFrameRate = 45;)
Reduce FPS The benefits of :
1) Save electricity , Reduce the heating of mobile phones ;
2) Can stabilize the game FPS, Reduce the occurrence of jamming .When we set up FPS after , Adjust again Fixed timestep This parameter ,
This parameter is in ProjectSetting->Time in , The purpose is to reduce the number of physical calculations , To improve game performance .Use... As little as possible Update LateUpdate FixedUpdate, This can also improve performance and save power .
Use more events ( His writing , perhaps C# Event delegation in ).For the vertices of the model (<500), Number of faces (300-1500), Map size (512*512) To standardize ( It was formulated when the project was approved )
Number of light sources : Suggest 1 A directional light , The more light sources ,drawcall The more
Try to mark non moving objects Static label ,Unity At run time static Automatic optimization of objects , Therefore, non operating entities should be checked as much as possible static label .
OnBecameInvisible() When it becomes invisible and OnBecameVisible() When it becomes visible .
Take this 2 The premise for a function to work is , The GameObject The binding MeshRender Components .
Memory optimization
- Be sure to delete the default methods that are empty or unnecessary in the script ;
- Use only in one script OnGUI Method ;
- To avoid the OnGUI Of variables in 、 Method to update 、 assignment , Output variables are recommended in Update Inside ;
- For variables frequently used in the same script, it is recommended to declare them as global variables , Variables or methods frequently called between scripts are recommended to be declared as global static variables or methods ;
- Don't get components frequently , Declare it as a global variable ;
- Array 、 Collection elements are preferred Array, The second is List;
- Scripts are disabled when not in use , Enable when necessary ;
- have access to Ray Instead of OnMouseXXX Class method ;
- Need to hide / Show or instantiate objects that switch back and forth , Try not to use SetActiveRecursively or active, Instead, use the method of moving the object far out of the camera range and back to its original position ;
- Minimize the use of modular operations and division operations , such as a/5f, It must be written as a*0.2f.
- For variables or methods that are not often called or changed, it is recommended to use Coroutines & Yield;
- Try to use integer numbers , because iPhone The floating-point calculation ability of is very poor ;
- Do not use native GUI Method ;
- Do not instantiate (Instantiate) object , Build the object pool in advance , And use Translate“ Generate ” object ;
Model optimization
- Merge shaders with the same map , Merge... Using the same shader Mesh;
- There is only one character map and shader , If more than one is necessary, separate the model into multiple parts ;
- Don't use too much of the skeletal system ;
- When using multiple roles , Separate the animation separately ;
- Use layer distance to control the display distance of the model ;
- Shadow actually contains two aspects: darkness and shadow , It is recommended to bake out the shadow effect when using real-time shadow , Don't use lights to adjust the darkness .
- Use fewer pixel lights and those that use pixel lights Shader;
- If hard shadows can solve the problem, don't use soft shadows , And use low resolution shadows that do not affect the effect ;
- Real time shadows are performance intensive , Minimize the distance of shadows ;
- If allowed, use linear fog in large scenes , This makes distant objects or shadows imperceptible , Therefore, the performance can be improved by reducing the distance between the camera and the shadow ;
- Use smooth groups to minimize the number of faces of the model ;
- If there are no lights or objects moving in the project, do not use real-time lights ;
- Surface of the water 、 Mirror and other real-time reflection / The effect of refraction is placed separately Water In the layer , And according to the real-time reflection / Adjust the range of refraction ;
- Collision has little effect on efficiency , But collision is still recommended Box、Sphere Colliding body ;
- Try to consider the use of building material balls Substance;
- Try to reflect all real-time / refraction ( Like water 、 Mirror 、 The floor and so on ) All assembled into one face ;
- False reflexes / Refraction does not need to use too large a resolution , commonly 6464 Can , No more than 256256;
- Shaders that need to be changed , It is recommended to instantiate one , Instead of using public shaders ;
- Place objects that do not require rays or collision events in IgnoreRaycast Layers ;
- Place the water surface or similar effect on Water Layers
- Place the object of the transparent channel in TransparentFX Layers ;
- Develop good labels (Tags)、 level (Hieratchy) And layers (Layer) Methodical habits , Put different objects on different labels or layers , The effective combination of the three will be very convenient by name 、 Categories and attributes to find ;
- adopt Stats and Profile View the aspects or objects that have the greatest impact on efficiency , Or use the method of disabling some models to see where the problem is ;
- Use occlusion culling (Occlusion Culling) Deal with big scenes , A more primitive class LOD( Multi level detail ) technology , And be able to “ Division ” A model as a whole .
Other
- If lights and pixel lights are not used in the scene , Don't use normal mapping , Because the normal effect is only when there is a light source (Direct Light/Point Light/Angle Light/Pixel Light) It works only when .
边栏推荐
- Product manager interview | innovation and background of the fifth generation verification code
- js图片悬挂样式照片墙js特效
- Mysql报错:Specified key was too long; max key length is 767 bytes
- Character device drive structure
- Introduction to seven kinds of polling (practice link attached)
- 根据openGauss/MogDB的lwtid查看线程堆栈。
- Simple use of robobrowser
- 卡通js射击小游戏源码
- MySQL batch update data
- DSACTF7月re
猜你喜欢
随机推荐
MySQL error: specified key was too long; max key length is 767 bytes
Redis review summary
Linux Installation MySQL (pit filling version)
太空射击第14课: 玩家生命
Networkx common operations summary (for personal use)
Usage Summary of thymeleaf
关于正则的两道笔试面试题
[pytorch] LSTM neural network
h5微信射击小游戏源码
Configure Windows Server + install MySQL database on the server + Remote Access database
Using typedef in C language to change the name of data type
Common commands of raspberry pie
Vivado design single cycle CPU
进制及数的表示 2
Leetcode-297 serialization and deserialization of binary tree
Character device drive structure
3D激光SLAM:LeGO-LOAM论文解读---简介部分
MySQL startup error 1607 unexpected process termination
产品力大幅提升 新款福特探险者发布
【pytorch】LSTM神经网络









