Version: 2023.2
public static string buildNumber ;

描述

捆绑包的版本号

系统会将该版本号保存到“CFBundleVersion”字段(位于构建的应用程序的 info.plist 文件中)。

                        
using UnityEngine;
using UnityEditor;

public class BuildNumberExample { // This example will create a Menu Item called "Increase Minor Build Number" under "Examples" submenu which when pressed will get the current "Build" property and increase the Minor version by 1 // Assuming the "Build" property follows the format Major.Minor.Patch (for example 2.0.5 will be increased to 2.1.0), [MenuItem("Examples/Increase Minor Build Number")] public static void IncreaseMinorBuildNumber() { // Get the current build number value string currentBuildNumberString = PlayerSettings.iOS.buildNumber;

// Separate the build number string to Major, Minor and Patch numbers string[] separatedBuildNumbers = currentBuildNumberString.Split('.');

// Parse the Major and Minor version numbers to integer values int majorVersionNumber = int.Parse(separatedBuildNumbers[0]); int minorVersionNumber = int.Parse(separatedBuildNumbers[1]);

// Increment the Minor version number minorVersionNumber++; // Update the buildNumber property with the new values: // - keep the old Major version number; // - update Minor version number; // - replace Patch version number with 0, since Minor version was updated. PlayerSettings.iOS.buildNumber = string.Format("{0}.{1}.{2}", majorVersionNumber, minorVersionNumber, 0); } }