范围注册表允许 Unity 将任何自定义包注册表服务器的位置传达给 Package Manager,以便用户可以同时访问多个包集合。以下是一些重要概念,可帮助您理解此功能:
概念: | 描述: |
---|---|
包注册表服务器 | 一个跟踪包并提供包存储位置的应用程序。在 Unity 的 Package Manager 窗口中,当您选择 Unity Registry 上下文时,所有在 Unity 注册表中注册的包都出现在列表视图中。 |
Package Manager | 一个应用程序,它告诉用户哪些包是可用的,并下载和安装用户为其项目请求的任何包。Unity 已经实现了自己版本的 Package Manager,但在其他组织中也有几个类似的应用程序。 |
范围 | 定义包名称或命名空间(以反向域格式),例如 com.example.mycompany.animation 或 com.example 。当用户请求包时,Package Manager 从最匹配该范围的注册表中获取包。有关更多信息,请参阅下面的管理项目的范围注册表。 |
除了 Unity 注册表,包提供者还可以设置自定义注册表服务器来托管和分发自定义包。包使用者为每个项目设置范围注册表,以便访问自定义包提供者的注册表服务器。
范围注册表可以帮助:
通过分发工具、库和其他资源来提供新的功能。
作为提供者,您可以创建自己的注册表来分发工具和脚本(或其他类型的资源),版本号表明包的成熟度,或者更新是否引入了破坏性的 API 更改或次要修复:语义版本控制。并且您的代码可以依赖于其他包中的代码,因为 Package Manager 支持包的依赖关系。
作为使用者,您在 Package Manager 中浏览和安装第三方自定义包的体验与 Unity 包相同。
扩展现有 Unity 包的功能。
As a consumer, you can have a seamless experience where the custom package overrides the Unity package without the having to manually switch registries or explicitly install a different package version. This is because you can map packages to a specific registry so that Package Manager fetches from either the Unity registry or a custom package registry server.
在封闭网络环境中访问包。
一些组织在封闭的网络中工作,这使得访问 Unity 自己的包注册表变得困难。在这些情况下,组织可以在其封闭网络内的服务器上设置自己的包注册表。然后,网络管理员可以定期与 Unity 的包注册表同步,以确保范围注册表具有最新的可用包集合。
如果您是包裹使用者,请参阅管理项目的范围注册表了解如何连接到 Unity 项目中现有的自定义包注册表服务器。如果您是包提供者,请参阅分享您的包裹了解受支持的包注册表服务器以及有关如何设置它们以与范围注册表一起使用的信息的链接。
注意:如果您正在设置范围注册表指向具有受限访问权限的包注册表服务器,您可以配置 Package Manager 将您的 npm 身份验证令牌传递给服务器。有关更多信息,请参阅范围注册表身份认证。
如果您在一个共享项目中工作,并且另一个用户向该项目添加了一个范围注册表,Unity 会警告您已经添加了一个新的范围注册表。
当您单击 Close 按钮,将出现 Package Manager 项目设置窗口,您可以添加、修改或者移除项目的范围注册表。
如果您单击 Read more 按钮,Unity 在您的默认 Web 浏览器中打开此页面。
提示: |
---|
To access the Package Manager project settings window at any time, use the main menu in Unity (menu: Edit > Project Settings, then the Package Manager category) or select Advanced Project Settings from the advanced settings drop-down menu on the Package Manager window. |
要管理项目中的包范围注册表,您可以直接编辑项目清单文件,或者使用 Package Manager 的项目设置窗口让 Unity 为您修改清单。
项目清单使用一个 scopedRegistries 属性,其中包含一个范围注册表配置对象数组。每个对象都包含以下属性:
属性 | JSON 类型 | 描述 |
---|---|---|
name | String | 范围名称,在用户界面中显示。Package Manager 窗口在包详细信息视图中显示此名称。 例如 "name": "Tools" 。 |
url | String | The URL to the npm-compatible registry server. For example, "url": "https://mycompany.example.com/tools-registry"
|
scopes | 字符串数组 | 可映射到包名称的范围数组(可与包名称完全匹配,也可以是命名空间)。不支持通配符和其他 glob 模式。 例如 "scopes": [ "com.example", "com.example.tools.physics" ] 注意:该类型的配置假设包遵循反向域名表示法。这确保了 com.unity 等价于任何与 com.unity 命名空间匹配的包名,例如 com.unity.timeline 或 com.unity.2d.animation 。警告: Unity 不支持 npm 的范围表示法。 |
Package Manager 决定从哪个注册表获取包时,会将包 name 的值与 scopes 的值进行比较,并找到 scopes 最匹配的注册表。
例如,在以下项目清单中,有两个范围注册表(“General” 和 “Tools”):
{
"scopedRegistries": [
{
"name": "General",
"url": "https://example.com/registry",
"scopes": [
"com.example", "com.example.tools.physics"
]
},
{
"name": "Tools",
"url": "https://mycompany.example.com/tools-registry",
"scopes": [
"com.example.mycompany.tools"
]
}
],
"dependencies": {
"com.unity.animation": "1.0.0",
"com.example.mycompany.tools.animation": "1.0.0",
"com.example.tools.physics": "1.0.0",
"com.example.animation": "1.0.0"
}
}
当 Package Manager 查找 com.example.animation
包时,发现 com.example
命名空间与其名称最匹配,因此从 “General” 注册表获取包。
When the Package Manager looks up the com.example.tools.physics
package, the “Tools” registry has a scope that exactly matches the package name.
当 Package Manager 查找 com.example.mycompany.tools.animation
包时,发现 com.example.mycompany.tools
命名空间与其名称最匹配,因此从 “Tools” 注册表获取包。虽然它也与 “General” 范围匹配,但 com.example
命名空间的匹配度不够精确。
当 Package Manager 查找 com.unity.animation
包时,在任何范围注册表中都找不到匹配项,因此从默认注册表获取该包。
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.