update MeatKit (9a1a68ab68cd0650227af944ffa30d1166b9e056)

This commit is contained in:
msk
2023-07-26 16:45:05 -07:00
parent 920875f56b
commit d2316bac96
266 changed files with 2855 additions and 9187 deletions
+80 -37
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -14,6 +14,8 @@ namespace MeatKit
{
public static void DoBuild()
{
BuildLog.StartNew();
try
{
DoBuildInternal();
@@ -23,13 +25,17 @@ namespace MeatKit
string message = e.Message;
if (e.InnerException != null) message += "\n\n" + e.InnerException.Message;
EditorUtility.DisplayDialog("Build failed", message, "Ok.");
BuildLog.SetCompletionStatus(true, "MeatKit Build Exception", e);
}
catch (Exception e)
{
EditorUtility.DisplayDialog("Build failed with unknown error",
"Error message: " + e.Message + "\n\nCheck console for full exception text.", "Ok.");
Debug.LogException(e);
BuildLog.SetCompletionStatus(true, "Unexpected exception during build", e);
}
BuildLog.Finish();
}
private static void DoBuildInternal()
@@ -41,6 +47,8 @@ namespace MeatKit
BuildProfile profile = BuildWindow.SelectedProfile;
if (!profile) return;
string bundleOutputPath = profile.ExportPath;
// Start a stopwatch to time the build
Stopwatch sw = Stopwatch.StartNew();
@@ -48,39 +56,66 @@ namespace MeatKit
if (!profile.EnsureValidForEditor()) return;
// Clean the output folder
CleanBuild();
BuildLog.WriteLine("Cleaning build folder");
CleanBuild(profile);
// And export the assembly to the folder
ExportEditorAssembly(BundleOutputPath);
// Then get their asset bundle configurations
var bundles = profile.BuildItems.SelectMany(x => x.ConfigureBuild()).ToArray();
BuildPipeline.BuildAssetBundles(BundleOutputPath, bundles, BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows64);
// Cleanup the unused files created with building the bundles
foreach (var file in Directory.GetFiles(BundleOutputPath, "*.manifest"))
File.Delete(file);
File.Delete(Path.Combine(BundleOutputPath, "AssetBundles"));
// With the bundles done building we can process them
// Make a copy of the editor assembly because when we build an asset bundle, Unity will delete it
string editorAssembly = EditorAssemblyPath + AssemblyName + ".dll";
string tempAssemblyFile = Path.GetTempFileName();
BuildLog.WriteLine("Copying editor assembly: " + editorAssembly + " -> " + tempAssemblyFile);
File.Copy(editorAssembly, tempAssemblyFile, true);
// Make sure we have the virtual reality supported checkbox enabled
// If this is not set to true when we build our asset bundles, the shaders will not compile correctly
BuildLog.WriteLine("Forcing VR support on");
bool wasVirtualRealitySupported = PlayerSettings.virtualRealitySupported;
PlayerSettings.virtualRealitySupported = true;
// Create a map of assembly names to what we want to rename them to, then enable bundle processing
var replaceMap = new Dictionary<string, string>
{
{"Assembly-CSharp.dll", profile.PackageName + ".dll"},
{"Assembly-CSharp-firstpass.dll", profile.PackageName + "-firstpass.dll"},
{"H3VRCode-CSharp.dll", "Assembly-CSharp.dll"},
{"H3VRCode-CSharp-firstpass.dll", "Assembly-CSharp-firstpass.dll"}
{AssemblyName + ".dll", profile.PackageName + ".dll"},
{AssemblyFirstpassName + ".dll", profile.PackageName + "-firstpass.dll"},
{AssemblyRename + ".dll", AssemblyName + ".dll"},
{AssemblyFirstpassRename + ".dll", AssemblyFirstpassName + ".dll"}
};
BuildLog.WriteLine("Enabling bundle processing.");
BuildLog.WriteLine("Replace map:");
foreach (var key in replaceMap.Keys)
BuildLog.WriteLine(" " + key + " -> " + replaceMap[key]);
BuildLog.WriteLine("Ignored types (Assembly-CSharp.dll):");
foreach (var type in StripAssemblyTypes)
BuildLog.WriteLine(" " + type);
AssetBundleIO.EnableProcessing(replaceMap, false, true);
foreach (var bundle in bundles)
{
var path = Path.Combine(BundleOutputPath, bundle.assetBundleName);
ProcessBundle(path, path, replaceMap, profile.BundleCompressionType);
}
// Get the list of asset bundle configurations and build them
BuildLog.WriteLine("Collecting bundles from build items");
var bundles = profile.BuildItems.SelectMany(x => x.ConfigureBuild()).ToArray();
BuildLog.WriteLine(bundles.Length + " bundles to build. Building bundles.");
BuildPipeline.BuildAssetBundles(bundleOutputPath, bundles, BuildAssetBundleOptions.ChunkBasedCompression,
BuildTarget.StandaloneWindows64);
// Disable bundle processing now that we're done with it.
AssetBundleIO.DisableProcessing();
var requiredScripts = AssetBundleIO.SerializedScriptNames;
BuildLog.WriteLine("Bundles built");
// Cleanup the unused files created with building the bundles
BuildLog.WriteLine("Cleaning unused files");
foreach (var file in Directory.GetFiles(bundleOutputPath, "*.manifest"))
File.Delete(file);
File.Delete(Path.Combine(bundleOutputPath, profile.Version));
// Reset the virtual reality supported checkbox, so if the user had it disabled it will stay disabled
PlayerSettings.virtualRealitySupported = wasVirtualRealitySupported;
// And export the assembly to the folder
BuildLog.WriteLine("Exporting editor assembly");
ExportEditorAssembly(bundleOutputPath, tempAssemblyFile, requiredScripts);
// Now we can write the Thunderstore stuff to the folder
profile.WriteThunderstoreManifest(BundleOutputPath + "manifest.json");
BuildLog.WriteLine("Writing Thunderstore manifest");
profile.WriteThunderstoreManifest(bundleOutputPath + "manifest.json");
// Check if the icon is already 256x256
Texture2D icon = profile.Icon;
@@ -90,6 +125,7 @@ namespace MeatKit
if (!importSettings.isReadable ||
importSettings.textureCompression != TextureImporterCompression.Uncompressed)
{
BuildLog.WriteLine("Fixing icon import settings");
importSettings.isReadable = true;
importSettings.textureCompression = TextureImporterCompression.Uncompressed;
importSettings.SaveAndReimport();
@@ -98,41 +134,48 @@ namespace MeatKit
if (profile.Icon.width != 256 || profile.Icon.height != 256)
{
// Resize it for the build
BuildLog.WriteLine("Icon was not 256x256, resizing");
icon = icon.ScaleTexture(256, 256);
}
// Write the texture to file
File.WriteAllBytes(BundleOutputPath + "icon.png", icon.EncodeToPNG());
BuildLog.WriteLine("Saving icon");
File.WriteAllBytes(bundleOutputPath + "icon.png", icon.EncodeToPNG());
// Copy the readme
File.Copy(AssetDatabase.GetAssetPath(profile.ReadMe), BundleOutputPath + "README.md");
BuildLog.WriteLine("Copying readme");
File.Copy(AssetDatabase.GetAssetPath(profile.ReadMe), bundleOutputPath + "README.md");
string packageName = profile.Author + "-" + profile.PackageName;
if (profile.BuildAction == BuildAction.CopyToProfile)
{
BuildLog.WriteLine("Copying built files to profile");
string pluginFolder = Path.Combine(profile.OutputProfile, "BepInEx/plugins/" + packageName);
if (Directory.Exists(pluginFolder)) Directory.Delete(pluginFolder, true);
Directory.CreateDirectory(pluginFolder);
Extensions.CopyFilesRecursively(BundleOutputPath, pluginFolder);
Extensions.CopyFilesRecursively(bundleOutputPath, pluginFolder);
}
else if (profile.BuildAction == BuildAction.CreateThunderstorePackage)
{
BuildLog.WriteLine("Zipping built files");
using (var zip = new ZipFile())
{
zip.AddDirectory(BundleOutputPath, "");
zip.Save(Path.Combine(BundleOutputPath, packageName + ".zip"));
zip.AddDirectory(bundleOutputPath, "");
zip.Save(Path.Combine(bundleOutputPath, packageName + "-" + profile.Version + ".zip"));
}
}
// End the stopwatch and save the time
BuildLog.SetCompletionStatus(false, "", null);
MeatKitCache.LastBuildDuration = sw.Elapsed;
MeatKitCache.LastBuildTime = DateTime.Now;
}
public static void CleanBuild()
public static void CleanBuild(BuildProfile profile)
{
if (Directory.Exists(BundleOutputPath)) Directory.Delete(BundleOutputPath, true);
Directory.CreateDirectory(BundleOutputPath);
string outputPath = profile.ExportPath;
if (Directory.Exists(outputPath)) Directory.Delete(outputPath, true);
Directory.CreateDirectory(outputPath);
}
}
}
}