スコープ付きレジストリは、Unity のデフォルトのレジストリに加えてレジストリを使用することを可能にし、独自のパッケージをホストできます。スコープ付きレジストリを使用すると、Package Manager は常に 1 つのパッケージを 1 つのレジストリにマップし、ネットワークの条件にかかわらず一貫した結果を保証します。
例えば、Unity のパッケージの一部をホストする独自のサーバーを設定すると、もし 1 つのレジストリが一時的に利用できなくなると、たとえ Package Manager が常に同じ順序でレジストリを検索しても、誤ったレジストリからパッケージを取得する可能性があります。ただし、独自のサーバーにスコープ付きレジストリを設定すると、 パッケージは常に 1 つのレジストリにのみマップされるため 、ネットワークの条件にかかわらず一貫した結果が保証されます。
Unity Package Manager は npm プロトコルに基づくレジストリをサポートします。既成の npm レジストリサーバーはなんでも使用でき、動作するはずですが、Verdaccio は素早く設定でき、多くの設定を必要としません。
これらのサーバーを設定したら、それらを スコープ付きレジストリ として加えることができます。これは npm が使用する概念と同じです。
一部の npm レジストリサーバーは、/all
Web API ルートですべてのパッケージの検索をサポートするわけではありません。Package Manager Search API は、設定されたスコープ付きレジストリに依存してこの古い npm API プロトコルをサポートします。公開されたすべてのパッケージのメタデータを返す HTTP エンドポイントがあります (例えば、https://registry.my-company.com/-/all
)。
Package Manager API を使用して使用可能なパッケージを列挙するツールがある場合、レジストリが古いプロトコルをサポートしていないと、予期しない結果が発生する可能性があります。例えば、Package Manager ウィンドウの All packages (すべてのパッケージ) タブに、スコープ付きレジストリのパッケージは表示されません。ただし、この制限はパッケージの解決には適用されないため、スコープ付きレジストリからプロジェクトマニフェストにパッケージを手動で追加できます。
スコープ付きレジストリをプロジェクトマニフェストに設定するには、スコープ付きレジストリ設定オブジェクトの配列を取る scopedRegistries 属性を使用します。各オブジェクトには、スコープ付きレジストリにマップしたい各パッケージ名パターンの名前、URL の場所、スコープのリストが含まれます。Package Manager がパッケージを取得するレジストリを決定すると、パッケージの name と scopes の値を比較し、scopes が最も一致するレジストリを見つけます。
例えば、以下のプロジェクトマニフェストには、 Main と Tools の 2 つのスコープ付きレジストリがあります。
{
"scopedRegistries": [
{
"name": "Main",
"url": "https://my.company.com/registry",
"scopes": [
"com.my-company", "com.my-company.tools.foo"
]
},
{
"name": "Tools",
"url": "https://my.company.com/tools-registry",
"scopes": [
"com.my-company.tools"
]
}
],
"dependencies": {
"com.unity.cinemachine": "1.0.0",
"com.unity.2d.common": "1.0.0",
"com.unity.2d.animation": "1.0.0",
"com.my-company.bar": "1.0.0"
}
}
ユーザーが com.my-company.bar パッケージをリクエストすると、Package Manager は com.my-company.* 名前空間がその名前に最も一致することを見つけ、Main レジストリからパッケージを取得します。
ユーザーが com.my-company.tools.foo パッケージをリクエストすると、 Main レジストリに正確に一致する名前空間を持つスコープがあります。
ユーザーが com.my-company.tools.animation パッケージをリクエストすると、Package Manager は com.my-company.tools.* 名前空間がその名前に最も近いことを見つけ、Tools レジストリからパッケージを取得します。Main スコープにも一致しますが、com.my-company.* 名前空間はそれほど近く一致しません。
ユーザーが com.other-company.bar パッケージをリクエストすると、Package Manager はスコープされたどのレジストリーでも一致するものを見つけられないため、 デフォルトのレジストリからパッケージを取得します。
プロジェクトマニフェストの scopedRegistries 属性でスコープ付きレジストリを設定します。scopedRegistries 属性には、すべてのレジストリーを表すエントリー (オブジェクト) の配列が含まれます。
各レジストリオブジェクトには、一意の名前 (name)、場所 (url)、名前空間 (scopes) の配列が含まれます。Package Manager は scopes を使用して、 パッケージ名とレジストリを一致させます。
属性 | JSON 型 | 説明 |
---|---|---|
name | 文字列 | ユーザーインターフェースに表示されるスコープ名。Package Manager ウィンドウはパッケージの詳細ビューにこの名前を表示します。例えば、"name": "Tools"
|
url | 文字列 |
npm に互換するレジストリ への URL。例えば、"url": "https://my.company.com/tools-registry"
|
scopes | 文字列の配列 | スコープの配列。パッケージ名の正確な一致か、名前空間のいずれかでパッケージ名にマップできます。 例えば、 "scopes": [ "com.my-company", "com.my-company.tools.foo" ] ノート: このような設定は、パッケージが 逆ドメイン名表記 (英語) に従っていることを前提としています。これにより、com.unity が com.unity.* と同じであることが保証されます。 |
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.