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

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 指针文件,并且不会显示任何错误或警告消息。

Note: You cannot use the Package Manager window to install a package directly from a Git repository. You must edit the Project manifest to add a Git URLs as a dependency.

要将 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 中解析为提交哈希的表达形式。修订版本的最常见类型是提交哈希、标签和分支。

To target a specific revision, append the following to the Git URL in the dependencies attribute: # followed by the revision (either the version or a specific Git hash). Specifying the hash ensures that you get exactly the version you want. For example:

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

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

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

使用 SSH 协议

If you want to use the ssh protocol, make sure you use the full protocol syntax. The Package Manager does not support SCP-based shorthand syntax, and many Git hosting services supply the repository’s URL with the SCP syntax. So if you are copying the URL directly, make sure you use the ssh:// protocol and replace the colon (:) before the repository path with a slash (/). For example, if you get git@mycompany.github.com:gitproject/com.mycompany.mypackage.git from a GitHub repository, make sure you change it to the full syntax, as shown in this example:

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

NOTE: If you set up your SSH key with a passphrase, the Package Manager can’t retrieve the package, because you need to enter the passphrase in a shell or command line. In this case, consider using the https protocol instead, or use the ssh-add utility shipped with Git. For more information, see Authentication issues with Git URLs.

使用 FILE 协议

The Package Manager does not support file paths with the file prefix, but it does support full URLs with the file protocol. For example:

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