减小文件大小

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编译发布一个播放器之后,它将打印什么资源类型占用大部分文件大小的一个概述,并打印在编译时包含哪些资源。

Desktop

To see it just open the editor console log: Open Editor Log button in the Console window (Window -> Console).
在控制台窗口(Window -> Console)单击Open Editor Log 按钮,打开控制台日志就能看到。

iOS
To see it just open the console log: Help -> Open Editor console log menu.
在Help -> Open Editor console log 菜单中打开查看控制台日志。

Android
To see it just open the editor console log: Open Editor Log button in the Console window (Window -> Console).
在控制台窗口(Window -> Console)单击Open Editor Log 按钮. 打开控制台日志就能看到

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(Desktop platforms) or PVRTC) where you can.
通常纹理在编译时会占用大量空间。第一件需要做的事情就是在编译播放器时使用纹理压缩(DXT(Desktop platforms) or 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.
如果压缩仍不能缩小纹理的大小,你可以试着去减小纹理的大小。有个技巧,你不需要修改实际的源内容。在你的项目视图的Import Settings菜单下选择Max Texture Size。这样你可以缩小对象上使用的纹理,然后调整Max Texture Size,直到在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?
纹理占用多少内存

Desktop
Compression 压缩 Memory consumption 内存消耗
RGB Compressed DXT1 0.5 bpp (bytes/pixel)
RGBA Compressed DXT5 1 bpp
RGB 16bit 2 bpp
RGB 24bit 3 bpp
Alpha 8bit 1 bpp
RGBA 16bit 2 bpp
RGBA 32bit 4 bpp

iOS
Compression 压缩 Memory consumption 内存消耗
RGB Compressed PVRTC 2 bits 0.25 bpp (bytes/pixel)
RGBA Compressed PVRTC 2 bits 0.25 bpp
RGB Compressed PVRTC 4 bits 0.5 bpp
RGBA Compressed PVRTC 4 bits 0.5 bpp
RGB 16bit 2 bpp
RGB 24bit 3 bpp
Alpha 8bit 1 bpp
RGBA 16bit 2 bpp
RGBA 32bit 4 bpp

Android
Compression 压缩 Memory consumption 内存消耗
RGB Compressed DXT1 0.5 bpp (bytes/pixel)
RGBA Compressed DXT5 1 bpp
RGB Compressed ETC1 0.5 bpp
RGB Compressed PVRTC 2 bits 0.25 bpp (bytes/pixel)
RGBA Compressed PVRTC 2 bits 0.25 bpp
RGB Compressed PVRTC 4 bits 0.5 bpp
RGBA Compressed PVRTC 4 bits 0.5 bpp
RGB 16bit 2 bpp
RGB 24bit 3 bpp
Alpha 8bit 1 bpp
RGBA 16bit 2 bpp
RGBA 32bit 4 bpp

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

总纹理大小:宽*高*bpp,如果使用Mipmap增加33%。

By default Unity compresses 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会在导入时对纹理进行压缩,为了加速工作,你可以在Preferences里关闭该功能,但是当编译游戏时,所有尚未被压缩纹理都将被重新压缩。

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:

此外,你可以选择不把法线 和/或 切线存储在网格里,这样你可以在游戏编译和内存运行时节省空间。你可以在Mesh Import Settings菜单下面的Tangent Space Generation设置,规则如下:

Tangents are used for normal-mapping. If you don’t use normal-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 Players 减少播放器中的包含的dll
When building a player (Desktop, Android or iOS) it is important to not depend on System.dll or System.Xml.dll. Unity does not include System.dll or System.Xml.dll in the players installation. That means, if you want to use Xml or some Generic containers which live in System.dll then the required dlls will be included in the players. This usually adds 1mb to the download size, obviously this is not very good for the distribution of your players and you should really avoid it. If you need to parse some Xml files, you can use a smaller xml library like this one Mono.Xml.zip. While most Generic containers are contained in mscorlib, Stack<> and few others are in System.dll. So you really want to avoid those.

在编译播放器(Desktop、Android或iOS)不依赖System.dll或System.XML.dll是很重要的。在播放器安装时Unity不包含System.dll或System.XML.dll。就是说,如果你想使用XML或一些位于System.dll中的通用容器,那么需要的DLL将被包含在播放器中。这通常会使下载大小增加1MB,显然这对于播放器的发布并不好,因此你应该避免。如果您需要解析一些XML文件,你可以使用一个较小的像这样的Mono.Xml.zip的XML库。大多数通用的容器包含在mscorlib中,Stack<>和其他一些在System.dll中。所以,你应该避免这些。

As you can see, Unity is including System.Xml.dll and System.dll, when building a player
正如你所见,当编译一个播放器时Unity包含System.XML.dll和System.dll

Unity includes the following DLLs with the players distribution mscorlib.dll, Boo.Lang.dll, UnityScript.Lang.dll and UnityEngine.dll.

在播放器分发包中,Unity包含如下的dll,mscorlib.dll,Boo.Lang.dll,UnityScript.Lang.dll 和UnityEngine.dll。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值