Version: 2021.3
包状态和生命周期
全局缓存

依赖和解析

当您在 Package Manager 窗口中工作时,可以安装来自多个来源的包(注册表,本地文件夹或者 tarball 以及 Git URL)。然而,虽然 Package Manager 从这些源无缝安装包,但它首先必须进行一系列计算来决定安装哪个版本,以及安装其他哪些包和版本来支持它。

当您通过 Package Manager 窗口选择要安装的包版本时,请向您的项目清单添加一个__依赖项__。这是一个声明,您需要特定包的特定版本才能使项目正常工作。出现在您的依赖项中项目清单称为“直接”依赖项。

包也可能需要其他包才能工作。这些被称为“间接”或传递性依赖项。包开发人员在开发过程中将这些依赖项添加到包的清单中。例如,在下图中,alembic@1.0.7 包依赖于 timeline@1.0.0 包,因此 timeline 包是一个“间接”依赖项。另一方面,该项目依赖于 cinemachine@2.6.0alembic@1.0.7 包,所以它们都是“直接”依赖项。

显示直接依赖项和间接依赖项的图

When you add a package version as a dependency, that version is not necessarily the version that the Package Manager installs, because it has to consider all of the dependencies in your project, whether direct or indirect. For example, in this case, the Settings Manager package requested was version 1.0.1, but the installed version is actually version 1.0.3 because another package depended on the higher version, as indicated in the information message (B):

When you click the information button in the details pane (A), a text box appears (B) explaining why this version was installed instead of the one you requested
When you click the information button in the details pane (A), a text box appears (B) explaining why this version was installed instead of the one you requested

The Package Manager can only install one package version at a time, so it has to construct a dependency graph, which is a list of every direct and indirect dependency for the project. The dependency graph determines which version of each package to install.

When the Package Manager successfully resolves all version conflicts, it saves the resolution in a lock file to ensure determinism (so that the same packages are reliably installed every time), and to reduce the amount of time and resources it takes to compute the dependency graph again.


包状态和生命周期
全局缓存
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961