使用 Unity 的 IL2CPP 脚本后端(在 Unity 2018.4 中是可选的,在 2019 和更高版本中是必需的)时,会发生托管代码剥离。 Unity 的链接器将执行此过程,以减小二进制文件大小并减少生成时间。
混合现实工具包使用文件 link.xml
来影响 Unity 链接器处理 MRTK 程序集的方式。 此文件在 Unity 的文档中已有详细介绍,它为链接器提供有关在无法推断代码的用法时如何保留代码的说明(例如:通过反射使用)。
作为一个灵活且可自定义的平台,MRTK 会在导入时在 Assets/MixedRealityToolkit.Generated
中创建 link.xml
文件(如果发现该文件不存在)。 不会覆盖现有的 link.xml 文件。 建议将 link.xml
和 link.xml.meta
添加到版本控制。 开发人员可以根据项目的需求任意自定义 Assets/MixedRealityToolkit.Generated/link.xml
。
默认情况下,MRTK 创建的 link.xml 文件会保留以下数据中显示的整个程序集。
<linker>
<!--
This link.xml file is provided to prevent MRTK code from being optimized away
during IL2CPP builds.More details on when this is needed and why this is needed
can be found here: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/5273
If your application doesn't use some specific services (for example, if teleportation system is
disabled in the profile), it is possible to remove their corresponding lines down
below(in the previous example, we would remove the TeleportSystem below).
It's recommended to start with this list and narrow down if you want to ensure
specific bits of code get optimized away.
-->
<assembly fullname = "Microsoft.MixedReality.Toolkit" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.SDK" preserve="all"/>
<!-- Core systems -->
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.BoundarySystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.CameraSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.DiagnosticsSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.InputSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.SceneSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.SpatialAwarenessSystem" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Services.TeleportSystem" preserve="all"/>
<!-- Data providers -->
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.LeapMotion" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.OpenVR" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.UnityAR" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality.Shared" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.WindowsVoiceInput" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.XRSDK" preserve="all"/>
<!-- Extension services -->
<assembly fullname = "Microsoft.MixedReality.Toolkit.Extensions.HandPhysics" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Extensions.Tracking" preserve="all"/>
<assembly fullname = "Microsoft.MixedReality.Toolkit.Extensions.SceneTransitionService" preserve="all"/>
</linker>
有关 link.xml 文件格式的详细信息,请参阅 Unity 文档。