本节提供有关如何为 Package Manager 配置以下内容的信息:
此外,您可以在配置文件下找到 Package Manager 配置文件的位置。
默认情况下,Package Manager 为其缓存使用以下文件夹结构:
<global-cache-root>
├── npm
│ └── <registry data (package metadata and tarballs)>
├── packages
│ └── <uncompressed contents of package tarballs>
└── git-lfs (if enabled)
└── <downloaded Git LFS files>
要覆盖 Package Manager 全局缓存根的默认位置,您可以使用用户配置文件中的 cacheRoot
属性或设置 UPM_CACHE_ROOT
环境变量。
注意:考虑对 macOS 和 Linux 系统使用配置文件策略,因为如果您不在 Windows 上,则很难使用环境变量启动 Unity。
您还可以设置环境变量来覆盖注册表数据缓存、未压缩包缓存或 Git LFS 缓存。但是,环境值和配置文件属性并不等效,因此使用不同的方法来配置设置可能会产生意想不到的结果。
影响级别和设置方法如何协同工作的因素有很多:
UPM_CACHE_ROOT
环境变量和 cacheRoot
属性为全局缓存根设置了不同的值,Package Manager 使用 UPM_CACHE_ROOT
环境变量中的位置。UPM_NPM_CACHE_PATH
)、未压缩包缓存 (UPM_CACHE_PATH
) 或 Git LFS 缓存 (UPM_GIT_LFS_CACHE_PATH
) 设置了环境变量,Package Manager 将使用新位置,而无论全局缓存根的位置如何。UPM_ENABLE_GIT_LFS_CACHE
),但未显式制定其路径 (UPM_GIT_LFS_CACHE_PATH
),Package Manager 将使用全局缓存根下的 git-lfs
文件夹作为其位置。按照以下说明覆盖全局缓存根的位置:
找到 .upmconfig.toml
用户配置文件。如果该文件不存在,请创建一个空文本文件。
使用绝对路径为 cacheRoot
属性设置一个自定义位置。例如:
cacheRoot = "/dev/external/shared/Unity/cache"
更改其 cacheRoot
属性后,无需重启 Unity 编辑器或 Hub 即可生效。
您可以使用环境变量为 Package Manager 配置多个设置。但是,为了应用这些设置,您必须从 Terminal 或命令提示符启动 Unity 或 Hub,其中每次都定义和导出这些环境变量。
For example, you can run these commands in a macOS or Linux terminal to configure the location of the global cache root and enable the Git LFS cache:
# On macOS/Linux:
export UPM_CACHE_ROOT=/dev/ssd/shared/Unity/cache
export UPM_ENABLE_GIT_LFS_CACHE=true
echo "Launching Unity with the Git LFS cache enabled and using this global cache location: '$UPM_CACHE_ROOT'"
"/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
This Windows example configures the location of the global cache root:
# On Windows:
set UPM_CACHE_ROOT=%ALLUSERSPROFILE%\Unity\cache
echo "Launching Unity with this global cache location: '%UPM_CACHE_ROOT%'"
"C:\Program Files\Unity Hub\Unity Hub.exe"
您可以使用 UPM_CACHE_ROOT
环境变量来覆盖全局缓存(包含注册表数据和未压缩包缓存的根文件夹)的位置。
以下环境变量可用:
环境变量: | 描述: |
---|---|
UPM_NPM_CACHE_PATH |
指定您希望 Package Manager 存储包的元数据和 tarball 的位置的绝对路径。默认情况下,这是全局缓存根目录下的 npm 子文件夹。 |
UPM_CACHE_PATH |
指定您希望 Package Manager 存储包的 tarball 的未压缩内容位置的绝对路径。默认情况下,这是全局缓存根目录下的 packages 子文件夹。 |
UPM_GIT_LFS_CACHE_PATH |
指定您希望 Package Manager 存储 Git LFS 缓存的位置的绝对路径。通过设置此路径,您会自动启用 Git LFS 缓存。 |
UPM_ENABLE_GIT_LFS_CACHE |
指定空值 ("" ) 以外的任何值以启用 Git LFS 缓存。Package Manager 将使用全局缓存根目录下的 git-lfs 子文件夹。 |
Package Manager 支持两个配置文件:全局配置文件和用户配置文件。这两个文件都使用 TOML 格式,位于不同的位置:
Package Manager 使用名为 upmconfig.toml
的全局配置文件,可以在这里找到:
环境: | 位置: |
---|---|
Windows | %ALLUSERSPROFILE%\Unity\config\upmconfig.toml |
macOS 和 Linux | /etc/upmconfig.toml |
Package Manager 使用名为 upmconfig.toml
的用户配置文件,可以在这里找到:
环境: | 位置: |
---|---|
Windows(用户帐户) |
%USERPROFILE%\.upmconfig.toml (for example, C:\Users\myusername\.upmconfig.toml ) |
Windows(系统用户帐户) |
%ALLUSERSPROFILE%\Unity\config\ServiceAccounts\.upmconfig.toml (例如,C:\Users\Public\Unity\config\ServiceAccounts\.upmconfig.toml ) |
macOS 和 Linux |
~/.upmconfig.toml (例如,/Users/myusername/.upmconfig.toml ) |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.