Unity Manual


  • 首页

  • 分类

  • 公益404

  • 搜索

Android Manifest

发表于 2018-01-11 | 更新于 2018-01-11 | 分类于 Platform-specific , Android , Android Manifest

网址:Android Manifest

How Unity produces the Android Manifest

  1. 使用主 Manifest
  2. 找到所有插件的 Mainifest
  3. 使用 Google’s manifmerger class 来合并
  4. Unity 根据设置修改 Manifest

Overriding the Android Manifest

  • Assets/Plugins/Android/AndroidManifest.xml 可以在这里放进一个 Manifest 代替 Unity 的那个
  • Unity 仅支持 launchMode - singleTask

Special optimizations

发表于 2017-07-29 | 更新于 2017-07-29 | 分类于 Best practice guides , Understanding optimization in Unity , Special optimizations

网址:Special optimizations

Multidimensional vs. jagged arrays

  • 使用数组的数组代替多维数组

Particle System pooling

  • 粒子很占内存,所以可以的话尽量通过配置表共用一种粒子来做池

Update managers

  • 减少 Update,尽可能在调用前做判断跳过

Using C# delegates in an update manager

  • C# deleagate 每次 add 和 remove 都会触发深度拷贝,因此考虑用别的类型代替这些操作

Loading thread control

  • 可以单独设置线程的优先度来优化效率

Mass object movement & CullingGroups

  • 优化不显示的物体

Reducing method call overhead

  • for 里面的赋值放到外面

Trivial properties

  • 固定属性值的访问,改为静态,或者只在第一次使用的时候进行计算

General Optimizations

发表于 2017-07-29 | 更新于 2017-07-29 | 分类于 Best practice guides , Understanding optimization in Unity , General Optimizations

网址:General Optimizations

Address Properties by ID

  • 使用 Hash 代替 string 作为索引

Use non-allocating physics APIs

  • 使用 non-allocating 接口

Transform manipulation

  • Transform 的改变会引起 OnTransformChanged,合并或者尽量减少修改

Vector and quaternion math and order of operations

  • 由于类型转换的原因,尽量先计算简单的类型

Built-In ColorUtility

  • 使用 Unity 内置的这个颜色转换接口

Find and FindObjectOfType

  • 减少调用

Camera locators

Internally, Unity’s Camera.main property calls Object.FindObjectWithTag, a specialized variant of Object.FindObject. Accessing this property is no more efficient than a call to Object.FindObjectOfType. If code must address the main camera, it is strongly recommended to do one of two things:

  • Access Camera.main in a Start orOnEnable callback and cache the resulting reference.
  • Construct a Camera Manager class that can provide or inject a reference to the active camera.

Debug code & the [conditional] attribute

  • 懒人谁会用啊

Understanding the managed heap

发表于 2017-07-29 | 更新于 2017-07-29 | 分类于 Best practice guides , Understanding optimization in Unity , Understanding the managed heap

网址:Understanding the managed heap

Technical details: how the managed heap operates and why it expands

  • 每次 GC 会移动内存块,没回收的移动到一块,使其紧密
  • 大内存占用的不移动,因为移动消耗巨大

Key problems with the heap

  • 堆内存只增不减

Basic memory conservation

Collection and array reuse

  • 重复利用数组,减少浪费

Closures and anonymous methods

  • 减少匿名函数的使用,特别是闭包

Anonymous methods under IL2CPP

  • Prefer coding styles that do not require passing methods as arguments.
  • When unavoidable, prefer anonymous methods over predefined methods.
  • Avoid closures, regardless of scripting backend.

Boxing

Dictionaries and enums

  • 定义一个类实现 IEqualityComparer

Empty array reuse

  • 重复利用空数组

Asset auditing

发表于 2017-07-28 | 更新于 2017-07-28 | 分类于 Best practice guides , Understanding optimization in Unity , Asset auditing

网址:Asset auditing

Common Asset rules

Textures

Disable the read/write enabled flag

  • 默认是关闭的
  • 一般需要操控 texture 的 pixel 的时候需要使用到

Disable Mipmaps if possible

  • 关掉大概省3分1内存
  • 对于那些会修改 Z-depth 的,关闭会印象 GPU 采集 Texture
  • UI 一般不需要开启

Compress all Textures

  • 如果 Texture Format 在对应平台上无法正常使用,Unity 会解压出来,即耗 CPU 又耗 GPU

Enforce sensible Texture size limits

  • 手机一般 1024 图集,512 模型就足够了

Models

Disable the Read/Write enabled flag

  • 默认开启
  • MeshRender 和 Static Batching 都需要开启

Disable rigs on non-character models

  • 不需要动画的关掉

Enable the Optimize Game Objects option on animated models

  • 开启来优化骨骼,需要的添加到 Extra Transforms

Use Mesh compression when possible

  • 优化掉精度
  • 可以针对 channel 来优化,只优化 tangents 和 normals,保留 UVS 和 顶点位置

Note: Mesh Renderer Settings

  • 不需要阴影和投射阴影的关掉,否则会导致 adds a full shadow pass to the rendering loop

Audio

Platform-appropriate compression settings

  • Enable a compression format for audio that matches the available hardware. All iOS devices include hardware MP3 decompressors, and many Android devices support Vorbis natively.

Force audio clips to mono

  • 很少移动设备支持 3D 音效
  • 强制单通道能减半内存

Reduce audio bitrate

  • 减少比特率,可以减少硬盘和内存消耗

Optimizations

发表于 2017-07-28 | 更新于 2017-07-28 | 分类于 Platform-specific , Mobile Developer Checklist , Optimizations

网址:Optimizations

Focus on GPUs

  • 填充率 = 屏幕像素 shader复杂度 overdraw

Good practice

  1. 少用 material,方便 batch
  2. 使用图集,加快载入时间,和方便 batch
  3. 使用 Renderer.sharedMaterial 代替 Renderer.material
  4. 前向像素光很耗
    • 使用光照贴图代替
    • 减少像素光照
  5. 测试灯光效果,调节优先次序
  6. 减少使用 cutout
  7. 减少透明混合
  8. 减少多光对同一个物体使用
  9. 减少 pass
  10. 渲染顺序很重要
  11. Post Processing 很耗
  12. 粒子减少 overdraw,使用简单的 shader
  13. Double buffer for Meshes modified every frame

Shader optimizations

  • 使用 alpha 混合代替 alpha 测试
  • 使用简单的优化的 shader
  • 减少运算,考虑使用查图代替
  • 减少精度

WindowsLowIntegrity

发表于 2017-07-28 | 更新于 2017-07-28 | 分类于 Platform-specific , Windows , Windows General , WindowsLowIntegrity

网址:WindowsLowIntegrity

WindowsLowIntegrity

Windows Standalone player can detect if it’s running at Low Integrity Level (see Microsoft’s documentation on Designing Applications to Run at a Low Integrity Level for more information). In this case, several things happen:

  • The log file is written to %USER PROFILE%\AppData\LocalLow\CompanyName\ProductName
  • PlayerPrefs is saved to HKCU\Software\AppDataLow\Software\CompanyName\ProductName

Optimizing the size of the built iOS player

发表于 2017-07-26 | 更新于 2017-07-27 | 分类于 Platform-specific , iOS , iOS Advanced Topics , Optimizing Performance in iOS , Optimizing the size of the built iOS player

网址:Optimizing the size of the built iOS player

iOS stripping level

The size optimizations activated by stripping work in the following way:

  1. Strip assemblies level: the scripts’ bytecode is analyzed so that classes and methods that are not referenced from the scripts can be removed from the DLLs and thereby excluded from the AOT compilation phase. This optimization reduces the size of the main binary and accompanying DLLs and is safe as long as no reflection is used.
  2. Strip ByteCode level: any .NET DLLs (stored in the Data folder) are stripped down to metadata only. This is possible because all the code is already precompiled during the AOT phase and linked into the main binary.
  3. Use micro mscorlib level: a special, smaller version of mscorlib is used. Some components are removed from this library, for example, Security, Reflection.Emit, Remoting, non Gregorian calendars, etc. Also, interdependencies between internal components are minimized. This optimization reduces the main binary and mscorlib.dll size but it is not compatible with some System and System.Xml assembly classes, so use it with care.
    每一层都包含上一层

Stripping with IL2CPP

Simple checklist for making your distribution as small as possible

  1. 压缩贴图和音效
  2. 调高 ios stripping level(难)
  3. 设置 Fast but no exceptions(没人用)
  4. 尽量不要使用 System.dll 和 System.xml.dll
  5. 移除没必要的代码依赖
  6. 使用 .net 2.0 subset
  7. 不使用 JS Array
  8. 不使用 泛型和值类型的结合(引用类型的泛型代码有优化,但是值类型没有)

iOS Specific Optimizations

发表于 2017-07-26 | 更新于 2017-07-26 | 分类于 Platform-specific , iOS , iOS Advanced Topics , Optimizing Performance in iOS , iOS Specific Optimizations

网址:iOS Specific Optimizations

Script Call Optimization

  • 大部分调用 UnityEngine 的接口,都会调用到 C,所以效率不高,可以更改 Script Call Optimization* 来做优化

Setting the Desired Framerate

  • 默认30帧

Tuning Accelerometer Processing Frequency

  • accelerometer input 不用可以关闭

Performance and Optimization

发表于 2017-07-25 | 更新于 2017-07-26 | 分类于 Animation , Performance and Optimization

网址:Performance and Optimization

Character Setup

Number of Bones

  • 减少骨骼数,或者隐藏掉

Multiple Skinned Meshes

  • 合并 Skinned Meshes

Animation System

Scale Curves

  • 比起位移旋转更加耗时,尽量不用

Humanoid vs. Generic Modes

  • 使用 BodyMask 移除 IK Goals 和 fingers animation 如果不用到的话
  • root motion 比较耗,可以的话不要使用

Runtime Optimizations

Visibility and Updates

  • Culling Mode Base On Renderers
  • 关闭 skinned mesh renderer’s update

12…7
Fly

Fly

作者懒得写

69 日志
113 分类
GitHub CSDN
© 2018 Fly
由 Hexo 强力驱动
主题 - NexT.Pisces
0%