Easily export a folder of scripts and assets as a local Unity 2018 package for use with the new Package Manager.
- Exporting packages in a format that the Unity package manager seems to like.
- Some basic validation for the files inside the package and for fields of the package.json
- Odin Inspector (not included)
How to use
- Put the PackageExporter script somewhere in your project, ideally in an Editor folder.
- Gather the assets and scripts you want to package in one folder (make sure you add an assembly definition for scripts). You can add subfolders to that folder, just make sure that the Package Exporter asset is at the root.
- Add a Package Exporter asset to that folder (right click > Create > Package Exporter).
- Fill in the fields and click Export Package!
The package(s) can now be found at the root of your project in a newly created folder called ExportedPackages. The tool will automatically create folders for each package, for each version, and also for each export of the same folder. It should not overwrite a previous export!
In Unity 2018.3 you can add a package to another project by using the + button on the Package Manager window.
This will add the package path to the manifest file in the Packages folder in your project root
As you can see it points to a local full path. This is not ideal if you’re not the only developer on the project. It does seem that you can use your own npm registry. However that’s beyond the scope of this tool (at least for now).
- AudioClips wouldn’t import from a package, so you can’t export packages with AudioClips in them.
- Currently the tool only spits out a package for local use. I don’t know what is gonna happen if you’d put it on a server or something. The generated package.json is easy enough to edit by hand, though.
- I have not tested it on an OS other than macOS Mojave.
- I have not tested it with large files or folders.
- I have only tested it on Unity 2018.3, will probably work on an earlier version though. But maybe not?
- I have only tested it with scripts, a few textures and an AudioClip.
- I’m not sure what will happen if you move the Package Exporter asset around.
- I have no idea if this thing is performant, but it seems fast enough.
- Consider this thing untested!!
- Lastly, I’m not sure what will happen if you include this in a project that’s meant for deployment. I made this so I can easily export my tools and extensions to a package, so I can use those things in other projects. In my usecase this script will never find its way into an actual project.
- Make the validation more intelligent and expandable.
- Test some more
- Maybe add dependencies to the package.json generation
- Unity editor version field validation?