unity-package-installer

0.3.1 • Public • Published

unity-package-installer

A lightweight utility for installing npm packages into a unity project.

Background

This utility was inspired and informed by the work done by shadowmint; many thanks to him for blazing the trail. This utility encapsulates the boilerplate of installing packages into a Unity3D project.

Usage

Add unity-package-installer as a dependency to your package.json file. Information on the latest version can be found here.

"dependencies"{
  "unity-package-installer": ">=0.3.0"
},

Automatic installation of packages

To subscribe to automatic installation of your package into a unity project after npm install, add a unity_package_installer config.

"config"{
  "unity_package_installer": {
    "source": "Source",
    "path": "Test Module"
  }
}
  • source: A relative path to the folder to install in your unity project
  • path: The name of the folder in unity to install to; if not provided then your package name will be used instead.

Manual installation of packages

You may elect to control installing your package via a post install script of your own.

"scripts"{
  "postinstall": "node scripts/postinstall.js"
},

The following example will copy the contents of sourceFolder into Assets/Packages/My Unity Package.

const PACKAGE_NAME = 'My Unity Package';
 
var installer = require('unity-package-installer');
var path = require('path');
 
// set the package source to ./../Files/My Unity Package/Source
var sourceFolder = path.join(__dirname, '..', 'Files', PACKAGE_NAME, 'Source');
 
// install the source into unity
installer.install(sourceFolder, PACKAGE_NAME, callback);
 
// optional callback
function callback(err, dir) {
  // err - an error which occurred while trying to install your package
  // dir - the directory within the unity project that was source copied to
}

As demonstrated, you may provide a callback to the installer if you want/need to perform additional actions after your files are copied into your project.

Enhancements

I plan on using this utility with something I'm developing now, and already have a few improvements in mind. If you think of any, please feel free to create an issue!

Bug reports

Please, file an issue if you notice anything not working as you think it should.

Readme

Keywords

Package Sidebar

Install

npm i unity-package-installer

Weekly Downloads

3

Version

0.3.1

License

MIT

Last publish

Collaborators

  • wallyworld