Last active
August 9, 2023 22:13
-
-
Save TiborUdvari/401e9053f64d5218ccd6d5b6412535d9 to your computer and use it in GitHub Desktop.
Unity Editor Script that increments build number for iOS builds
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
using UnityEngine; | |
using UnityEditor.Build; | |
using UnityEditor.Build.Reporting; | |
using UnityEditor; | |
public class IncrementBuildNumber : IPreprocessBuildWithReport | |
{ | |
public int callbackOrder { get { return 0; } } // Part of the IPreprocessBuildWithReport interface | |
public void OnPreprocessBuild(BuildReport report) | |
{ | |
if (report.summary.platform == BuildTarget.iOS) // Check if the build is for iOS | |
{ | |
// Increment build number if proper int, ignore otherwise | |
int currentBuildNumber; | |
if (int.TryParse(PlayerSettings.iOS.buildNumber, out currentBuildNumber)) | |
{ | |
string newBuildNumber = (currentBuildNumber + 1).ToString(); | |
Debug.Log("Setting new iOS build number to " + newBuildNumber); | |
PlayerSettings.iOS.buildNumber = newBuildNumber; | |
} | |
else | |
{ | |
Debug.LogError("Failed to parse build number " + PlayerSettings.iOS.buildNumber + " as int."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment