We had a partner support question on good practises when using shared code across multiple projects (related GitHub request here: https://github.com/playcanvas/editor/issues/340)
At the moment, they are doing ‘one scene per game’ which has it’s own problems with project management and preloading assets as not all assets are needed for all games and script loading order only works for preloaded scripts.
This was my reply:
I will split this email into two to help keep the two conversations separate:
I’ve not done this before but the ways I would think of doing this would be the following:
- Single project, one game per branch approach
The shared SDK would be in the master branch and then there would be a branch per game. Changes to the SDK would be made against the master branch and then it can be merged upstream to the game branches as needed.
Each branch then could be configured as needed without the ‘weight’ of the other games. The version control graph view and careful naming of branches should help with management.
- Copy and paste between projects
If the SDK is just code script files, then the SDK can be in a separate project and the files are copied over as needed.
- Keep the current one game per scene format and use Editor API
If you would like to keep the current format then I would tag all scripts with the game name they are associated with. I would then also write some Editor API tool/code/functionality that would untick and tick preload on the scripts for the game that is being published.
- Keep the current one game per scene format and use a build post processing script
Same as above where the scripts are tagged with the game that they are for. Using the REST API, download the build with scripts not concatenated (so they are separated files) and then process the build that you create your own
__game-script.js file based on the game and tags and change the
config.json so that the included scripts are preloaded.
You will need to minify manually and also get the scripts order from the project export
project.json file where there is a property
scripts that has the order by asset id.
Out of the above options, I would more likely prefer 1. or 2. Having each game in a single scene where all the assets from all games are together feels like it could be a maintenance issue where one developer from another game can affect the others quite easily.