Rebuild assets and add new editor script

This commit is contained in:
ivan tkachenko 2026-04-10 21:30:54 +03:00
parent b6f0901063
commit 52a69155bb
3 changed files with 52 additions and 13 deletions

View File

@ -1,10 +1,8 @@
using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using System.Windows;
public class HookahAssetBuilder public class HookahAssetBuilder
{ {
@ -15,28 +13,53 @@ public class HookahAssetBuilder
static readonly string ModPackProfilePath = $@"{ModManagerProfilesPath}/{ModPackProfileName}"; static readonly string ModPackProfilePath = $@"{ModManagerProfilesPath}/{ModPackProfileName}";
static readonly string ModPackHookahPlacePath = @$"{ModPackProfilePath}/BepInEx/plugins/{ModPackModName}"; 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 DllName = "Ratijas.HookahPlace.dll";
static readonly string DllSourcePath = $@"{ModProjectPath}/HookahPlace/bin/Debug/netstandard2.1/{DllName}"; static readonly string DllSourcePath = $@"{ModProjectPath}/HookahPlace/bin/Debug/netstandard2.1/{DllName}";
static readonly string[] DllDestinationPaths = new string[] static readonly string[] DllDestinationPaths = new string[]
{ {
// relative to Unity project // relative to Unity project
$@"Assets/LethalCompany/Mods/plugins/HookahPlace/Dependencies/{ModPackModName}", $@"Assets/LethalCompany/Mods/plugins/Dependencies/{ModPackModName}",
ModPackHookahPlacePath, ModPackHookahPlacePath,
}; };
static readonly string AssetBundlesPath = "Assets/LethalCompany/Mods/plugins/HookahPlace/AssetBundles"; static readonly string AssetBundlesPath = "Assets/LethalCompany/Mods/plugins/HookahPlace/AssetBundles";
static readonly string[] AssetBundlesNames = new string[]
{
"hookahplaceasset",
"hookahunlockableassets",
};
static readonly string[] AssetBundlesDestinationPaths = new string[] static readonly string[] AssetBundlesDestinationPaths = new string[]
{ {
@$"{ModPackHookahPlacePath}/Assets", @$"{ModPackHookahPlacePath}/Assets",
@$"{ModProjectPath}/HookahPlace/res", @$"{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")] [MenuItem("HookahPlace/All")]
public static void DoAll() public static void DoAll()
{ {
@ -82,9 +105,22 @@ public class HookahAssetBuilder
{ {
UnityEngine.Debug.Log("Building asset bundles for HookahPlace..."); 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) if (Application.isBatchMode)
{ {
@ -97,13 +133,16 @@ public class HookahAssetBuilder
{ {
UnityEngine.Debug.Log("Installing asset bundles for HookahPlace..."); UnityEngine.Debug.Log("Installing asset bundles for HookahPlace...");
var buildParameters = GetBuildAssetBundlesParameters();
foreach (var destinationPath in AssetBundlesDestinationPaths) foreach (var destinationPath in AssetBundlesDestinationPaths)
{ {
Directory.CreateDirectory(destinationPath); 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}"; var destFileName = $"{destinationPath}/{name}";
FileCopy(sourceFileName, destFileName); FileCopy(sourceFileName, destFileName);
} }

Binary file not shown.