|
|
@@ -0,0 +1,51 @@
|
|
|
+using UnityEngine;
|
|
|
+using UnityEditor;
|
|
|
+using UnityEditor.Build;
|
|
|
+using UnityEditor.Build.Reporting;
|
|
|
+
|
|
|
+//版本号递增
|
|
|
+class BuildVersionProcessor : IPreprocessBuildWithReport
|
|
|
+{
|
|
|
+ //是否在构建时触发BuildVersion递增
|
|
|
+ private bool autoIncreamentBuildVersion = false;
|
|
|
+ public int callbackOrder { get => 0; }
|
|
|
+
|
|
|
+ public void OnPreprocessBuild(BuildReport report)
|
|
|
+ {
|
|
|
+ if (autoIncreamentBuildVersion) IncrementVersion();
|
|
|
+ }
|
|
|
+
|
|
|
+ [MenuItem("File/手动递增 Build Version", priority = 1)]
|
|
|
+ public static void ButtonIncrementVersion()
|
|
|
+ {
|
|
|
+ IncrementVersion();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void IncrementVersion()
|
|
|
+ {
|
|
|
+ string versionCurrent = Application.version;
|
|
|
+ string[] versionParts = versionCurrent.Split('.');
|
|
|
+
|
|
|
+ if (versionParts != null && versionParts.Length > 0)
|
|
|
+ {
|
|
|
+ int versionNumber = int.Parse(string.Join("", versionParts));
|
|
|
+ versionNumber += 1;
|
|
|
+ char[] versionNumberChars = versionNumber.ToString().ToCharArray();
|
|
|
+ string versionText = string.Join(".", versionNumberChars);
|
|
|
+ PlayerSettings.bundleVersion = versionText;
|
|
|
+ Debug.Log("Build Version " + versionCurrent + " => " + PlayerSettings.bundleVersion);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log("Version has no data, check Unity - Player Settings - Version, input box at top.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [MenuItem("File/手动递增 Android Version Code", priority = 1)]
|
|
|
+ public static void ButtonIncrementAndroidVersionCode()
|
|
|
+ {
|
|
|
+ int oldVersionCode = PlayerSettings.Android.bundleVersionCode;
|
|
|
+ PlayerSettings.Android.bundleVersionCode = oldVersionCode + 1;
|
|
|
+ Debug.Log("Android Version Code " + oldVersionCode + " => " + PlayerSettings.Android.bundleVersionCode);
|
|
|
+ }
|
|
|
+ }
|