By default, the Package Manager uses the following folder structure for its caches:
<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
环境变量。
Note: For macOS and Linux systems, consider using the configuration file strategy for macOS and Linux systems, because it can be hard to launch Unity with environment variables on those systems.
You can also set environment variables to override the registry data cache, the uncompressed packages cache, and the Git LFS cache. However, environment values and configuration file properties are not equivalent, so using different methods to configure settings can produce unexpected results.
There are many factors affecting how setting several values with different methods works together:
UPM_CACHE_ROOT
环境变量和 cacheRoot
属性为全局缓存根设置了不同的值,Package Manager 使用 UPM_CACHE_ROOT
环境变量中的位置。UPM_NPM_CACHE_PATH
), the uncompressed packages cache (UPM_CACHE_PATH
), or the Git LFS cache (UPM_GIT_LFS_CACHE_PATH
), Package Manager uses the location specified by the environment variable, regardless of where the global cache root is.UPM_ENABLE_GIT_LFS_CACHE
),但未显式制定其路径 (UPM_GIT_LFS_CACHE_PATH
),Package Manager 将使用全局缓存根下的 git-lfs
文件夹作为其位置。按照以下说明覆盖全局缓存根的位置:
Locate the .upmconfig.toml
user configuration file. To find the file location, see Configuration files. If the file doesn’t exist, create an empty text file.
使用绝对路径为 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 locations of both the global cache root and the Git LFS cache:
# On Windows:
set UPM_CACHE_ROOT=%ALLUSERSPROFILE%\Unity\cache
set UPM_GIT_LFS_CACHE_PATH=%ALLUSERSPROFILE%\repos\caches\lfs
echo "Launching Unity with this global cache location: '%UPM_CACHE_ROOT%'"
echo "... and this Git LFS cache location: '%UPM_GIT_LFS_CACHE_PATH%'"
"C:\Program Files\Unity Hub\Unity Hub.exe"
以下环境变量可用:
环境变量: | 描述: |
---|---|
UPM_CACHE_ROOT |
Specify the location of the global cache (the root folder containing the registry data and uncompressed packages caches). |
UPM_NPM_CACHE_PATH |
指定您希望 Package Manager 存储包的元数据和 tarball 的位置的绝对路径。默认情况下,这是全局缓存根目录下的 npm 子文件夹。 |
UPM_CACHE_PATH |
指定您希望 Package Manager 存储包的 tarball 的未压缩内容位置的绝对路径。默认情况下,这是全局缓存根目录下的 packages 子文件夹。 |
UPM_ENABLE_GIT_LFS_CACHE |
Specify any value except empty ("") to enable the Git LFS cache. By default, Package Manager uses the git-lfs subfolder under the global cache root, unless you specify a different path using the UPM_GIT_LFS_CACHE_PATH environment variable. |
UPM_GIT_LFS_CACHE_PATH |
指定您希望 Package Manager 存储 Git LFS 缓存的位置的绝对路径。通过设置此路径,您会自动启用 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 ) |