Skip to content

Commit 80447d7

Browse files
committed
added auto increment
1 parent 922fab8 commit 80447d7

6 files changed

Lines changed: 176 additions & 84 deletions

File tree

Basis/Assets/Basis/Settings/Unity Rendering Defaults/UniversalRenderPipelineGlobalSettings.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ MonoBehaviour:
7676
- rid: 2858994164428701703
7777
- rid: 2858994164428701706
7878
- rid: 2858994164428701708
79+
- rid: 3153963600462741861
7980
- rid: 3153963794888130669
8081
- rid: 3153963794888130672
8182
- rid: 2858994164428701716

Basis/Assets/Basis/link.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<assembly fullname="BasisNetworkClient" preserve="all" />
1818
<assembly fullname="BasisNetworkCore" preserve="all" />
1919
<assembly fullname="BasisNetworkServer" preserve="all" />
20+
<assembly fullname="BasisOpenVR" preserve="all" />
2021
<assembly fullname="BasisOpenXR" preserve="all" />
2122
<assembly fullname="BasisPoolTable" preserve="all" />
2223
<assembly fullname="BasisProfiler" preserve="all" />
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
using LinkerGenerator;
2+
using System.Collections.Generic;
3+
using System.Text.RegularExpressions;
4+
using UnityEditor;
5+
using UnityEditor.Build;
6+
using UnityEditor.Build.Reporting;
7+
using UnityEngine;
8+
9+
public class BasisBuildDialogAndSettings : IPreprocessBuildWithReport
10+
{
11+
public int callbackOrder => 0;
12+
13+
// ====== Version bump config ======
14+
private const bool AutoIncrementBundleVersion = true; // PlayerSettings.bundleVersion (also Android versionName)
15+
private const bool AutoIncrementAndroidVersionCode = true; // PlayerSettings.Android.bundleVersionCode
16+
17+
// If true, forces bundleVersion into X.Y.Z format (best practice).
18+
private const bool ForceSemanticVersionFormat = true;
19+
20+
// Platforms that effectively require IL2CPP (commonly true in modern Unity).
21+
private static readonly HashSet<BuildTarget> Il2CppOnlyTargets = new HashSet<BuildTarget>
22+
{
23+
BuildTarget.Android,
24+
BuildTarget.iOS,
25+
BuildTarget.tvOS,
26+
BuildTarget.WebGL,
27+
#if UNITY_2019_1_OR_NEWER
28+
BuildTarget.PS4,
29+
BuildTarget.XboxOne,
30+
BuildTarget.Switch,
31+
#endif
32+
};
33+
34+
// Platforms you want to force Mono (example: your Linux choice).
35+
private static readonly HashSet<BuildTarget> MonoOnlyTargets = new HashSet<BuildTarget>
36+
{
37+
BuildTarget.StandaloneLinux64,
38+
BuildTarget.LinuxHeadlessSimulation,
39+
};
40+
41+
public void OnPreprocessBuild(BuildReport report)
42+
{
43+
// 0) Generate link.xml
44+
BasisLinkGenerator.GenerateLinkXml();
45+
46+
// 0.5) Versioning
47+
BumpVersionsIfNeeded(report.summary.platform);
48+
49+
var namedBuildTarget =
50+
UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(report.summary.platformGroup);
51+
52+
var currentBackend = PlayerSettings.GetScriptingBackend(namedBuildTarget);
53+
var target = report.summary.platform;
54+
55+
// 1) Force IL2CPP-only targets
56+
if (Il2CppOnlyTargets.Contains(target))
57+
{
58+
SetBackendIfNeeded(namedBuildTarget, currentBackend, ScriptingImplementation.IL2CPP);
59+
return;
60+
}
61+
62+
// 2) Force Mono-only targets
63+
if (MonoOnlyTargets.Contains(target))
64+
{
65+
SetBackendIfNeeded(namedBuildTarget, currentBackend, ScriptingImplementation.Mono2x);
66+
return;
67+
}
68+
69+
// 3) Ask for everything else (avoid dialogs in batch mode)
70+
bool useIl2Cpp;
71+
if (Application.isBatchMode)
72+
{
73+
// Safe default for CI: keep current backend (or change to true to default IL2CPP)
74+
useIl2Cpp = (currentBackend == ScriptingImplementation.IL2CPP);
75+
}
76+
else
77+
{
78+
useIl2Cpp = EditorUtility.DisplayDialog(
79+
"Scripting Backend",
80+
$"Build target: {target}\n\nUse IL2CPP for this build?",
81+
"Yes (IL2CPP)",
82+
"No (Mono)"
83+
);
84+
}
85+
86+
SetBackendIfNeeded(
87+
namedBuildTarget,
88+
currentBackend,
89+
useIl2Cpp ? ScriptingImplementation.IL2CPP : ScriptingImplementation.Mono2x
90+
);
91+
}
92+
93+
private static void BumpVersionsIfNeeded(BuildTarget target)
94+
{
95+
if (AutoIncrementBundleVersion)
96+
{
97+
var before = PlayerSettings.bundleVersion;
98+
var after = IncrementBundleVersion(before);
99+
if (after != before)
100+
{
101+
PlayerSettings.bundleVersion = after;
102+
Debug.Log($"[Build] bundleVersion: {before} -> {after}");
103+
}
104+
}
105+
106+
// Only bump Android versionCode when building Android (usually what you want).
107+
// If you want it bumped on *any* build, remove the target check.
108+
if (AutoIncrementAndroidVersionCode && target == BuildTarget.Android)
109+
{
110+
int before = PlayerSettings.Android.bundleVersionCode;
111+
int after = Mathf.Max(1, before + 1);
112+
PlayerSettings.Android.bundleVersionCode = after;
113+
Debug.Log($"[Build] Android versionCode: {before} -> {after}");
114+
115+
// Android versionName comes from PlayerSettings.bundleVersion by default.
116+
// If you want it explicitly logged:
117+
Debug.Log($"[Build] Android versionName: {PlayerSettings.bundleVersion}");
118+
}
119+
120+
// If you want the changes to definitely persist to ProjectSettings on disk:
121+
// AssetDatabase.SaveAssets();
122+
}
123+
124+
private static string IncrementBundleVersion(string version)
125+
{
126+
// Prefer X.Y.Z
127+
if (ForceSemanticVersionFormat)
128+
{
129+
// Match "major.minor.patch" with optional extra junk ignored
130+
var m = Regex.Match(version ?? "", @"^\s*(\d+)\.(\d+)\.(\d+)\s*$");
131+
if (m.Success)
132+
{
133+
int major = int.Parse(m.Groups[1].Value);
134+
int minor = int.Parse(m.Groups[2].Value);
135+
int patch = int.Parse(m.Groups[3].Value) + 1;
136+
return $"{major}.{minor}.{patch}";
137+
}
138+
139+
// If it isn't semver, coerce it into semver and start at .0.1
140+
// Examples:
141+
// "1" -> "1.0.1"
142+
// "1.2" -> "1.2.1"
143+
// "v1.2" -> "1.2.1" (extracts digits)
144+
var nums = Regex.Matches(version ?? "", @"\d+");
145+
int majorC = nums.Count > 0 ? int.Parse(nums[0].Value) : 0;
146+
int minorC = nums.Count > 1 ? int.Parse(nums[1].Value) : 0;
147+
int patchC = 1;
148+
return $"{majorC}.{minorC}.{patchC}";
149+
}
150+
151+
// Otherwise, try to increment a trailing number, else append ".1"
152+
var match = Regex.Match(version ?? "", @"^(.*?)(\d+)\s*$");
153+
if (match.Success)
154+
{
155+
string prefix = match.Groups[1].Value;
156+
int n = int.Parse(match.Groups[2].Value) + 1;
157+
return $"{prefix}{n}";
158+
}
159+
160+
if (string.IsNullOrWhiteSpace(version)) return "0.0.1";
161+
return version.Trim() + ".1";
162+
}
163+
164+
private static void SetBackendIfNeeded(
165+
UnityEditor.Build.NamedBuildTarget namedBuildTarget,
166+
ScriptingImplementation current,
167+
ScriptingImplementation desired)
168+
{
169+
if (current == desired) return;
170+
PlayerSettings.SetScriptingBackend(namedBuildTarget, desired);
171+
}
172+
}

Basis/Packages/com.basis.framework.editor/Editor/BasisBuildDialogil2CPP.cs.meta renamed to Basis/Packages/com.basis.framework.editor/Editor/BasisBuildDialogAndSettings.cs.meta

File renamed without changes.

Basis/Packages/com.basis.framework.editor/Editor/BasisBuildDialogil2CPP.cs

Lines changed: 0 additions & 82 deletions
This file was deleted.

Basis/ProjectSettings/ProjectSettings.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ PlayerSettings:
143143
loadStoreDebugModeEnabled: 0
144144
visionOSBundleVersion: 1.0
145145
tvOSBundleVersion: 1.0
146-
bundleVersion: 2
146+
bundleVersion: 2.0.2
147147
preloadedAssets:
148148
- {fileID: 11400000, guid: cf469a9a31a25dc449c2537cb0b17ad6, type: 2}
149149
- {fileID: -944628639613478452, guid: 5e4c3601c6a155f43af19da3bdd35a64, type: 3}
@@ -177,7 +177,7 @@ PlayerSettings:
177177
iPhone: 0
178178
tvOS: 0
179179
overrideDefaultApplicationIdentifier: 1
180-
AndroidBundleVersionCode: 157
180+
AndroidBundleVersionCode: 158
181181
AndroidMinSdkVersion: 32
182182
AndroidTargetSdkVersion: 34
183183
AndroidPreferredInstallLocation: 0

0 commit comments

Comments
 (0)