Aetheria/Assets/Editor/EveAssetBundleBuilder.cs
2026-07-12 06:43:33 +01:00

58 lines
2.3 KiB
C#

using System;
using System.IO;
using System.Linq;
using GameCult.Aetheria.State.Verse;
using UnityEditor;
namespace Aetheria.Editor
{
public static class EveAssetBundleBuilder
{
public const string BundleName = "aetheria-world";
public static void BuildWindows()
{
Build(BuildTarget.StandaloneWindows64);
}
private static void Build(BuildTarget target)
{
EveThermalProfileMigrator.EnsureGenerated();
var output = Environment.GetEnvironmentVariable("AETHERIA_EVE_BUNDLE_OUTPUT");
if (string.IsNullOrWhiteSpace(output))
output = Path.GetFullPath(Path.Combine("Build", "EveAssets", target.ToString()));
Directory.CreateDirectory(output);
var assetNames = AetheriaRuntimeAssets.ProjectManifest(null).Assets
.Select(entry => entry.Ref.Metadata.TryGetValue("unityAssetPath", out var explicitPath)
? explicitPath
: entry.Ref.Metadata.TryGetValue("resourcesPath", out var path) &&
string.Equals(entry.Ref.Kind, AetheriaRuntimeAssetKinds.Prefab, StringComparison.Ordinal)
? $"Assets/Resources/{path}.prefab"
: "")
.Where(path => !string.IsNullOrWhiteSpace(path) && File.Exists(path))
.Distinct(StringComparer.Ordinal)
.OrderBy(path => path, StringComparer.Ordinal)
.ToArray();
if (assetNames.Length == 0)
throw new InvalidOperationException("Aetheria Eve bundle has no provider Unity assets.");
var manifest = BuildPipeline.BuildAssetBundles(
output,
new[]
{
new AssetBundleBuild
{
assetBundleName = BundleName,
assetNames = assetNames
}
},
BuildAssetBundleOptions.None,
target);
if (manifest == null || !manifest.GetAllAssetBundles().Contains(BundleName, StringComparer.Ordinal))
throw new InvalidOperationException("Unity did not emit the Aetheria Eve world bundle.");
Console.WriteLine($"Aetheria Eve AssetBundle: {Path.Combine(output, BundleName)}");
}
}
}