Created
May 15, 2018 09:36
-
-
Save rstecca/766bc7ebe158b56e35ccbcc17f593dd7 to your computer and use it in GitHub Desktop.
Increment version number on build (Unity/iOS)
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
/* | |
From Derek Arndt's tweet | |
https://twitter.com/derekarndt/status/993994998084354048 | |
*/ | |
using UnityEditor; | |
using UnityEditor.Build; | |
using System.Diagnostics; | |
public class BuildAndIncrementVersionNumber : IPostprocessBuild | |
{ | |
public int callbackOrder { get { return 0; } } | |
public void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) | |
{ | |
//Debug.Log("post processing build"); | |
#if UNITY_IOS | |
string buildStr = PlayerSettings.i0S.buildNumber; | |
string[] splitBuildStr = buildStr.Split('.'); | |
if (splitBuildStr.Length != 2) | |
return; | |
int buildNuml = Parselnt(splitBuildStr[0]); | |
int buildNum2 = Parselnt(splitBuildStr[1]); | |
PlayerSettings.iOS.buildNumber = buildNuml.ToString() + "." + (buildNum2 + 1).ToString(); | |
#endif | |
} | |
static public int Parselnt(object obj) | |
{ | |
if (obj == null) | |
return 0; | |
int outlnt; | |
bool couldParse = System.Int32.TryParse(obj.ToString(), out outlnt); | |
if (couldParse) return outlnt; | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment