Unity3D研究院之Unity5.6的Lz4打ipa、apk包(九十二)

栏目: 编程语言 · 发布时间: 8年前

内容简介:Unity3D研究院之Unity5.6的Lz4打ipa、apk包(九十二)

Unity5.6今天发布了。支持打包lz4压缩包,支持ios和android。 这个lz4不是assetbundle,而是压缩预制在游戏包内的资源。比如场景依赖的资源,或者Resources目录下的资源,Prefab关联的资源等等。

压缩资源的描述如下

Compressed data files include:

1. Player settings – globalgamemanagers and globalgamemanagers.assets files.

2. Scenes and Assets – level* and sharedassets*.asset files.

3. Resources – resources.assets files.

4. GI data.

5. Built-in resources – unity_builtin_extra file.

之前Unity默认打的包都是zip也就是lzma 格式。因为压缩的比较大,那么解压就会慢。用新版lz4打包的好处就是游戏包可能大一点,但是解压的速度就更快。换句话说实例化gameObject 到Hierarchy的时候就会快。

我在小米Pad真机上测试了一下。

为了能突出时间,我拷贝了N张图片关联在Prefab上。在真机上来看加载的时间。

Unity3D研究院之Unity5.6的Lz4打ipa、apk包(九十二)

接着是打包的代码,因为我要同时出两个包,所以这里打了个lz4的和一个默认zip的包。

 [MenuItem("build/build")]
 static void Start () {
 
 
 PlayerSettings.bundleIdentifier = "com.yusongmomo.lz4";
 BuildPipeline.BuildPlayer (
 EditorBuildSettings.scenes, "export_lz4.apk",
 BuildTarget.Android,
 BuildOptions.CompressWithLz4 | BuildOptions.ConnectWithProfiler );
 
 
 
 PlayerSettings.bundleIdentifier = "com.yusongmomo.none";
 BuildPipeline.BuildPlayer (
 EditorBuildSettings.scenes, "export_none.apk",
 BuildTarget.Android,
 BuildOptions.ConnectWithProfiler);
 }

场景里把下面的脚本挂上去,把Resources.load的时间打印在屏幕上。。

usingSystem.Collections;
usingSystem.Collections.Generic;
usingUnityEngine;
usingUnityEngine.Profiling;
usingSystem.Diagnostics;
 
public class NewBehaviourScript : MonoBehaviour {
 
 string total =string.Empty;
 // Use this for initialization
 void Start () {
 
 Stopwatchsw = new Stopwatch();
 sw.Start();
 
 
 GameObject.Instantiate<GameObject> (Resources.Load<GameObject> ("1"));
 
 sw.Stop();
 total = string.Format("total: {0} ms",sw.ElapsedMilliseconds);
 
 }
 
 void OnGUI () 
 {
 GUI.skin.label.fontSize=50;
 GUILayout.Label (total);
 }
}

APK打出来后,可以看到zip的压缩格式比lzm4小一点。

Unity3D研究院之Unity5.6的Lz4打ipa、apk包(九十二)

把这两个包都装在手机上分别看看加载的速度吧。

请看左上角的加载速度,先看看zip的包。

Unity3D研究院之Unity5.6的Lz4打ipa、apk包(九十二)

在看看的lz4的包,加载速度完胜zip。。

Unity3D研究院之Unity5.6的Lz4打ipa、apk包(九十二)

最后总结一下:

如果可以容忍游戏包大一点,我觉得用lz4打包还是很给力的。

如果你的游戏包大量使用assetbundle,可能优势就不是那么明显。不过初始包肯定还是包含资源的,那么这些资源用lz4还是会快。


以上所述就是小编给大家介绍的《Unity3D研究院之Unity5.6的Lz4打ipa、apk包(九十二)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web ReDesign 2.0

Web ReDesign 2.0

Kelly Goto、Emily Cotler / Peachpit Press / 2004-12-10 / USD 45.00

If anything, this volume's premise--that the business of Web design is one of constant change-has only proven truer over time. So much so, in fact, that the 12-month design cycles cited in the last ed......一起来看看 《Web ReDesign 2.0》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具