- Home /
What's the best way to execute different code for itch.io build v.s. macOS App Store build?
I'm releasing my macOS game both on itch.io and the macOS App Store.
I want to execute different code for each of them, for example, a button to open the store page that lists the game itself. One needs to open the itch.io link, the other the macOS App Store link.
My current solution is to use #define symbols: set ITCH_IO_BUILD or MACOS_APP_STORE_BUILD in Scripting Define Symbols of Player Settings.
But this requires me to remember and change the settings without typos every time I build the app, twice. Is there a better way?
Answer by hexagonius · Dec 10, 2018 at 07:42 AM
sure, atomate it. in general, whenever you know you'll be doing things more than once, think about scripting:
react to platform switches:
https://docs.unity3d.com/ScriptReference/Build.IActiveBuildTargetChanged.OnActiveBuildTargetChanged.html. change symbols by code: https://docs.unity3d.com/ScriptReference/PlayerSettings.SetScriptingDefineSymbolsForGroup.html
But both of the itch.io & App Store macOS build is only one single build target (macOS standalone), I still need to change the script every time I build for those two.
You can make yourself a build button for each store front. and set the Scripting defines via code before executing the build command. You just have to remember to use your custome build buttons and you never have to change the defines yourself.