48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using UnityEditor;
|
|
using UnityEditor.Build;
|
|
using UnityEditor.Build.Reporting;
|
|
using UnityEngine;
|
|
using UnityEditor.Callbacks;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
namespace BITKit
|
|
{
|
|
class BuildVersionProcessor : IPreprocessBuildWithReport
|
|
{
|
|
private bool autoIncreamentBuildVersion = true;
|
|
|
|
public int callbackOrder { get { return 0; } }
|
|
public void OnPreprocessBuild(BuildReport report)
|
|
{
|
|
//Debug.Log("MyCustomBuildProcessor.OnPreprocessBuild for target " + report.summary.platform + " at path " + report.summary.outputPath);
|
|
if (autoIncreamentBuildVersion) { IncrementVersion(); }
|
|
}
|
|
|
|
[MenuItem("File/Manually Increment Build Version", priority = 1)]
|
|
public static void ButtonIncrementVersion()
|
|
{
|
|
Debug.Log("Button Increment Version called.");
|
|
IncrementVersion();
|
|
}
|
|
|
|
private static void IncrementVersion()
|
|
{
|
|
string versionCurrent = Application.version;
|
|
string[] versionParts = versionCurrent.Split('.');
|
|
|
|
if (versionParts != null && versionParts.Length > 0)
|
|
{
|
|
int versionIncremented = int.Parse(versionParts[versionParts.Length - 1]);
|
|
versionIncremented += 1;
|
|
versionParts[versionParts.Length - 1] = versionIncremented.ToString();
|
|
PlayerSettings.bundleVersion = string.Join(".", versionParts);
|
|
|
|
Debug.Log("Version: " + versionCurrent + " increased to: " + PlayerSettings.bundleVersion);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Version has no data, check Unity - Player Settings - Version, input box at top.");
|
|
}
|
|
}
|
|
}
|
|
} |