using UnityEngine.UIElements;
public class BuildNumberSetter : EditorWindow
private int majorVersion = 1;
private int minorVersion = 0;
private int patchVersion = 0;
[MenuItem("Tools/Set Build Number")]
public static void ShowWindow()
GetWindow<BuildNumberSetter>("Set Build Number");
GUILayout.Label("Set Build Number", EditorStyles.boldLabel);
GUILayout.BeginVertical("box");
GUILayout.Label("Version Number", EditorStyles.largeLabel);
GUILayout.BeginHorizontal();
GUILayout.Label("v", GUILayout.Width(10));
majorVersion = EditorGUILayout.IntField(majorVersion, GUILayout.Width(30));
GUILayout.Label(".", GUILayout.Width(5));
minorVersion = EditorGUILayout.IntField(minorVersion, GUILayout.Width(30));
GUILayout.Label(".", GUILayout.Width(5));
patchVersion = EditorGUILayout.IntField(patchVersion, GUILayout.Width(30));
GUILayout.EndHorizontal();
if (GUILayout.Button("Set Build Number", GUILayout.Height(30)))
SetBuildNumber(majorVersion, minorVersion, patchVersion);
private void SetBuildNumber(int major, int minor, int patch)
string buildNumber = $"v{major}.{minor}.{patch}";
// Set build number in various places
PlayerSettings.bundleVersion = buildNumber;
PlayerSettings.iOS.buildNumber = buildNumber;
PlayerSettings.Android.bundleVersionCode = major * 10000 + minor * 100 + patch; // or another scheme to convert version to an integer
// Optionally update the Product Name
PlayerSettings.productName = $"MyProduct {buildNumber}";
// Save changes to the asset database
AssetDatabase.SaveAssets();
// Update the #app-version label via the UI_Manager
UpdateAppVersionLabel(buildNumber);
Debug.Log($"Build number set to {buildNumber}");
private void UpdateAppVersionLabel(string buildNumber)
// Find the UI_Manager in the scene
UI_Manager uiManager = FindObjectOfType<UI_Manager>();
Debug.LogError("UI_Manager not found in the scene.");
// Get the root VisualElement from the UI_Manager
VisualElement root = uiManager.GetRootVisualElement();
Debug.LogError("Root VisualElement not found in UI_Manager.");
// Find the #app-version label and update its text
var appVersionLabel = root.Q<Label>("app-version");
if (appVersionLabel != null)
appVersionLabel.text = buildNumber;
Debug.Log($"Updated #app-version label to {buildNumber}");
Debug.LogError("#app-version label not found in the VisualElement.");
// Assuming this is your UI_Manager component script
public class UI_Manager : MonoBehaviour
public UIDocument uiDocument;
public VisualElement GetRootVisualElement()
// Ensure uiDocument is assigned
uiDocument = GetComponent<UIDocument>();
// Return the root VisualElement of the UI
return uiDocument?.rootVisualElement;