2024年5月4日发(作者:)

Unity Manual > Advanced > Reducing File Size

Unity手册->高级->减少文件大小

Reducing File Size 较少文件大小

Unity post-processes all imported assets

Unity后处理所有导入的资产

Unity always post-processes imported files, thus storing a file as a multi-layered psd file instead of a jpg will

make absolutely zero difference in the size of the player you will deploy. Save your files in the format you are

working with (eg. .mb files, .psd files, .tiff files) to make your life easier.

Unity始终后处理导入的文件,因此存储一个文件作为一个多层次的psd文件代替一个jpg文件将绝对零差别在

你部署的播放器大小里。保存你文件在正在使用(例如.MB 、.PSD.、TIFF格式文件)格式使你的生活更轻松。

Unity strips out unused assets Unity输出不使用的资产

The amount of assets in your project folder does not influence the size of your built player. Unity is very smart

about detecting which assets are used in your game and which are not. Unity follows all references to assets

before building a game and generates a list of assets that need to be included in the game. Thus you can safely

keep unused assets in your project folder.

在你的项目文件夹里的资产的数量不影响你的内置播放器的大小。Unity是很聪明关于检测哪些资产应用与你的

游戏中,哪些不是。Unity跟踪所所有的引用资产在建立一个游戏之前并产生一个需要包含到游戏里的资产列表。

因此,你可以安全地保持没有使用的资产在你的项目文件夹里。

Unity prints an overview of the used file size Unity打印出使用文件大小的概述

After Unity has completed building a player, it prints an overview of what type of asset took up the most file size,

and it prints which assets were included in the build.

Unity已完成建设一个播放器后,它打印一个什么样的资产类型概述携带大多数的文件大小,以及它打印的包含

在创建里的资产。

To see it just open the editor console log: Open Editor Log button in the Console window (Window ->

Console).

去查看它只需打开编辑器控制日志:打开编辑器日志按钮在控制台窗口里(Window -> Console)。

An overview of what took up space 一个携带什么空间的概述

Optimizing texture size 优化纹理大小

Often textures take up most space in the build. The first to do is to use compressed texture formats (DXT or

PVRTC) where you can.

通常纹理携带许多空间在创建里。第一个做的是你可以在那里使用压缩纹理格式(DXT或PVRTC)。

If that doesn't get the size down, try to reduce the size of the textures. The trick here is that you don't need to

modfiy the actual source content. Simply select the texture in the Project view and set Max Texture Size in

Import Settings. It is a good idea to zoom in on an object that uses the texture, then adjust the Max Texture

Size until it starts looking worse in the Scene View.

如果没有得到减少的大小,尝试减少纹理的大小。这里的技巧是,你不必修改实际来源的内容。简单地选择在项

目视图的纹理和在导入设置里设置最大纹理尺寸。这是一个好主意放大在一个使用纹理的对象上,然后调整最大

纹理尺寸直到它开始看起来不好看在场景视图里。

Changing the Maximum Texture Size will not affect your texture asset, just its resolution in the game

更改纹理大小的最大值将不影响你的纹理资产,仅是它自己的分辨率在游戏里。

How much memory does my texture take up? 我的纹理占去多少内存

Compression 压缩

RGB Compressed DXT1

RGBA Compressed DXT5

RGB 16bit

RGB 24bit

Memory consumption 内存消耗

0.5 bpp (bytes/pixel)

1 bpp

2 bpp

3 bpp

Alpha 8bit

RGBA 16bit

RGBA 32bit

1 bpp

2 bpp

4 bpp

To figure out total texture size: width * height * bpp. Add 33% if you have Mipmaps.

计算出纹理大小总计:宽*高*bpp曾记33% 如果你有Mipmaps。

By default Unity compressed all textures when importing. This can be turned off in the Preferences for faster

workflow. But when building a game, all not-yet-compressed textures will be compressed.

到导入时,Unity默认压缩所有的纹理。这可以在参数选择里关闭为加快工作流程。但当编译一个游戏时,所有

没有压缩的纹理将被压缩。

Optimizing mesh and animation size 优化网格和动画大小

Meshes and imported Animation Clips can be compressed so they take up less space in your game file.

Compression can be turned on in Mesh Import Settings.

网格和导入的动画剪辑可以被压缩因此它们占去少的空间在你的游戏文件里。压缩可以开启在网格导入设置里。

Mesh and Animation compression uses quantization, which means it takes less space but the compression can

introduce some inaccuracies. Experiment with what level of compression is still acceptable for your models.

网格和动画压缩使用量化,这意味着它占用少的空间但压缩可能引入一些不准确度。为你的模型实验什么样的压

缩级别是可以接受的。

Note that mesh compression only produces smaller data files, and does not use less memory at run time.

Animation Keyframe reduction produces smaller data files and uses less memory at run time, and generally

you should always use keyframe reduction.

请注意,网格压缩只处理小型数据文件,并不在运行时使用较少的内存。动画关键帧还原生成较小的数据文件和

在运行时使用较少的内存,通常你应该总是使关键帧减少。

Additionally, you can choose not to store normals and/or tangents in your Meshes, to save space both in the

game builds and memory at run time. This can be set in Tangent Space Generation drop down in Mesh

Import Settings. Rules of thumb:

此外,你可以选择不要在你的网格平均和/或切线,既节省空间,在游戏中建立和内存在运行时。这可以在导入设

置里里切线空间生成里设置下降。经验法则:

Tangents are used for bump-mapping. If you don't use bump-mapping, you probably don't need to

store tangents in those meshes.

切线用于凹凸映射。如果你不使用凹凸映射,你可能并不需要存储在这些网格切线。

Normals are used for lighting. If you don't use realtime lighting on some of your meshes, you

probably don't need to store normals in them.

正常用于照明。如果你不使用你的网格一些实时照明,你可能不需要存储正常在它们里。

Reducing included dlls in the Web Player 减少包含的dlls在web播放器里

When building a Web player it is important to not depend on or . Unity does not

include or in the web player installation. That means, if you want to use Xml or

some Generic containers which live in then the required dlls will be included in the web player. This

usually adds 1mb to the download size, obviously this is not very good for the distribution of your web player

and you should really avoid it. If you need to parse some Xml files, you can use a smaller xml library like this

one . While most Generic containers are contained in mscorlib, Stack<> and few others are in

. So you really want to avoid those.

当建立一个Web播放器,重要的是不依赖于中或。Unity不包括在网页播放器安装

或。这意味着,如果你想使用XML或某些通用容器在里那么所需要的DLL

将包含在WEB播放器中。这通常增加下载1MB的大小,显然这不是很好的对你的WEB播放器,你应该避免。

如果你需要分析一些XML文件,你可以使用类似这样的一个较小的XML库。虽然大多数通用容

器包含mscorlib,Stack和其他几个都是在里。因此你真正要避开这些。

As you can see, Unity is including and , when building a player

正如你看到的,

Unity

是包含

,当编译一个播放器时。

Unity includes the following DLLs with the web player distribution , ,

and .

Unity包含下面的DLLS利用web播放器发布、、和。