从 2019.1 开始,您可以将示例添加到资源包中。示例可能是一段示例代码、一些着色器和纹理、一些动画,或者您通常可以在项目的 Assets
文件夹下找到的任何其他文件。
当用户打开 Package Manager 窗口并选择包含示例的资源包时,资源包中每个示例的详细信息窗格中将出现 Import 按钮。当用户单击 Import 按钮时,Package Manager 会将该示例的整个子文件夹结构复制到项目的 Assets
文件夹下。
要将示例添加到您的资源包中,请执行以下操作:
Samples~
文件夹下。一个资源包可包含多个示例:Samples~
文件夹的每个子文件夹分别包含一个示例。package.json
清单文件中的 samples
数组下为每个示例添加一个 JSON 对象。您可以在资源包的 Samples~
文件夹的子文件夹下添加示例资源。例如,一个包含着色器示例的资源包可能如下所示:
MyPackage
├── package.json
└── Samples
├── SamplesHDRP
│ ├── Textures
│ | ├── MossyRock.bmp
│ | └── SandyRock.bmp
│ └── Shader
│ ├── Lit Texture Blend HDRP.ShaderGraph
│ └── Lit Vertex Color HDRP.ShaderGraph
└── SamplesStandard
│ ├── Textures
│ | ├── MossyRock.bmp
│ | └── SandyRock.bmp
│ └── Shader
│ ├── StandardTextureBlend.shader
│ └── StandardVertexColor.shader
└── SamplesUniversalRP
├── Textures
| ├── MossyRock.bmp
| └── SandyRock.bmp
└── Shader
├── Lit Texture Blend URP.ShaderGraph
└── Lit Vertex Color URP.ShaderGraph
将 JSON 数组添加到名为 samples
的 package.json
文件。对于每个示例,将至少包含 displayName
和 path
的 JSON 对象添加到示例文件夹:
值: | 描述: |
---|---|
displayName |
在 Package Manager 窗口中,将出现在资源包详细信息中的示例的名称。 |
description |
示例演示或包含的内容的简要说明。仅用于资源包清单。说明不会出现在界面中,即使是作为工具提示。 |
path |
从 Samples~ 文件夹到该示例的根文件夹的路径。 |
例如,使用与示例文件的位置一例相同的结构,samples
部分类似于:
{
"samples": [
{
"displayName": "HDRP Shaders",
"description": "Contains sample shaders for the High Definition render pipeline",
"path": "Samples~/SamplesHDRP"
},
{
"displayName": "URP Shaders",
"description": "Contains sample shaders for the Universal render pipeline",
"path": "Samples~/SamplesUniversalRP"
},
{
"displayName": "Standard RP Shaders",
"description": "Contains sample shaders for the Standard render pipeline",
"path": "Samples~/SamplesStandard"
}
]
}
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.