Unity 创建一个规范的Package
-
为包命名
xxx.xxx.xxx...@v.v.v (字母要小写,@后是包版本号) -
Packages ├── package.json ├── README.md ├── CHANGELOG.md ├── LICENSE.md ├── Third Party Notices.md ├── Editor │ ├── Unity.[YourPackageName].Editor.asmdef │ └── EditorExample.cs ├── Runtime │ ├── Unity.[YourPackageName].asmdef │ └── RuntimeExample.cs ├── Tests │ ├── Editor │ │ ├── Unity.[YourPackageName].Editor.Tests.asmdef │ │ └── EditorExampleTest.cs │ └── Runtime │ ├── Unity.[YourPackageName].Tests.asmdef │ └── RuntimeExampleTest.cs ├── Samples~ │ ├── SampleFolder1 │ ├── SampleFolder2 │ └── ... └── Documentation~ └── [YourPackageName].md
- package.json: 定义了包的依赖项和其他元数据
- README.md: 说明文档
- CHANGELOG.md: 更新变更日志
- LICENSE.md: 许可证文本
- Editor: 存放与编辑器相关的代码
- Runtime/: 存放与运行时相关的代码
- Tests/: 存放用于测试包功能内容
- Samples~/: 存放各个示例文件夹
- Documentation~: 存放包的文档
-
包的示例 放置在 Samples~ 文件夹下.
- 一个子文件夹对应一个示例.
- 在 pageck.json 的 samples数组下为每个示例添加一个 JSON 对象.
-
package.json: 示例:
{ "name": "com.unity.example", "version": "1.2.3", "displayName": "Package Example", "description": "This is an example package", "unity": "2019.1", "unityRelease": "0b5", "documentationUrl": "https://example.com/", "changelogUrl": "https://example.com/changelog.html", "licensesUrl": "https://example.com/licensing.html", "dependencies": { "com.unity.some-package": "1.0.0", "com.unity.other-package": "2.0.0" }, "keywords": [ "keyword1", "keyword2", "keyword3" ], "samples": [ { "displayName": "HDRP Shaders", "description": "description text", "path": "Samples~/SamplesHDRP" }, { "displayName": "URP Shaders", "description": "description text", "path": "Samples~/SamplesUniversalRP" } ], "author": { "name": "Unity", "email": "unity@example.com", "url": "https://www.unity3d.com" } }
必需属性:
- name
- version
强制属性: 在技术上是可选的,但强烈要求填写
- displayName
- description
- unity: 包兼容的最低 Unity 版本, 如 "2019.4.28f1c1" 中的 "2019.4"
可选属性
-
unityRelease: 包兼容的 Unity 版本后部分,如 "2019.4.28f1c1" 中的 "28f1c1",注意: 如果省略 unity 属性,则此属性没有效果。
-
documentationUrl
-
changelogUrl
-
licensesUrl
-
dependencies: 此包依赖的其他包. 键是包名,值是特定版本
-
keywords: Package Manager 搜索使用的关键字数组。这可以帮助用户找到相关的包。
-
samples
-
author
-
hideInEditor:通常,Package Manager 会自动隐藏大多数包(隐式值为 “true”),但您可以将此属性设置为 “false”,确保您的包及其资源始终可见.
-
程序集定义 必须将包内的脚本与程序集定义文件 (.asmdef) 关联
请使用以下约定来命名和存储程序集定义文件.// 存储在 Editor 的程序集定义文件 Editor/MyCompany.MyFeature.Editor.asmdef // 运行时的程序集定义文件 Runtime/MyCompany.MyFeature.Runtime.asmdef // 用于测试的程序集定义文件 Tests/Editor/MyCompany.MyFeature.Editor.Tests.asmdef Tests/Runtime/MyCompany.MyFeature.Runtime.Tests.asmdef
示例文件:
{ "name": "com.test.template", "references": [], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], "versionDefines": [], "noEngineReferences": false }