rabidus-test/Assets/00_CI/BuilderTool.cs

72 lines
2.2 KiB
C#
Raw Permalink Normal View History

2023-10-25 15:02:47 +03:00
#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++;
2023-10-25 15:09:40 +03:00
var buildRootPath = Path.Combine(rootPath, "Builds");
2023-10-25 15:02:47 +03:00
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