Version: 2023.2
向包添加测试
包清单

为资源包创建示例

Starting with Unity Editor version 2019.1, you can add samples to a package. A sample might be a piece of example code, some shaders and textures, some animation, or any other files that you can usually find under the project’s Assets folder.

When you open the Package Manager window and select a package containing samples, an Import button appears in the package’s details panel for each sample in the package. When you select Import, the Package Manager copies the whole subfolder structure for that sample under the project’s Assets folder.

要将示例添加到您的资源包中,请执行以下操作:

  1. Put the asset files or example C# code files under the Samples~ folder. You can have more than one sample in a package; each subfolder of the Samples~ folder has one sample.

    Note: The tilde character (~) tells Unity to ignore the contents the Samples~ folder. Such folders aren’t tracked with .meta files.

  2. 在您的 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

在清单中包含您的示例

Add a JSON array called samples to the package.json file. For each sample, add a JSON object containing at least the displayName and the path to the samples folder:

描述
displayName The name of the sample as it appears in the package details in the Package Manager window.
description A brief description of what the sample demonstrates or contains. This is just for the package manifest. The description doesn’t appear in the interface, even as a tooltip.
path Samples~ 文件夹到该示例的根文件夹的路径。

For example, using the same structure as the example for Location of sample files, the samples section looks similar to this:

{
    "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"
        }
    ]
}
向包添加测试
包清单