[Unity] AssetBundles打包后资源加载速度慢

记一次打包异常,资源加载速度过慢- -

打包设置为gradle时发现进游戏loading时间贼长,后查找发现似乎AssetBundles都被安卓aapt工具给压缩了。loading时似乎在解压,所以占用了很长的时间。选择internal就没有这个问题了。

如果必须要设置打包方式为gradle,可以将AssetBundles包手动加上一个自定义后缀名。然后在Assets\Plugins\Android\mainTemplate.gradle文件中这行,加上自定义的后缀名,noCompress为不压缩的意思。

	aaptOptions {
		noCompress '.unity3d', '.ress', '.resource', '.obb'
	}

其实这行默认的是这样的:

	aaptOptions {
		noCompress '.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**
	}

但是如果打包异常,可以选择删掉'**STREAMING_ASSETS**',因为这个不压缩文件数量似乎是有一个255的限制,超过的话会导致打包异常。

-----------------------------------------------------------------分割线-----------------------------------------------------------------

刚翻了出去上谷歌看了下官方文档说明然后尝试了一波,没有后缀名的AssetBundles直接在noCompress里写上文件名也行,例如:

	aaptOptions {
		noCompress '.unity3d', '.ress', '.resource', '.obb','aaa','bbb','ccc'
	}

这样AssetBundles 'aaa','bbb','ccc' 也不会被压缩,loading速度也可以保持正常水平。

猜测unity或者Android是通过endwith方式查找指定文件然后选择是否压缩,猜测0.0。(注意aaptOptions 里面参数似乎得小写,他似乎是区分大小写的)

这是官方文档关于aaptOptions 的说明:

noCompress

Extensions of files that will not be stored compressed in the APK. Adding an empty extension, i.e., setting noCompress '' will trivially disable compression for all files.

猜你喜欢

转载自blog.csdn.net/qq302756113/article/details/89242959
今日推荐