Created
May 4, 2019 14:52
-
-
Save SradnickDev/8a3e509bae05cc46948d98800cbd8e60 to your computer and use it in GitHub Desktop.
Auto Increment Version (Unity 3D 2019)
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
#if UNITY_EDITOR | |
using UnityEditor; | |
using UnityEditor.Build; | |
using UnityEditor.Build.Reporting; | |
using UnityEngine; | |
public class AutoVersion : IPreprocessBuildWithReport | |
{ | |
public int callbackOrder | |
{ | |
get { return 0; } | |
} | |
public void OnPreprocessBuild(BuildReport report) | |
{ | |
IncreaseBuildNumbers(); | |
} | |
private void IncreaseBuildNumbers() | |
{ | |
try | |
{ | |
//Example : current BuildVersion 1.9.9 | |
// after build process new Build Version is 2.0.1 | |
string[] bundleVersionSplit = PlayerSettings.bundleVersion.Split('.'); | |
var n1 = int.Parse(bundleVersionSplit[0]); | |
var n2 = int.Parse(bundleVersionSplit[1]); | |
var n3 = int.Parse(bundleVersionSplit[2]); | |
if (n2 == 9) | |
{ | |
n2 = 0; | |
n1 += 1; | |
} | |
if (n3 == 9) | |
{ | |
n3 = 0; | |
n2 = 0; | |
} | |
n3 += 1; | |
var buildVersion = n1 + "." + n2 + "." + n3; | |
var buildNumber = int.Parse(PlayerSettings.macOS.buildNumber) + 1; | |
PlayerSettings.bundleVersion = buildVersion; | |
PlayerSettings.macOS.buildNumber = buildNumber.ToString(); | |
Debug.Log("Build Version : " + buildVersion); | |
Debug.Log("Build Number : " + buildNumber); | |
} | |
catch (System.Exception ex) | |
{ | |
Debug.LogException(ex); | |
} | |
} | |
} | |
#endif |
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
#if UNITY_EDITOR | |
using UnityEditor; | |
using UnityEditor.Build; | |
using UnityEditor.Build.Reporting; | |
using UnityEngine; | |
public class AutoVersion : IPreprocessBuildWithReport | |
{ | |
public int callbackOrder | |
{ | |
get { return 0; } | |
} | |
public void OnPreprocessBuild(BuildReport report) | |
{ | |
IncreaseBuildNumbers(); | |
} | |
private void IncreaseBuildNumbers() | |
{ | |
try | |
{ | |
//Example : current BuildVersion 1.9.9 | |
// after build process new Build Version is 2.0.1 | |
string[] bundleVersionSplit = PlayerSettings.bundleVersion.Split('.'); | |
var n1 = int.Parse(bundleVersionSplit[0]); | |
var n2 = int.Parse(bundleVersionSplit[1]); | |
var n3 = int.Parse(bundleVersionSplit[2]); | |
if (n2 == 9) | |
{ | |
n2 = 0; | |
n1 += 1; | |
} | |
if (n3 == 9) | |
{ | |
n3 = 0; | |
n2 = 0; | |
} | |
n3 += 1; | |
var buildVersion = n1 + "." + n2 + "." + n3; | |
var buildNumber = int.Parse(PlayerSettings.macOS.buildNumber) + 1; | |
PlayerSettings.bundleVersion = buildVersion; | |
PlayerSettings.macOS.buildNumber = buildNumber.ToString(); | |
Debug.Log("Build Version : " + buildVersion); | |
Debug.Log("Build Number : " + buildNumber); | |
} | |
catch (System.Exception ex) | |
{ | |
Debug.LogException(ex); | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment