Unity-Package-Template
Unity-Package-Template copied to clipboard
Template Unity Package for OpenUPM and NPMJS. Supports UPM (Unity Package Manager) with versioning.
Unity Package Template
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
- ✔️ NPMJS
- ✔️ OpenUPM
- ✔️ GitHub Packages
- ✔️ UPM (Unity Package Manager)
Unity Package Creation
- 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/_PackageRootfolder. 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
namein formatmy.packge.name.hello.world - change
displayName,version,descriptionto any - change
unityto 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
LICENSEfile
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.batand 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
versioninpackage.jsonfile. Versions lower than1.0.0gonna be shown in Unity as "preview" - Execute the script in Unity project
npmPublish.batto 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

