From 5f7a9154384ae9307f55e14e73cea6d216b3f784 Mon Sep 17 00:00:00 2001 From: "a.gorbunov" <0alexgorbynov0@gmail.com> Date: Wed, 25 Oct 2023 15:02:47 +0300 Subject: [PATCH] Add ci. --- Assets/00_CI.meta | 8 +++++ Assets/00_CI/BuilderTool.cs | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 Assets/00_CI.meta create mode 100644 Assets/00_CI/BuilderTool.cs diff --git a/Assets/00_CI.meta b/Assets/00_CI.meta new file mode 100644 index 00000000..4972ca8c --- /dev/null +++ b/Assets/00_CI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4feeb981ea509cd42967c3637667453d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/00_CI/BuilderTool.cs b/Assets/00_CI/BuilderTool.cs new file mode 100644 index 00000000..156cb262 --- /dev/null +++ b/Assets/00_CI/BuilderTool.cs @@ -0,0 +1,72 @@ +#if UNITY_EDITOR + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEditor; +using UnityEditor.Build; +using UnityEditor.Build.Reporting; +using UnityEditor.SceneManagement; +using UnityEngine; + +public static class BuilderTool +{ + public static NamedBuildTarget GetBuildTarget() => NamedBuildTarget.Standalone; + + [MenuItem("Builds/Build")] + public static void Build() + { + var productName = $"VR Project 3"; + var rootPath = Application.dataPath + "/../"; + var bundleNumber = PlayerSettings.Android.bundleVersionCode; + bundleNumber++; + var buildRootPath = Path.Combine(rootPath, "Builds2"); + var buildName = $"{productName}.exe"; + var buildPlayerOptions = new BuildPlayerOptions(); + + var defines = GetActualDefines(); + ApplyDefines(defines); + + + PlayerSettings.applicationIdentifier = $"com.BoggArt.OscSender.{productName}"; + PlayerSettings.productName = productName; + buildPlayerOptions.scenes = GetScenes(); + buildPlayerOptions.locationPathName = Path.Combine(buildRootPath, buildName); + buildPlayerOptions.target = BuildTarget.StandaloneWindows64; + buildPlayerOptions.options = BuildOptions.None; + buildPlayerOptions.extraScriptingDefines = defines; + + if (!Directory.Exists(buildRootPath)) + Directory.CreateDirectory(buildRootPath); + + BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions); + BuildSummary summary = report.summary; + + if (summary.result == BuildResult.Succeeded) + { + Debug.Log("Build succeeded: " + summary.totalSize + " bytes"); + } + + if (summary.result == BuildResult.Failed) + { + Debug.Log("Build failed"); + } + } + + public static string[] GetActualDefines() + { + return PlayerSettings.GetScriptingDefineSymbols(GetBuildTarget()).Split(";").ToArray(); + } + + public static string[] GetScenes() + { + return EditorBuildSettings.scenes.Select(s => s.path).ToArray(); + } + + private static void ApplyDefines(string[] defines) + { + PlayerSettings.SetScriptingDefineSymbols(GetBuildTarget(), defines); + } +} +#endif \ No newline at end of file