Created
January 28, 2016 08:48
-
-
Save liortal53/7d0e0061195ff06072e2 to your computer and use it in GitHub Desktop.
Unity: Auto increment iOS build number post build
This file contains hidden or 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 System.IO; | |
using System.Linq; | |
using UnityEditor; | |
using UnityEditor.Callbacks; | |
using UnityEditor.iOS.Xcode; | |
using UnityEngine; | |
public static class PostBuildHelper | |
{ | |
[PostProcessBuild] | |
public static void OnBuildComplete(BuildTarget buildTarget, string pathToBuiltProject) | |
{ | |
if (buildTarget != BuildTarget.iOS) | |
{ | |
return; | |
} | |
IncrementBuildNumber(); | |
} | |
private static void IncrementBuildNumber() | |
{ | |
// Load the PlayerSettings asset. | |
var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>().FirstOrDefault(); | |
if (playerSettings != null) | |
{ | |
SerializedObject so = new SerializedObject(playerSettings); | |
// Find the build number property. | |
var sp = so.FindProperty("iPhoneBuildNumber"); | |
var currentValue = sp.stringValue; | |
int ver = 0; | |
if (int.TryParse(currentValue, out ver)) | |
{ | |
// Increment version. | |
sp.stringValue = (ver + 1).ToString(); | |
// Save player settings. | |
so.ApplyModifiedProperties(); | |
AssetDatabase.SaveAssets(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment