Unity中的StrippingLevel

来源:互联网 发布:mac连接投影仪快捷键 编辑:程序博客网 时间:2024/05/20 23:07

StrippingLevel的作用

StrippingLevel是用来减少打包出来的player的体积

如图。第一个是选择Strip Byte Code的包的大小,第一个是选择的Disabled的打出来的包的大小,明显的Strip Byte Code的包体积小于没有进行剥离的包,大概1M。
这里写图片描述

StrippingLevel选项的副作用

使用Stripping Level需要注意的是,有可能会导致一些API执行过程中报异常,比如选择Strip Byte Code下,HttpWebRequest就会报异常:System.NotSupportedException,原因是被Strip出去了。
这里写图片描述

  /// <summary>    /// 获取下载文件的大小    /// </summary>    /// <returns>The length.</returns>    /// <param name="url">URL.</param>    public static long GetLength (string url) {        HttpWebRequest requet = HttpWebRequest.Create(url) as HttpWebRequest;        requet.Method = "HEAD";        HttpWebResponse response = requet.GetResponse() as HttpWebResponse;        UnityEngine.Debug.LogFormat("GetLength StatusCode:{0}", response.StatusCode);        return response.ContentLength;    }

利用link.xml手动排除不能被剥离的的类

<linker>      <assembly fullname="mscorlib">                  <type fullname="System.Reflection" preserve="all"/>                  <type fullname="System.Security.Cryptography" preserve="all"/>                  <type fullname="System.Runtime.CompilerServices" preserve="all"/>                  <type fullname="System.Runtime.InteropServices" preserve="all"/>                  <type fullname="System.Diagnostics" preserve="all"/>                  <type fullname="System.Security" preserve="all"/>                  <type fullname="System.Security.Permissions" preserve="all"/>      </assembly></linker>

参考链接:https://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html

原创粉丝点击