Skip to content

Template Unity Package for OpenUPM and NPMJS. Supports UPM (Unity Package Manager) with versioning.

License

Notifications You must be signed in to change notification settings

IvanMurzak/Unity-Package-Template

Repository files navigation

Unity Package Template

Stats

UPM (Unity Package Manager) ready GitHub repository for Unity. Unity package system is very easy to use and to make your project much cleaner. The repository helps you to create your own Unity package with dependencies.

This is a template repository for fast package creation for Unity which can be imported to Unity project through Package Manager in Unity Editor. The repository is universal for Package Creation and Publishing cycles.

Supported

Unity Package Creation

image

  • Create your own repository on GitHub using this repository as a template. Press the green button one line above.
  • Clone freshly created repository and open in Unity
  • Put files that should be packed into the package under Assets/_PackageRoot folder. Everything outside the folder could be used for testing or demonstrating your plugin
>> Detailed data structure in package root folder

Unity guidlines about organizing files into the package root directory

  <root>
  ├── package.json
  ├── README.md
  ├── CHANGELOG.md
  ├── LICENSE.md
  ├── Third Party Notices.md
  ├── Editor
  │   ├── [company-name].[package-name].Editor.asmdef
  │   └── EditorExample.cs
  ├── Runtime
  │   ├── [company-name].[package-name].asmdef
  │   └── RuntimeExample.cs
  ├── Tests
  │   ├── Editor
  │   │   ├── [company-name].[package-name].Editor.Tests.asmdef
  │   │   └── EditorExampleTest.cs
  │   └── Runtime
  │        ├── [company-name].[package-name].Tests.asmdef
  │        └── RuntimeExampleTest.cs
  ├── Samples~
  │        ├── SampleFolder1
  │        ├── SampleFolder2
  │        └── ...
  └── Documentation~
       └── [package-name].md

Edit Assets/_packageRoot/package.json

Required steps

  • change name in format my.packge.name.hello.world
  • change displayName, version, description to any
  • change unity to setup minimum supported Unity version

Optional steps

  • add yourself as an author in format "author": { "name": "Ivan Murzak", "url": "https://github.com/IvanMurzak" },
  • advanced editing and format package.json - read more about NPM package format here
  • don't forget to update LICENSE file

Publishing

There are many platforms to publish your Package. You can read more about all alternative variants and their pros and cons here (OPTIONAL). This tutorial is targeted on NPMJS deployment.

Preparation (just once)

  • Install NPM
  • Create NPMJS account
  • Execute script in Unity project npmAddUser.bat and sign-in to your account
>> npmAddUser.bat script content

It executes npm adduser command in the package root folder

cd Assets/_PackageRoot
npm adduser

Deploy

Make sure you finished editing package.json and files in Assets/_PackageRoot folder. Because it is going to be public with no ability to discard it

  • Don't forget to increment version in package.json file. Versions lower than 1.0.0 gonna be shown in Unity as "preview"
  • Execute the script in Unity project npmPublish.bat to publish your package to the public
>> npmPublish.bat script content

The first line in the script copies the README.md file to the package root. Because the README should be in a package also, that is a part of the package format. It executes npm publish command in the package root folder. The command publishes your package to the NPMJS platform automatically

xcopy .\README.md .\Assets\_PackageRoot\README.md /y
cd Assets\_PackageRoot
npm publish
pause

Installation

When your package is distributed, you can install it into any Unity project.

  • Install OpenUPM-CLI
  • Open the command line in the Unity project folder
  • openupm --registry https://registry.npmjs.org add YOUR_PACKAGE_NAME

Final view in Package Manager

image

About

Template Unity Package for OpenUPM and NPMJS. Supports UPM (Unity Package Manager) with versioning.

Topics

Resources

License

Stars

Watchers

Forks