Unity代码裁剪

原址:https://docs.unity3d.com/Manual/ManagedCodeStripping.html

 

描述

Managed code stripping removes unused code from a build, which can significantly decrease the final build size. When using the IL2CPP  scripting backend, managed code stripping can also decrease build time because less code needs to be converted to C++ and compiled. Managed code stripping removes code from managed assemblies, including assemblies built from the C# scripts

 in your Project, assemblies that are part of packages and plugins, and assemblies in the .NET frameworks.

(简言之:减小包大小,加速打包时间,特别是IL2CPP模式)

 

link.xml是Unity为了减少最终打入包的类库的精简配置文件。你可以用它来标识哪些类可以保留,哪些类可以剔除。到了il2cpp时代,Unity为了精简包大小,把所有C#函数里面用不到的类都给剔除了,导致lua中的反射受到严重影响。因此如果我们的c#类里面没有相关的类调用,但是最终在游戏运营阶段可能用到的类,就用link.xml类进行打包保留下来。这样ulua就可以在运营阶段调用到相关的类了。

 

原理

Managed code stripping works by statically analyzing the code in a Project to detect classes, members of classes, and even portions of functions that can never be reached during execution. You can control how aggressive Unity prunes unreachable code with the Managed Stripping Level setting on the Player Settings window (in the Optimization section).

 

posted @ 2019-11-20 11:39  何卫  阅读(1234)  评论(0)    收藏  举报