您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 
fzhangtj 52bb51b2 move files 6 年前
Assets move files 6 年前
Documentation~ add packman template 6 年前
Editor add 6 年前
Packages add packman template 6 年前
ProjectSettings add packman template 6 年前
Runtime move files 6 年前
Samples add packman template 6 年前
Tests add packman template 6 年前
scripts add packman template 6 年前
.README - External.md add packman template 6 年前
.gitignore fix 6 年前
.gitlab-ci.yml add packman template 6 年前
.npmignore add packman template 6 年前
Assets.meta add packman template 6 年前
CHANGELOG.md add packman template 6 年前
CHANGELOG.md.meta add packman template 6 年前
CONTRIBUTING.md add packman template 6 年前
CONTRIBUTING.md.meta add packman template 6 年前
Editor.meta add packman template 6 年前
LICENSE.md add packman template 6 年前
LICENSE.md.meta add packman template 6 年前
Packages.meta add packman template 6 年前
ProjectSettings.meta add packman template 6 年前
QAReport.md add packman template 6 年前
QAReport.md.meta add packman template 6 年前
README.md add packman template 6 年前
README.md.meta add packman template 6 年前
Runtime.meta add packman template 6 年前
Samples.meta add packman template 6 年前
Tests.meta add packman template 6 年前
Third Party Notices.md add packman template 6 年前
Third Party Notices.md.meta add packman template 6 年前
build.bat add packman template 6 年前
build.bat.meta add packman template 6 年前
build.sh add packman template 6 年前
build.sh.meta add packman template 6 年前
package.json add packman template 6 年前
package.json.meta add packman template 6 年前
scripts.meta add packman template 6 年前

README.md

UPM Package Starter Kit

The purpose of this package template starter kit is to provide the data structure and development guidelines for new packages meant for the Unity Package Manager (UPM).

This is the first of many steps towards an automated package publishing experience within Unity. This package template starter kit is merely a fraction of the creation, edition, validation, and publishing tools that we will end up with.

We hope you enjoy your experience. You can use #devs-packman on Slack to provide feedback or ask questions regarding your package development efforts.

Are you ready to become a package?

The Package Manager is a work-in-progress for Unity and, in that sense, there are a few criteria that must be met for your package to be considered on the package list at this time:

  • Your code accesses public Unity C# APIs only. If you have a native code component, it will need to ship with an official editor release. Internal API access might eventually be possible for Unity made packages, but not at this time.
  • Your code doesn't require security, obfuscation, or conditional access control. Anyone should be able to download your package and access the source code.
  • You have no urgent need to release your package. Our current target for new packages is aligned with 2018.1. Although, based on upcoming package requests and limited packman capacity, that release date is not assured for any package.
  • You are willing to bleed with us a little! Packman is still in development, and therefore has a few rough edges that will require patience and workarounds.

Package structure

<root>
  ├── package.json
  ├── README.md
  ├── CHANGELOG.md
  ├── LICENSE.md
  ├── Third Party Notices.md
  ├── QAReport.md
  ├── Editor
  │   ├── Unity.[YourPackageName].Editor.asmdef
  │   └── EditorExample.cs
  ├── Runtime
  │   ├── Unity.[YourPackageName].asmdef
  │   └── RuntimeExample.cs
  ├── Tests
  │   ├── .tests.json
  │   ├── Editor
  │   │   ├── Unity.[YourPackageName].Editor.Tests.asmdef
  │   │   └── EditorExampleTest.cs
  │   └── Runtime
  │        ├── Unity.[YourPackageName].Tests.asmdef
  │        └── RuntimeExampleTest.cs
  ├── Samples
  │   └── Example
  │       ├── .sample.json
  │       └── SampleExample.cs
  └── Documentation~
       ├── your-package-name.md
       └── Images

Develop your package

Package development works best within the Unity Editor. Here's how to set that up:

  1. Clone the package-template repository locally

    • In a console (or terminal) application, choose a place to clone the repository and perform the following :
    git clone https://gitlab.cds.internal.unity3d.com/upm-packages/upm-package-template.git
    
  2. Create a new repository for your package and clone to you desktop

    • On Gitlab, navigate to the upm-packages, and make sure you have a sub-group for your feature area. If you don't have one, you can request a new sub-group in #devs-packman.
    • Create a new repository with the name of your package (Example: "com.unity.terrain-builder")
    • In a console (or terminal) application, choose a place to clone the repository and perform the following :
    git clone https://gitlab.cds.internal.unity3d.com/upm-packages/[your-sub-group]/com.unity.[sub-group].[your-package-name]
    
  3. Start Unity, create a local empty project.

  4. In a console (or terminal) application, go to the newly created project folder, then clone your newly created package repository into the packages directory.

    cd <YourProjectPath>/Packages
    git clone https://gitlab.internal.unity3d.com/upm-packages/[sub-group]/[your-package-name].git com.unity.[sub-group].[your-package-name]
    

    Note: Your directory name must be the name of your package (Example: "com.unity.terrain-builder")

  5. Copy the locally cloned upm-package-template folder contents to your locally cloned package's folder. Be careful not to copy the upm-package-template .git folder over.

  6. In a console (or terminal) application, push the template files you copied in your new package repository to it's remote

    • Add them to your repository's list to version git add .
    • Commit to your new package's remote master git commit
    • Push to your new package's remote master git push
  7. Fill in your package information

    Update the following required fields in file package.json:

    • "name": Package name, it should follow this naming convention: "com.unity.[sub-group].[your-package-name]" (Example: "com.unity.2d.animation", where sub-group should match the sub-group you selected in Gitlab)
    • "displayName": Package user friendly display name. (Example: "Terrain Builder SDK").
      Note: Use a display name that will help users understand what your package is intended for.
    • "version": Package version "X.Y.Z", your project must adhere to Semantic Versioning. Follow this guideline:
      • To introduce a new feature or bug fix, increment the minor version (X.Y.Z)
      • To introduce a breaking API change, increment the major version (X.Y.Z)
      • The patch version (X.Y.Z), is reserved for sustainable engineering use only.
    • "unity": Unity Version your package is compatible with. (Example: "2018.1")
    • "description": This description appears in the Package Manager window when the user selects this package from the list. For best results, use this text to summarize what the package does and how it can benefit the user.
      Note: Special formatting characters are supported, including line breaks (\n) and unicode characters such as bullets (\u25AA).
      For more information, see the Writing Package docs page on Confluence.

    Update the following recommended fields in file package.json:

    • "dependencies": List of packages this package depends on. All dependencies will also be downloaded and loaded in a project with your package. Here's an example:
      dependencies: {
        "com.unity.ads": "1.0.0"
        "com.unity.analytics": "2.0.0"
      }
      
    • "keywords": List of words that will be indexed by the package manager search engine to facilitate discovery.

    Update the following field in file Tests/.tests.json:

    • "createSeparatePackage": If this is set to true, the CI will create an separate package for these tests.
  8. Restart Unity. For more information on embedded packages see here.

  9. If on 2018.1 - Enable package support in the editor (Internal Feature). From the Project window's right hang menu, enable DEVELOPER->Show Packages in Project Window (only available in developer builds). You should now see your package in the Project Window, along with all other available packages for your project.

  10. Update README.md

    The README.md file should contain all pertinent information for developers using your package, such as:

    • Prerequistes
    • External tools or development libraries
    • Required installed Software
    • Command line examples to build, test, and run your package.
  11. Rename and update your-package-name.md documentation file.

    Use this template to create preliminary, high-level documentation. This document is meant to introduce users to the features and sample files included in your package.

  12. Rename and update assembly definition files.

    If your package contains Editor code, rename and modify Editor/Unity.YourPackageName.Editor.asmdef. Otherwise, delete the Editor directory.

    • Name must match your package name, suffixed by .Editor (i.e Unity.[YourPackageName].Editor)
    • Assembly must reference Unity.[YourPackageName] (if you have any Runtime)
    • Platforms must include "Editor"

    If your package contains code that needs to be included in Unity runtime builds, rename and modify Runtime/Unity.YourPackageName.asmdef. Otherwise, delete the Runtime directory.

    • Name must match your package name (i.e Unity.[YourPackageName])

    If your package has Editor code, you must have Editor Tests. In that case, rename and modify Tests/Editor/Unity.YourPackageName.Editor.Tests.asmdef.

    • Name must match your package name, suffixed by .Editor.Tests (i.e Unity.[YourPackageName].Editor.Tests)
    • Assembly must reference Unity.[YourPackageName].Editor and Unity.[YourPackageName] (if you have any Runtime)
    • Platforms must include "Editor"
    • Optional Unity references must include "TestAssemblies" to allow your Editor Tests to show up in the Test Runner/run on Katana when your package is listed in project manifest testables

    If your package has Runtime code, you must have Playmode Tests. In that case, rename and modify Tests/Runtime/Unity.YourPackageName.Tests.asmdef.

    • Name must match your package name, suffixed by .Tests (i.e Unity.[YourPackageName].Tests)
    • Assembly must reference Unity.[YourPackageName]
    • Optional Unity references must include "TestAssemblies" to allow your Playmode Tests to show up in the Test Runner/run on Katana when your package is listed in project manifest testables

    The reason for choosing such name schema is to ensure that the name of the assembly built based on assembly definition file (a.k.a .asmdef) will follow the .Net Framework Design Guidelines

  13. Document your package.

    Document your public APIs

    • All public APIs need to be documented with XmlDoc. If you don't need an API to be accessed by clients, mark it as internal instead.
    • API documentation is generated from XmlDoc tags included with all public APIs found in the package. See Editor/EditorExample.cs for an example.

    Document your features

    Documentation flow

    • Documentation needs to be ready when a publish request is sent to Release Management, as they will ask the documentation team to review it.
    • The package will remain in preview mode until the final documentation is completed. Users will have access to the developer-generated documentation only in preview packages.
    • When the documentation is completed, the documentation team will update the package git repo with the updates and they will publish it on the web.
    • The package's development team will then need to submit a new package version with updated docs.
    • The starting page in the user manual that links to package documentation is Here.
    • The Documentation~ folder is suffixed with ~ so that its content does not get loaded in the editor, which is the recommended behavior. If this is problematic, you can still name it Documentation and all tools will still work correctly. .Documentation is also supported.

    Test your documentation locally As you are developing your documentation, you can see what your documentation will look like by using the DocTools extension (optional). Once the DocTools package is installed, it will add a Generate Documentation button in the Package Manager UI's details of your installed packages. To install the extension, follow these steps:

    1. Make sure you have Package Manager UI v1.9.6 or above.
    2. Your project manifest will need to point to a staging registry for this, which you can do by adding this line to it: "registry": "https://staging-packages.unity.com"
    3. Install Package Manager DocTools v1.0.0-preview.6 or above from the Package Manager UI (in the All Packages section).
    4. After installation, you will see a Generate Documentation button which will generate the documentation locally, and open a web browser to a locally served version of your documentation so you can preview it.
    5. (optional) If your package documentation contains multiple .md files for the user manual, see this page to add a table of content to your documentation.

    The DocTools extension is still in preview, if you come across arguable results, please discuss them on #docs-packman.

  14. Add samples to your package (code & assets).

    If your package contains a sample, rename the Samples/Example folder, and update the .sample.json file in it.

    In the case where your package contains multiple samples, you can make a copy of the Samples/Example folder for each sample, and update the .sample.json file accordingly.

    Similar to .tests.json file, there is a "createSeparatePackage" field in .sample.json.If set to true, the CI will create an separate package for the sample..

    Delete the Samples folder altogether if your package does not need samples.

    As of Unity release 2019.1, the /Samples directory of a package will be recognized by the package manager. Samples will not be imported to Unity when the package is added to a project, but will instead be offered to users of the package as an optional import, which can be added to their "/Assets" directory through a UI option.

  15. Validate your package.

    Validate your package using the Validation Suite Before you publish your package, you need to make sure that it passes all the necessary validation checks by using the Package Validation Suite extension (required). Once the Validation Suite package is installed, it will add a Validate button in the Package Manager UI's details of your installed packages. To install the extension, follow these steps:

    1. Make sure you have Package Manager UI v1.9.6 or above.
    2. Your project manifest will need to point to a staging registry for this, which you can do by adding this line to it: "registry": "https://staging-packages.unity.com"
    3. Install Package Validation Suite v0.4.0-preview.2 or above from the Package Manager UI in the All Packages section. If you can't find it there, try turning on Show preview packages in the Advanced menu.
    4. After installation, you will see a Validate button show up in the Package Manager UI, which, when pressed, will run a series of tests and expose a See Results button for additional explanation.
      1. If it succeeds, you will see a green bar with a Success message.
      2. If it fails, you will see a red bar with a Failed message.

    The validation suite is still in preview, if you come across arguable results, please discuss them on #release-management.

  16. Design Guidelines.
    1. You should follow these design guideline when creating your package

    2. Package design guidelines

    3. Unity design checklist

    4. The namespace for code in the asmdef must match the asmdef name, except the initial Unity, which should be replaced with UnityEngine or UnityEditor:

    5. Runtime codeWe should only use the Unity namespace for code that has no dependency on anything in UnityEngine or UnityEditor and instead uses ECS and other Unity-namespace systems.

  17. Add tests to your package.

    Editor tests

    • Write all your Editor Tests in Tests/Editor
    • If your tests require access to internal methods, add an AssemblyInfo.cs file to your Editor code and use [assembly: InternalsVisibleTo("Unity.[YourPackageName].Editor.Tests")]

    Playmode Tests

    • Write all your Playmode Tests in Tests/Runtime.
    • If your tests require access to internal methods, add an AssemblyInfo.cs file to your Runtime code and use [assembly: InternalsVisibleTo("Unity.[YourPackageName].RuntimeTests")]
  18. Update CHANGELOG.md.

    Every new feature or bug fix should have a trace in this file. For more details on the chosen changelog format, see Keep a Changelog.

Create a Pre-Release Package

Pre-Release Packages are a great way of getting your features in front of Unity Developers in order to get early feedback on functionality and UI designs. Pre-Release packages need to go through the publishing to production flow, as would any other package, but with diminished requirements. Here are the supported Pre-Release tags (to be used in package.json,version field), along with the requirements for each one:

Preview - ex: "version" : "1.2.0-preview"

  • Expected Package structure respected
  • Package loads in Unity Editor without errors
  • License file present - With third party notices file if necessary
  • Test coverage is good - Optional but preferred
  • Public APIs documented, minimal feature docs exists- Optional but preferred

Register your package

If you think you are working on a feature that is a good package candidate, please take a minute to fill-in this form: https://docs.google.com/forms/d/e/1FAIpQLSedxgDcIyf1oPyhWegp5FBvMm63MGAopeJhHDT5bU_BkFPNIQ/viewform?usp=sf_link.

Working with the board of dev directors and with product management, we will schedule the entry of the candidates in the ecosystem, based on technical challenges and on our feature roadmap. Don’t hesitate to reach out and join us on #devs-packman on Slack.

Share your package

If you want to share your project with other developers, the steps are similar to what's presented above. On the other developer's machine:

  1. Start Unity, create a local empty project.

  2. Launch console (or terminal) application, go to the newly created project folder, then clone your repository in the packages directory

    cd <YourProjectPath>/Packages
    git clone https://gitlab.internal.unity3d.com/upm-packages/[sub-group]/[your-package-name].git com.unity.[sub-group].[your-package-name]
    

    Note: Your directory name must be the name of your package (Example: "com.unity.terrain-builder")

All packages are required to COMPLETE AND SUBMIT THIS FORM to receive approval. It is a simple, streamlined form that tells legal if there are any potential issues that need to be addressed prior to publication.

Update Third Party Notices.md
  1. If your package has third-party elements and its licenses are approved, then all the licenses must be added to the Third Party Notices.md file. Simply duplicate the Component Name/License Type/Provide License Details section if you have more then one licenes.

    a. Concerning [Provide License Details] in the Third Party Notices.md, a URL can work as long as it actually points to the reproduced license and the copyright information (if applicable).

  2. If your package does not have third party elements, you can remove the Third Party Notices.md file from your package.

Preparing your package for Staging

Before publishing your package to production, you must send your package on the Package Manager's staging repository. The staging repository is monitored by QA and release management, and is where package validation will take place before it is accepted in production.

*** IMPORTANT: The staging repository is publicly accessible, do not publish any packages with sensitive material you aren't ready to share with the public ***

  1. Publishing your changes to the package manager's staging repository happens from Gitlab. To do so, simply setup your project's Continuous integration, which will be triggered by "Tags" on your branches.

    • Join the #devs-packman channel on Slack, and request a staging USERNAME and API_KEY.
    • In Gitlab, under the Settings-> CI/CD -> Secret Variables section, setup the following 2 project variables:
      • API_KEY = [your API KEY]
      • USER_NAME = [your USER NAME@unity]
    • You're almost done! To publish a version of your package, make sure all your changes are checked into Gitlab, then create a new tag to reflect the version you are publishing (ex. "v1.2.2"), the tag will trigger a publish to Staging. You can view progress you the publish request by switch over to the "CI / CD" part of your project.
  2. Do it yourself CI

    If you are using your own CI, it is still recommended that you use the build.sh wrapper script that comes with the starter kit, as it handle the installation of the actual CI build scripts for you.

    Instead of calling npm pack and npm publish in the package root folder in your CI, use

    ./build.sh package-ci pack --git-head $CI_COMMIT_SHA --git-url $CI_REPOSITORY_URL
    

    and

    ./build.sh package-ci publish --git-head $CI_COMMIT_SHA --git-url $CI_REPOSITORY_URL
    

    respectively.

  3. Test your package locally

    Now that your package is published on the package manager's staging repository, you can test your package in the editor by creating a new project, and editing the project's manifest.json file to point to your staging package, as such:

    dependencies: {
      "com.unity.[sub-group].[your-package-name]": "0.1.0"
    },
    "registry": "https://staging-packages.unity.com"
    

Get your package published to Production

Packages are promoted to the production repository from staging, described above. Certain criteria must be met before submitting a request to promote a package to production. The list of criteria can be found here

Once you feel comfortable that your package meets the list of Release Management Criteria, Submit your package publishing request to Release Management.

Release management will validate your package content, and check that the editor/playmode tests are passed before promoting the package to production. You will receive a confirmation email once the package is in production.

You're not done! At this point, your package is available on the cloud, 2 more steps are required to make your package discoverable in the editor:

  1. Contact the Package Manager team in #devs-packman to ask them to add your package to the list of discoverable package for the Unity Editor. All you need to provide is the package name (com.unity.[sub-group].[your-package-name])
  2. If your package is meant to ship with a release of the editor (Unity Recommended Packages), follow these steps:
    • Modify the editor manifest [root]\External\PackageManager\Editor\Manifest.json to include your package in the list of dependencies.
    • Submit one or more Test Project(s) in Ono, so that your new package can be tested in all ABVs moving forward. The following steps will create a test project that will run in ABVs, load your package into the project, and run all the tests found in your package. The better your test coverage, the more confident you'll be that your package works with trunk.
      • Create a branch in Ono, based on the latest branch this package must be compatible with (trunk, or release branch)
      • If your package contains Editor Tests:
        • In [root]\Tests\Editor.Tests, create a new EditorTest Project (for new packages use YourPackageName) or use an existing project (for new versions of existing package).
        • A skeleton of EditorTest Project can be found here.
        • Modify the project’s manifest.json file to include the production version of the package (name@version).
        • Your project's manifest.json file should contain the following line: "testables" : [ "com.unity.[sub-group].[your-package-name]" ]
      • If your package contains PlaymodeTests:
        • In [root]\Tests\PlaymodeTests, create a new PlaymodeTest Project (for new packages use YourPackageName) or use an existing project (for new versions of existing package).
        • Modify the project’s manifest.json file to include the staging version of the package (name@version).
        • Your project's manifest.json file should contain the following line: "testables" : [ "com.unity.[sub-group].[your-package-name]" ].
        • Commit your branch changes to Ono, and run all Windows & Mac Editor/PlayMode tests (not full ABV) in Katana.
    • Once the tests are green on Katana, create your PR, add both Latest Release Manager and Trunk Merge Queue as reviewers.

FAQ

What’s the difference between a preview package and a verified package?

A preview package is a great way to develop and get feedback on new features and functionality. Preview package can be created against any version of Unity 2018.1+, and can be made discoverable through the Package Manager UI by issuing a request in #devs-packman. Quality and release schedule is up to the package owner, although minimum bars are set in place to ensure the package contains the right licenses, documentation, and a comprehensive set of tests.

Once a preview package has been in the field for 2-3 release cycles of the editor, that package can be considered for Verification. Verified packages are tested with a specific version of the editor, and offer our users a compatibility guarantee. Verified packages are the only packages that can be included in the set of templates we ship with the editor (Verified Templates). Code for these packages must follow core development guidelines, including code cutoff dates, and are tested in katana for continued compatibility.

What’s the difference between a core package and a default package?

A core package is a package that has its code included with the Editor’s core code. This is interesting for packages that plan to change enormously in parallel to editor APIs. By moving package code to the editor’s repo, both core API\functionality changes can be made along with required packages changes in the same PR. https://docs.google.com/document/d/1CMoanjR3KAdew-6n39JdCFmHkTp1oshs3vkpejapf4Q/edit

A default package is a verified packages that gets installed with every new project users create, regardless of the template they use. We should limit the number of default packages we support, as each default package adds to the project loading time. The list of default packages can be found in the editor manifest (de904b9e/External/PackageManager/Editor/manifest.json).

What are the requirement for me to publish a preview package?

https://docs.google.com/document/d/1epGkAJRayJLN89_weA_-G5LFT_1uFifFZqBzAgvp_Zs/

What are the requirements for me to get my package verified for a version of unity?

https://docs.google.com/document/d/1oWC9XArVfkGMnqN9azR4hW4Pcd7-kQQw8Oy7ckP43JE/

How is my verified package tested in Katana?

https://docs.google.com/document/d/1jwTh71ZGtB2vF0SsHEwivt2FunaJWMGDdQJTpYRj3EE/edit

How is my template tested in Katana?

https://docs.google.com/document/d/1jwTh71ZGtB2vF0SsHEwivt2FunaJWMGDdQJTpYRj3EE/edit

How do I add samples to my package?

https://docs.google.com/document/d/1rmxGh6Z9gtbQlGUKCsVBaR0RyHvzq_gsWoYs6sttzYA/edit#heading=h.fg1e3sz56048

How can I add tests to my package?

There’s a “Tests” directory in the package starter kit. If you add editor and playmode tests in that directory, they will make up the list of tests for your package.

The tests in my package bloat my package too much, what are my options?

https://docs.google.com/document/d/19kKIGFetde5ES-gKXQp_P7bxQ9UgBnBUu58-y7c1rTA/edit

Can I automate my package publishing yet?

Not just yet, but we’re working on it. The first automated publishing we will enable is the push to production for preview packages. Basically, when your package passes validation (loads in the editor without error, the tests in the package pass, validation suite run success), the package will be pushed to production automatically. Other publishing flows will soon be available as well, here’s the full list of internal package publishing flows Unity will support. https://docs.google.com/document/d/1zdMzAtfi-vgM8NMPmwL40yinBeL3YImwTO5gSfGNCgs/edit

How do I get a template package started?

Start with the Project Template Starter Kit (you can request access in #devs-packman). https://gitlab.internal.unity3d.com/upm-packages/project-templates/project-template-starter-kit

How do I get my package included in a template?

First and foremost, your package needs to be on the verified list of packages. Only verified packages can get added to templates we ship with the editor. Then reach out to the templates community in #devs-template to open discussions on adding your package to one or more of our existing templates.

How can I test my package locally, as a user would?

https://confluence.hq.unity3d.com/display/PAK/How+to+add+a+git+package+to+your+project

What tests are included by the validation suite?

https://docs.google.com/spreadsheets/d/1CdO7D0WSirbZhjnVsdJxJwOPK4UdUDxSRBIqwyjm70w/edit#gid=0