Created
February 11, 2020 01:37
-
-
Save benshippee/0b1446287517aa44a675c86c0711c2bf to your computer and use it in GitHub Desktop.
Unity build post process script to automatically bump iOS and Android version numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
using UnityEditor; | |
using UnityEditor.Callbacks; | |
using UnityEngine; | |
public class BuildNumberIncrementer | |
{ | |
[PostProcessBuild] | |
public static void OnBuildComplete(BuildTarget buildTarget, string pathToBuiltProject) | |
{ | |
IncrementBuildNumber(buildTarget); | |
} | |
private static void IncrementBuildNumber(BuildTarget buildTarget) | |
{ | |
switch (buildTarget) | |
{ | |
case BuildTarget.iOS: | |
BumpiOSBuildNumber(); | |
break; | |
case BuildTarget.Android: | |
BumpAndroidBuildNumber(); | |
break; | |
default: | |
break; | |
} | |
} | |
private static void BumpiOSBuildNumber() | |
{ | |
var buildNumberString = PlayerSettings.iOS.buildNumber; | |
int buildNumber; | |
if (int.TryParse(buildNumberString, out buildNumber)) | |
{ | |
PlayerSettings.iOS.buildNumber = (buildNumber + 1).ToString(); | |
Debug.Log("Bumped iOS Build Number to " + PlayerSettings.iOS.buildNumber); | |
AssetDatabase.SaveAssets(); | |
} | |
} | |
private static void BumpAndroidBuildNumber() | |
{ | |
var buildNumber = PlayerSettings.Android.bundleVersionCode; | |
PlayerSettings.Android.bundleVersionCode = buildNumber + 1; | |
Debug.Log("Bumped Android Bundle Version Code to " + PlayerSettings.Android.bundleVersionCode); | |
AssetDatabase.SaveAssets(); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment