Build Soundings cruise management simulator
This commit is contained in:
68
Assets/Soundings/Editor/SoundingsBuild.cs
Normal file
68
Assets/Soundings/Editor/SoundingsBuild.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Soundings.Editor
|
||||
{
|
||||
public static class SoundingsBuild
|
||||
{
|
||||
private const string ScenePath = "Assets/Soundings/Scenes/Soundings.unity";
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
if (!File.Exists(ScenePath))
|
||||
{
|
||||
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
||||
if (!EditorSceneManager.SaveScene(scene, ScenePath))
|
||||
throw new BuildFailedException("Could not save the Soundings scene.");
|
||||
}
|
||||
|
||||
EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(ScenePath, true) };
|
||||
PlayerSettings.companyName = "Soundings";
|
||||
PlayerSettings.productName = "Soundings";
|
||||
PlayerSettings.bundleVersion = "0.1.0";
|
||||
PlayerSettings.defaultScreenWidth = 1600;
|
||||
PlayerSettings.defaultScreenHeight = 900;
|
||||
PlayerSettings.fullScreenMode = FullScreenMode.Windowed;
|
||||
PlayerSettings.resizableWindow = true;
|
||||
PlayerSettings.runInBackground = true;
|
||||
PlayerSettings.SetApplicationIdentifier(NamedBuildTarget.Standalone, "game.soundings.simulator");
|
||||
PlayerSettings.SetScriptingBackend(NamedBuildTarget.Standalone, ScriptingImplementation.Mono2x);
|
||||
PlayerSettings.WebGL.compressionFormat = WebGLCompressionFormat.Disabled;
|
||||
PlayerSettings.WebGL.template = "PROJECT:Soundings";
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
public static void VerifyAndBuild()
|
||||
{
|
||||
Configure();
|
||||
EconomyVerification.Run();
|
||||
Build();
|
||||
}
|
||||
|
||||
public static void Build() => BuildTargetPlayer(EditorUserBuildSettings.activeBuildTarget);
|
||||
|
||||
private static void BuildTargetPlayer(BuildTarget target)
|
||||
{
|
||||
string output = Environment.GetEnvironmentVariable("SOUNDINGS_BUILD_PATH");
|
||||
if (string.IsNullOrEmpty(output))
|
||||
throw new BuildFailedException("Set SOUNDINGS_BUILD_PATH to the output file (native) or directory (WebGL).");
|
||||
string directory = Path.GetDirectoryName(Path.GetFullPath(output));
|
||||
Directory.CreateDirectory(directory);
|
||||
BuildReport report = BuildPipeline.BuildPlayer(new BuildPlayerOptions
|
||||
{
|
||||
scenes = new[] { ScenePath },
|
||||
target = target,
|
||||
locationPathName = output,
|
||||
options = BuildOptions.None
|
||||
});
|
||||
if (report.summary.result != BuildResult.Succeeded)
|
||||
throw new BuildFailedException($"Soundings build failed: {report.summary.result}.");
|
||||
Debug.Log($"Built Soundings for {target}: {report.summary.totalSize:N0} bytes at {output}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user