Set a shader to require a package
Use a PackageRequirements block to add package requirements to a subshader or a pass.
読み終わるまでの所要時間 2 分最終更新 22日前
To set a shader to only compile if a specific package is installed, add a block in the block or block.
PackageRequirementsSubShaderPassWhen Unity imports the shader, it checks if the specified package is installed in the project, and if the package version meets the requirements. If the requirements aren't met, Unity skips further processing of the subshader or shader pass.
For more information, refer to PackageRequirements block in ShaderLab reference.
Require a package version
Inside the block, use the following syntax:
PackageRequirements- to require package version
"com.my.package": "MAJOR.MINOR"or later.MAJOR.MINOR - to require Unity version
"unity": "6000.MINOR"or later.6000.MINOR
The block must be the first block in the block or block.
PackageRequirementsSubShaderPassRequire a version within a range
Inside the block, use , where is the minimum version and is the maximum version. The range is inclusive. For example:
PackageRequirements[MINIMUM,MAXIMUM]MININUMMAXIMUM- to require package version
"com.my.package": "[17.2,17.5]"or later, up to and including17.2.17.5 - to require Unity version
"unity": "[6000.2,6000.3]"or later, up to and including6000.2.6000.3
To specify a non-inclusive range, use parentheses. For example to require package version to , excluding and .
"com.my.package": "(17.2,17.5)"17.317.417.217.5To specify multiple ranges, use a semicolon to separate the ranges. For example .
"unity": "[6000.0,6000.1];[6000.3,6000.4]"Example
The following shader compiles only if the project has the package installed with a version of 2.2 or higher. The shader pass compiles only if the project has both the Universal Render Pipeline package with a version between 16.2.1 and 17.0, and the TextMesh Pro package with a version of 3.2 or higher.
com.my.packageShader "Examples/ExampleShader"{ SubShader { PackageRequirements { "com.my.package": "2.2" } Pass { PackageRequirements { "com.unity.render-pipelines.universal": "[16.2.1,17.0]" "com.unity.textmeshpro": "3.2" } ... } }}