I created this as a pre-build script, but I’d like to know if there’s a better way to achieve this. The script modifies the value of disableAllRemoteConnections based on the DisableAllRemoteConnections environment variable, using a generated C# script."
Can someone help me? I would greatly appreciate any advice.
Write a small C# console application to do all this.
Create a template .cs file and then simply call scriptContents.Replace("$PLACEHOLDER$", "actual content") to replace only what needs replacing.
This script looks like you can entirely write this in Unity as a build script. You’d merely have to toggle the config asset flag and then build.
Note: use AssetDatabase.SaveAssetIfDirty(backendConfig) to save just that file rather than calling SaveAssets (equivalent to File - Save Project).
Yes, that’s great advice, thank you!
But I need this script to run in Unity Remote Builds and they ask for this sort of build script so I can use the env variables.
Am I missing something?
So is this script working or not? Initially you just asked if there’s a “better way”. If it’s working, it’s fine. But if it isn’t working please let us know what exactly fails.
As to better way: keep this script entirely in the project. Use the batch file to only create or delete a file, perhaps name it exactly like the env variable. When the project opens, use InitializeOnLoadMethod to check File.Exists() and depending on that, you toggle the bool in the asset.
Yeah, the previous code didn’t work, so I managed to do it another way by writing only a batch script. I know it’s not the prettiest code, but it works.