diff --git a/Editor/HookahAssetBuilder.cs b/Editor/HookahAssetBuilder.cs index a199efa..233d810 100644 --- a/Editor/HookahAssetBuilder.cs +++ b/Editor/HookahAssetBuilder.cs @@ -1,10 +1,8 @@ -using System; using System.Diagnostics; using System.IO; using System.Linq; using UnityEditor; using UnityEngine; -using System.Windows; public class HookahAssetBuilder { @@ -15,28 +13,53 @@ public class HookahAssetBuilder static readonly string ModPackProfilePath = $@"{ModManagerProfilesPath}/{ModPackProfileName}"; static readonly string ModPackHookahPlacePath = @$"{ModPackProfilePath}/BepInEx/plugins/{ModPackModName}"; - static readonly string ModProjectPath = @"D:\Code\LC-Decompiled\Mods\HookahPlace"; + static readonly string ModProjectPath = @"D:\Code\LethalCompany\Mods\HookahPlace"; static readonly string DllName = "Ratijas.HookahPlace.dll"; static readonly string DllSourcePath = $@"{ModProjectPath}/HookahPlace/bin/Debug/netstandard2.1/{DllName}"; static readonly string[] DllDestinationPaths = new string[] { // relative to Unity project - $@"Assets/LethalCompany/Mods/plugins/HookahPlace/Dependencies/{ModPackModName}", + $@"Assets/LethalCompany/Mods/plugins/Dependencies/{ModPackModName}", ModPackHookahPlacePath, }; static readonly string AssetBundlesPath = "Assets/LethalCompany/Mods/plugins/HookahPlace/AssetBundles"; - static readonly string[] AssetBundlesNames = new string[] - { - "hookahplaceasset", - "hookahunlockableassets", - }; static readonly string[] AssetBundlesDestinationPaths = new string[] { @$"{ModPackHookahPlacePath}/Assets", @$"{ModProjectPath}/HookahPlace/res", }; + public static BuildAssetBundlesParameters GetBuildAssetBundlesParameters() + { + var assetBundleDefinitions = new AssetBundleBuild[] + { + new AssetBundleBuild() + { + assetBundleName = "hookahplaceasset", + assetNames = new string[] + { + "Assets/LethalCompany/Mods/plugins/HookahPlace/HookahContentContainer.asset", + } + }, + new AssetBundleBuild() + { + assetBundleName = "hookahunlockableassets", + assetNames = new string[] + { + "Assets/LethalCompany/Mods/plugins/HookahPlace/Content/Unlockables", + } + }, + }; + var buildParameters = new BuildAssetBundlesParameters() + { + outputPath = AssetBundlesPath, + options = BuildAssetBundleOptions.ChunkBasedCompression, + bundleDefinitions = assetBundleDefinitions + }; + return buildParameters; + } + [MenuItem("HookahPlace/All")] public static void DoAll() { @@ -82,9 +105,22 @@ public class HookahAssetBuilder { UnityEngine.Debug.Log("Building asset bundles for HookahPlace..."); - Directory.CreateDirectory(AssetBundlesPath); + var buildParameters = GetBuildAssetBundlesParameters(); + Directory.CreateDirectory(buildParameters.outputPath); + AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(buildParameters); - BuildPipeline.BuildAssetBundles(AssetBundlesPath, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows); + if (manifest != null) + { + foreach(var bundleName in manifest.GetAllAssetBundles()) + { + string projectRelativePath = buildParameters.outputPath + "/" + bundleName; + UnityEngine.Debug.Log($"Size of AssetBundle {projectRelativePath} is {new FileInfo(projectRelativePath).Length}"); + } + } + else + { + UnityEngine.Debug.Log("Build failed, see Console and Editor log for details"); + } if (Application.isBatchMode) { @@ -97,13 +133,16 @@ public class HookahAssetBuilder { UnityEngine.Debug.Log("Installing asset bundles for HookahPlace..."); + var buildParameters = GetBuildAssetBundlesParameters(); + foreach (var destinationPath in AssetBundlesDestinationPaths) { Directory.CreateDirectory(destinationPath); - foreach (var name in AssetBundlesNames) + foreach (var bundle in buildParameters.bundleDefinitions) { - var sourceFileName = $"{AssetBundlesPath}/{name}"; + var name = bundle.assetBundleName; + var sourceFileName = $"{buildParameters.outputPath}/{name}"; var destFileName = $"{destinationPath}/{name}"; FileCopy(sourceFileName, destFileName); } diff --git a/HookahPlace/res/hookahplaceasset b/HookahPlace/res/hookahplaceasset index 873d629..f751d64 100644 Binary files a/HookahPlace/res/hookahplaceasset and b/HookahPlace/res/hookahplaceasset differ diff --git a/HookahPlace/res/hookahunlockableassets b/HookahPlace/res/hookahunlockableassets index b9e4466..89a3c3f 100644 Binary files a/HookahPlace/res/hookahunlockableassets and b/HookahPlace/res/hookahunlockableassets differ