Version: 2022.2
访问包资源
解析和冲突

Scoped registries

Scoped registries allow Unity to communicate the location of any custom package registry server to the Package Manager so that the user has access to several collections of packages at the same time. Here are some important concepts to help you understand this feature:

概念: 描述:
包注册表服务器 一个跟踪包并提供包存储位置的应用程序。在 Unity 的 Package Manager 窗口中,当您选择 Unity Registry 上下文时,所有在 Unity 注册表中注册的包都出现在列表视图中。
Package Manager An application that tells the user what packages are available, and downloads and installs whatever package the user requests for their project. Unity has implemented its own version of a package manager, but there are several similar applications in other organizations.
范围 定义包名称或命名空间(以反向域格式),例如 com.example.mycompany.animationcom.example。当用户请求包时,Package Manager 从最匹配该范围的注册表中获取包。有关更多信息,请参阅下面的管理项目的范围注册表


The way you interact with scoped registries depends on your role:

  • Package providers set up custom registry servers to host and distribute custom packages in addition to the Unity registry.
  • Package consumers set up scoped registries for each project to access a custom package provider’s registry server.

Integrity and security of scoped registries

As a package provider, make sure any package registry servers you set up conform to Unity’s Terms of Service and Unity’s Package Guiding Principles & Guidelines. Unity provides access to the Package Manager to facilitate sharing knowledge and creations, but not as a marketplace for third-party products.

As a package consumer, when you install a scoped registry, use the same level of caution that you use when installing any other third-party software:

  • Install scoped registries only from trusted sources, since the packages in those registries can contain executable code.
  • Beware of third-party registries that may be harmful or capture data without appropriate controls. Also beware of third parties misrepresenting themselves as Unity, or sanctioned or supported by Unity.

Benefits of scoped registries

Scoped registries can help to:

  • 通过分发工具、库和其他资源来提供新的功能

    As a provider, you can create your own registry to distribute tools and scripts (or other types of assets) with version numbers that indicate how mature the package is. Version numbers also indicate whether updates introduce breaking API changes or minor fixes, based on Semantic Versioning. Your code can depend on code in other packages, because the Package Manager supports package dependencies.

    As a consumer, your experience of browsing and installing third-party custom packages in the Package Manager is the same as browsing Unity’s packages.

  • 扩展现有 Unity 包的功能

    作为使用者,您可以获得无缝体验,其中自定义包可覆盖 Unity 包,而无需手动切换注册表或显式安装不同的包版本。这是因为您可以将包映射到特定的注册表,以便 Package Manager 从 Unity 注册表或自定义包注册表服务器获取。

  • 在封闭网络环境中访问包

    一些组织在封闭的网络中工作,这使得访问 Unity 自己的包注册表变得困难。在这些情况下,组织可以在其封闭网络内的服务器上设置自己的包注册表。然后,网络管理员可以定期与 Unity 的包注册表同步,以确保范围注册表具有最新的可用包集合。

If you are a package consumer, see Managing scoped registries for a project for information about connecting to an existing custom package registry server in your Unity project. If you are a package producer, see Sharing your package for information about supported package registry servers, and to get links to information on how to set them up to use with scoped registries.

Note: If you are setting up a scoped registry that points to a package registry server with restricted access, you can configure Package Manager to pass your npm authentication token to the server. For more information, see Scoped registry authentication.

导入范围注册表

If you are working in a shared project, and another user adds a scoped registry to the project, Unity warns you that another user added a new scoped registry.

如果您的项目的范围注册表发生更改,Unity 会向您发出警告
如果您的项目的范围注册表发生更改,Unity 会向您发出警告

When you click the Close button, the Package Manager project settings window appears so you can add, modify, or remove scoped registries for your project.

If you click the Read more button instead, Unity opens this page in your default web browser.

Tip: To access the Package Manager project settings window at any time, use the main menu in Unity (Edit > Project Settings, then the Package Manager category) or select Advanced Project Settings from the advanced settings menu on the Package Manager window.

管理项目的范围注册表

To manage the scoped package registries in your project, you can either edit your project manifest file directly or use the Package Manager project settings window to let Unity modify the manifest for you.

The project manifest uses a scopedRegistries property, which contains an array of scoped registry configuration objects. Each object contains the following properties:

属性 JSON 类型 描述
name String 范围名称,在用户界面中显示。Package Manager 窗口在包详细信息视图中显示此名称。

例如 "name": "Tools"
url String 与 npm 兼容的注册表服务器的 URL。

例如:"url": "https://mycompany.example.com/tools-registry"

注意:并非所有注册表提供程序都与 Unity 的 Package Manager 兼容。确保您要添加的包注册表服务器实现 /-/v1/search/-/all 终端。
scopes 字符串数组 Array of scopes that you can map to a package name, either as an exact match on the package name, or as a namespace. Wildcards and other glob patterns aren’t supported.

For example, "scopes": [ "com.example", "com.example.tools.physics" ]

Note: This configuration type assumes that packages follow the Reverse domain name notation. This ensures that com.unity is equivalent to any package name that matches the com.unity namespace, such as com.unity.timeline or com.unity.2d.animation.

Warning: Unity doesn’t support npm’s scope notation.

When the Package Manager decides which registry to fetch a package from, it compares the package name to the scopes values and finds the registry whose scopes value is the closest match.

例如,在以下项目清单中,有两个范围注册表(“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"
    }
}

When the Package Manager looks up the com.example.animation package, it finds that the com.example namespace is the closest match to its name, and fetches that package from the “General” registry.

当 Package Manager 查找com.example.tools.physics 包时,“General” 注册表具有与包名称完全匹配的范围。

When the Package Manager looks up the com.example.mycompany.tools.animation package, the Package Manager finds that the com.example.mycompany.tools namespace is the closest match to its name and fetches that package from the “Tools” registry. Even though it also matches the “General” scope, the com.example namespace isn’t as close a match.

When the Package Manager looks up the com.unity.animation package, the Package Manager doesn’t find a match in any of the scoped registries, so it fetches the package from the default registry.


访问包资源
解析和冲突