Unity3d新手入门之-----TexturePackers的使用

刚开始从Cocos2dx转做Unity3D,不得不说组件化的开发真的是太方便了!

为了纪念之前不努力的那段工作时光,在面试碰壁之后,决定开始写博客记录自己的自救历程了。

从开始做Cocos2dx的时候,做的基本上就都是2d游戏,要减少内存损耗的第一步,个人觉得肯定是从资源下手了,用了以前一直在用的TexturePacker。


1、打成图集的功能不用说了。合理的使用图集能够有效的降低Batches与Draw Call。

   关于这一点,有需要说明的地方,即使是将一部分图片打包成一个图集了,如果渲染的顺序不一样,那同样有可能会产生额外的Batches和DrawCall,例如A、B两张图都在一个图集里,C是单独一张图片,当开发者没有刻意去控制他们的渲染顺序的时候,如果此时的渲染顺序是 A -> C -> B,那么就会产生额外的Draw Call,是3,因为渲染的过程中,A和B中间插入了一个C,被打断了,于是后面重新载入了一次。

2、TP打出来的图片,导入工程后是DXT5格式的。包括POT啊,抖动啊之类的功能设置起来都极其方便。

3、打成图集后图片占用内存真的小太多了。再详细的原理目前可能还是我没办法完全记住的内容,所以先记住了占用内存少。

4、(很重要,因为没以前麻烦了,我比较懒)以前还需要自己手写读取tp文件的脚本,现在只需要导入资源商店里的TexturePacker Importer就行了。

重点说一下Tracer Tolerance这个选项。

引用一段原文:

https://www.codeandweb.com/texturepacker/documentation/texture-settings

(only available if trim mode is Polygon)
Determines how precise the polygon approximates the sprite outline.

Small values lead to a very close-fitting polygon. This allows very good packing results, but increases the processing time needed by the packer. At runtime you might get a performance gain due to the reduced overdraw, or a performance loss due to the larger amount of vertices which have to be processed.

With large tracer tolerance values the polygon is only a rough approximation of the sprite outline. The packer performance will increase, but the sprite sheets might get a bit larger. Runtime performance might get better (less vertices to process) or worse (higher overdraw). Setup some performance tests to find the best value for your sprites and target platform!

数值越小,顶点越少,一定程度上会增加渲染区域,可能会增加性能开销。

数值越大,顶点越多,会减少多余的渲染区域,但因为顶点的增加,也可能会增加性能开销。

如何取值,要在实际项目中,自己去调试了。

猜你喜欢

转载自www.cnblogs.com/optexpr/p/11070901.html