So Robert Yang posted a decent guide on how to ‘sub-project’ your Unity projects so they can share a common code-base easily. This does what it needs to do pretty well, you can easily add to and maintain your own framework, and build individual games on top of it. This, as he warns, comes with some complications. You have to juggle different build/player/editor/project settings, each game’s /Resources folder will be included with every build, and you need to manage an ever-growing script base. I manage my shared code a different way, though the magic of Git submodules.
(Note: This method needs a non-Unity version control, so you need Unity Pro to make it work without freaking out. If you’re flying solo you might be able to get by with Unity Indie, but you’ve been warned)
Essentially, I do the complete opposite of Robert’s subproject system. I’ve built up a small set of useful ‘plugins’, mostly code but also models, shaders and materials. I keep each of these separate, and add them to specific games where needed. Then, if I update a plugin while working on a game, I can push the useful changes back to the ‘master’ plugin and get the updates in all the games that use them. You can do this outside of version control (with Unity packages), but you need to be disciplined about keeping the master updated, or changes within each game will become too unwieldy to merge together again. Git submodules let you pull and push changes back and forth between the master easily, while handling changes and merges automatically (mostly).
You’re all using some sort of version control, right? You already know you should, so I’m not going to go over the many many reasons why. I use and recommend Git. Other version control systems may have something similar to Git submodules (notably SVN’s sub-projects), but I’m not familiar with their utility.
Git submodules aren’t without their flaws. Most of all, they’re delicate little flowers that break at the drop of a mistyped terminal command. They work in a confusing way, and it can be difficult to understand just what’s happening. That said, if you use them you have to use Git, which makes it hard to really fuck up a project if things go wrong.
I think I need to put a detailed guide up at some point, on this and other Unity + Git best-practices… Until then, shoot if you have any questions!