Quantcast
Channel: Questions in topic: "buildpipeline"
Viewing all articles
Browse latest Browse all 249

Is it possible to change ScriptableObject values during BuildPipeline?

$
0
0
To the best of my Google-Fu abilities, I'll say there's no built-in way to access `PlayerSettings.iOS.buildNumber` or equivalent at runtime (feel free to prove me wrong! =) ) I created the silliest ScriptableObject then, to store the new build number every time I run a BuildPipeline, and attached that SO to an object in my root scene to show me the built version. While I can see the number increasing in the SO (**Inspector > Debug**) and I do see the correct value from the SO when running the scene in Editor, the iOS app doesn't take that number. Are there any known restrictions about affecting an SO during the BuildPipeline? Below is the full code for reference. [MenuItem("Build/iOS/Dev")] public static void BuildIOSDev() { BuildIOS(true); } [MenuItem("Build/iOS/Rel")] public static void BuildIOSRel() { BuildIOS(); } static void BuildIOS(bool devBuild = false) { Build(BuildTarget.iOS, devBuild); } static void Build(BuildTarget target, bool devBuild = false) { uint buildNumber = SetNewBuildNumber(); string pathToAssets = Application.dataPath; string pathToProject = pathToAssets.Replace("/Assets", ""); string buildPath = $"{pathToProject}/Builds/{target}/"; string buildName = $"2020Armor_v{Application.version}.{buildNumber}{(devBuild ? "_Dev" : "")}"; string fullPath = $"{buildPath}/{buildName}"; // configure the options for the build BuildPlayerOptions options = new BuildPlayerOptions(); options.locationPathName = fullPath; options.options = (devBuild ? BuildOptions.Development : BuildOptions.None) | BuildOptions.AutoRunPlayer; options.target = target; options.scenes = new string[EditorBuildSettings.scenes.Length]; for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) { options.scenes[i] = EditorBuildSettings.scenes[i].path; } // trigger the build process Debug.Log($"Building {buildName} to {fullPath}"); BuildReport buildReport = BuildPipeline.BuildPlayer(options); if (buildReport.summary.result == BuildResult.Succeeded) { Debug.Log($"{buildName} saved to {fullPath}"); } else { Debug.LogError($"Build failed with details {buildReport.summary.totalErrors} errors"); RevertBuildNumber(); } } static uint SetNewBuildNumber() { uint buildNumber = Convert.ToUInt32(PlayerSettings.iOS.buildNumber) + 1; PlayerSettings.iOS.buildNumber = (buildNumber).ToString(); BuildData buildData = AssetDatabase.LoadAssetAtPath("Assets/LocalData/BuildData.asset"); buildData.SetBuildNumber(buildNumber); return buildNumber; } static uint RevertBuildNumber() { uint buildNumber = Convert.ToUInt32(PlayerSettings.iOS.buildNumber) - 1; PlayerSettings.iOS.buildNumber = (buildNumber).ToString(); BuildData buildData = AssetDatabase.LoadAssetAtPath("Assets/LocalData/BuildData.asset"); buildData.SetBuildNumber(buildNumber); return buildNumber; }

Viewing all articles
Browse latest Browse all 249

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>