Version: 2019.3
本地路径
范围包注册表

Git URL

When the Package Manager fetches a package from a Git repository, it adds the package locally to your Project. This allows you to easily test unpublished changes, but you cannot use it to contribute to that Git repository. To set up an existing local Git repository as a dependency in your Project, use a local path instead.

To use Git packages in a Project, make sure the Git client is installed on your machine and that you have added the Git executable path to the PATH system environment variable.

如果代码仓库使用 Git LFS 来跟踪文件,请确保您的计算机上还安装了 Git LFS 客户端。如果未安装,则 Package Manager 无法获取存储在 LFS 服务器上的文件,而是签出 LFS 指针文件,并且不会显示任何错误或警告消息。

注意:还可以使用 Package Manager 窗口直接从 Git 代码仓库安装包。有关更多信息,请参阅从 Git URL 安装

要将 Git URL 指定为依赖项,请添加要使用 Git URL 安装的包名称,而不是版本号或本地文件路径。例如,下面演示了如何使用推荐的 HTTPS 协议指定远程 Git:

{
  "dependencies": {
    "com.mycompany.mypackage": "https://mycompany.github.com/gitproject/com.mycompany.mypackage.git"
}

Package Manager 支持 httpshttpsshgitfile 协议,使用的格式如下:

  <protocol>://[<user>[:<password>]@]<host>[:<port>]/<path>.git[#<revision>]

如果 URL 以如下格式的 git 开头,也可以跳过 .git 路径后缀:

  git://[<user>[:<password>]@]<host>[:<port>]/<path>[#<revision>]

或:

  git+<protocol>://[<user>[:<password>]@]<host>[:<port>]/<path>[#<revision>]

You might need to configure credentials in Git configuration files in order to provide your username and password securely. This is preferable to hard-coding them in the Git URL, which is a major security issue if the Project is shared with others.

当您使用 SSH 进行身份验证时,Git 会使用默认位置的密钥。但是,如果您在 Windows 上使用 PuTTY 作为 SSH 客户端,则可能需要配置 GIT_SSH 环境变量以使其指向 plink.exe

您需要在 Unity 外部设置 SSH 密钥。如果您没有适当的访问权限,Editor 会通知您身份验证失败。

有关为特定主机设置身份验证的更多信息,请参阅 GitLabGitHub 的帮助页面。

定位某个特定修订版本

您可以指定要安装的任何修订版本。修订版本是一个最终在 Git 中解析为提交哈希的表达形式。修订版本的最常见类型是提交哈希、标签和分支。

要定位某个特定修订版本,请将 # 及随后的修订版本(版本或特定 Git 哈希)附加到 dependencies 属性中的 Git URL。指定哈希可确保您准确获得所需的版本。例如:

{
  "dependencies": {
    "com.mycompany.mypackage": "https://mycompany.github.com/gitproject/com.mycompany.mypackage.git#523c4f291cea796141e7211f4951702984d2e9ca"
  }
}

如果省略了修订版本,则 Package Manager 将使用远程代码仓库的 HEAD 修订版本。

有关设置正确修订版本的更多信息,请参阅 Git 用户手册中有关 Git 修订版本的章节

使用 SSH 协议

如果要使用 ssh 协议,则可以使用完整的 URL 语法或 SCP 缩写:

# SCP shorthand
{
  "dependencies": {
    "com.mycompany.mypackage": "git@mycompany.github.com:gitproject/com.mycompany.mypackage.git"
}
# Full SSH protocol
{
  "dependencies": {
    "com.mycompany.mypackage": "ssh://git@mycompany.github.com/gitproject/com.mycompany.mypackage.git"
}

注意:如果您使用口令短语设置 SSH 密钥,则 Package Manager 将无法获取包,因为您需要在 shell 或命令行中输入口令短语。在这种情况下,请考虑改用 https 协议,或使用 Git 附带的 ssh-add 实用程序。有关更多信息,请参阅 Git URL 的身份验证问题

使用 FILE 协议

Package Manager 无法将带有 file 前缀的文件路径识别为 Git URL,但是如果格式正确,可以将带有 file 协议的完整 URL 识别为 Git URL。例如:

{
  "dependencies": {
    "com.mycompany.mypackage1": "file://localhost/absolute/path/to/com.mycompany.mypackage1.git",
    "com.mycompany.mypackage2": "git+file:///absolute/path/to/other/com.mycompany.mypackage2"
  }
}
本地路径
范围包注册表
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961