-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameAnalyticsBuildVersionUpdater.cs
More file actions
40 lines (33 loc) · 1.18 KB
/
GameAnalyticsBuildVersionUpdater.cs
File metadata and controls
40 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using UnityEditor.Build;
using GameAnalyticsSDK.Setup;
using UnityEditor.Build.Reporting;
namespace RimuruDev
{
public sealed class GameAnalyticsBuildVersionUpdater : IPreprocessBuildWithReport
{
private const string SettingsPath = "Assets/Resources/GameAnalytics/Settings.asset";
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report) =>
UpdateBuildVersion();
private static void UpdateBuildVersion()
{
var settings = AssetDatabase.LoadAssetAtPath<Settings>(SettingsPath);
if (settings != null)
{
for (var i = 0; i < settings.Build.Count; i++)
settings.Build[i] = Application.version;
EditorUtility.SetDirty(settings);
AssetDatabase.SaveAssets();
Debug.Log($"<color=yellow>Build version updated to {Application.version} in GameAnalytics Settings</color>");
}
else
{
Debug.LogError("Failed to load GameAnalytics Settings asset.");
}
}
}
}
#endif