UNITY优化资料收集

本文档详细介绍了Unity 3D (U3D) 游戏开发中的内存优化技巧,涵盖了Unity内存与Mono托管堆的区别及优化方法。提供了实用链接与API调用建议,如避免在移动端使用OnGUI()以减少内存消耗。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UNITY优化资料收集

U3D手册:

Optimizing garbage collection in Unity games

https://zhuanlan.zhihu.com/p/25306993  

https://github.com/mc-gulu/gl-bits/tree/master/(2017)%20unity-gc-cheatsheet 这个收集很全,也很新,结合项目得出的实际经验值得参考  

https://docs.unity3d.com/Manual/MobileProfiling.html 注意这里说明了MONO堆是只增不减的,在释放时并不是释放给操作系统,而是给MONO堆。

U3D的内存= UNITY内存+ MONO内存。

UNITY内存是引擎在C++层的堆内存: 包括:Asset data (Textures, Meshes, Audio, Animation, etc), Game objects, Engine internals (Rendering, Particles, Physics, etc). Use Profiler.usedHeapSize to get the total used Unity memory.

 

MONO堆是托管堆。在C#层申请的内存都属于托管堆。

 Use System.GC.GetTotalMemory to get the total used Mono memory.  

此文档中还提到了不要在移动平台使用 OnGUI(),在它里面会申请大量的内存。这一点不知道UNITY升级了IMGUI后还是否存在,有待测试。

可以使用下面这些API在游戏中实现自己的内存剖析功能:

You can also make your own tool using Unity API calls:-

  • FindObjectsOfTypeAll (type : Type) : Object[]
  • FindObjectsOfType (type : Type): Object[]
  • GetRuntimeMemorySize (o : Object) : int
  • GetMonoHeapSize
  • GetMonoUsedSize
  • Profiler.BeginSample/EndSample - profile your own code
  • UnloadUnusedAssets () : AsyncOperation
  • System.GC.GetTotalMemory/Profiler.usedHeapSize

 https://unity3d.com/de/learn/tutorials/topics/performance-optimization/optimizing-garbage-collection-unity-games?playlist=44069 

 

U3D 内存查看工具 MemoryProfiler 

安卓内存查看工具:android profiler

posted on 2018-09-06 10:10 时空观察者9号 阅读(...) 评论(...) 编辑 收藏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值