If for whatever reason you need to make a custom updater, here is how. Updaters as the name suggests update the numbers when the versioning system is in use. These are modular so you can add your own easily without needing to edit anything outside of your addition.
๐บ Build Updater
To add one, add a new script into an editor folder and call it whatever you want.
When compiled, implement the IBuildUpdater
interface. This contains a single method called OnBuildVersionIncremented()
with BuildTarget
as a parameter. Along with an int
property to define the order it should run in, set this to 0 if you donโt need the updated version number, greater than 0 if you do. You then add your implementation inside of this method to update the build number.
Example below of the android bundle code updater:
public int UpdateOrder => 0;
public void OnBuildVersionIncremented(BuildTarget buildTarget)
{
if (buildTarget != BuildTarget.Android) return;
if (BuildVersionsEditorUtil.BuildOptions.androidUpdateBundleCode == AssetUsageType.Disabled) return;
if (!BuildHandler.Get<AndroidBundleCodeUpdater>().Choice) return;
PlayerSettings.Android.bundleVersionCode++;
}
๐ Syncable Updater
To make your update sync with the sync options, implement the ISyncable
interface. This contains a single method called OnVersionSync()
with a string
as a parameter which will be the version number in string form to sync to.
Below is an example from a game analytics updater:
public void OnVersionSync(string version)
{
for (var i = 0; i < GameAnalytics.SettingsGA.Build.Count; i++)
{
GameAnalytics.SettingsGA.Build[i] = version;
}
}
๐ฌ Pre-Build Dialogue Extension
This allows you to add a dialogue box ahead of the build starting to help control whether the updater will function. If you wish to use this them implement the IPreBuildDialogue
interface. This contains a method called OnPreBuildDialogue()
with BuildTarget
as a parameter. Then implement the relevant logic for the dialogue box, using EditorUtility.DisplayDialog
https://docs.unity3d.com/ScriptReference/EditorUtility.DisplayDialog.html
You should register the result of this choice with the BuildHandler
if you need to use its result. Which you likely will. To do this just call the Register method on the BuildHandler
class and enter a new instance of the HandlerDialogueData
struct, passing in the class name as the id & the result as the value.
You can get the class name via typeof(T).Name
or via BuildVersionsEditorUtil.GetClassName
. The id needs to be the class name for the system to work, as youโd only have one result per class that implements the interface for dialogue boxes.
Then to get the result in another method such as the build updater interface method, you use the BuildHandler.Get
method entering the class type in <> brackets and then using the choice from that method to which will be the choice the user made from the dialogue box that build. An example from the android bundle code updater below:
An example from the android bundle code updater:
public void OnPreBuildDialogue(BuildTarget target)
{
if (target != BuildTarget.Android) return;
if (BuildVersionsEditorUtil.BuildOptions.androidUpdateBundleCode != AssetUsageType.PromptMe)
{
BuildHandler.Register(new HandlerDialogueData(BuildVersionsEditorUtil.GetClassName<AndroidBundleCodeUpdater>(), true));
return;
}
var currentBundleCode = PlayerSettings.Android.bundleVersionCode;
var choice = EditorUtility.DisplayDialog("Build Versions | Android Bundle Code Updater",
$"Do you want to increment the bundle code for this build?\n\nThis will update the code from {currentBundleCode} to {currentBundleCode + 1}.\n\nYou can disable this prompt in the asset settings.",
$"Yes (Set to {currentBundleCode + 1})", $"No (Leave as {currentBundleCode})");
BuildHandler.Register(new HandlerDialogueData(BuildVersionsEditorUtil.GetClassName<AndroidBundleCodeUpdater>(), choice));
}