mirror of
https://github.com/muskit/H3VR-TNH-Quality-of-Life-Improvements.git
synced 2026-06-02 20:24:26 -07:00
Initial commit
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using AssetsTools.NET;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace MeatKit
|
||||
{
|
||||
public static partial class MeatKit
|
||||
{
|
||||
private static readonly string ManagedDirectory = Path.Combine(Application.dataPath, "MeatKit/Managed/");
|
||||
|
||||
private static bool ShowErrorIfH3VRNotImported()
|
||||
{
|
||||
#if (H3VR_IMPORTED == false)
|
||||
EditorUtility.DisplayDialog("Cannot continue.", "You don't have the H3 scripts imported. Please do that before trying to export anything.", "Ok");
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("MeatKit/Scripts/Import Game", priority = 0)]
|
||||
public static void ImportAssemblies()
|
||||
{
|
||||
// If the path has never been set, or no longer exists, prompt the user to find it again
|
||||
var gameManagedLocation = MeatKitCache.GameManagedLocation;
|
||||
if (string.IsNullOrEmpty(gameManagedLocation) || !Directory.Exists(gameManagedLocation))
|
||||
{
|
||||
gameManagedLocation = EditorUtility.OpenFolderPanel("Select H3VR Managed directory", string.Empty, "Managed");
|
||||
MeatKitCache.GameManagedLocation = gameManagedLocation;
|
||||
}
|
||||
|
||||
// If it's _still_ empty, the user must have cancelled.
|
||||
if (string.IsNullOrEmpty(gameManagedLocation)) return;
|
||||
ImportAssemblies(gameManagedLocation, ManagedDirectory);
|
||||
}
|
||||
|
||||
[MenuItem("MeatKit/Scripts/Import Single", priority = 0)]
|
||||
public static void ImportSingleAssembly()
|
||||
{
|
||||
var assemblyLocation =
|
||||
EditorUtility.OpenFilePanel("Select assembly", null, "dll");
|
||||
if (string.IsNullOrEmpty(assemblyLocation)) return;
|
||||
MeatKitCache.LastImportedAssembly = assemblyLocation;
|
||||
ImportSingleAssembly(assemblyLocation, ManagedDirectory);
|
||||
Debug.Log("Finished importing " + assemblyLocation);
|
||||
}
|
||||
|
||||
[MenuItem("MeatKit/Scripts/Re-Import Last", priority = 0)]
|
||||
public static void ReimportLast()
|
||||
{
|
||||
if (string.IsNullOrEmpty(MeatKitCache.LastImportedAssembly))
|
||||
{
|
||||
Debug.Log("Nothing to re-import.");
|
||||
return;
|
||||
}
|
||||
|
||||
ImportSingleAssembly(MeatKitCache.LastImportedAssembly, ManagedDirectory);
|
||||
Debug.Log("Re-imported " + MeatKitCache.LastImportedAssembly);
|
||||
}
|
||||
|
||||
[MenuItem("MeatKit/Scripts/Export", priority = 0)]
|
||||
public static void ExportEditorScripts()
|
||||
{
|
||||
// Make sure the scripts are imported and there are no errors before exporting
|
||||
if (ShowErrorIfH3VRNotImported()) return;
|
||||
if (!BuildWindow.SelectedProfile.EnsureValidForEditor()) return;
|
||||
ExportEditorAssembly(BundleOutputPath);
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("MeatKit/Asset Bundle/Export", priority = 1)]
|
||||
public static void ExportBundle()
|
||||
{
|
||||
var assetBundlePath = EditorUtility.OpenFilePanel("Select asset bundle", Application.dataPath, "");
|
||||
var settings = BuildWindow.SelectedProfile;
|
||||
var replaceMap = new Dictionary<string, string>
|
||||
{
|
||||
{"Assembly-CSharp.dll", settings.PackageName + ".dll"},
|
||||
{"Assembly-CSharp-firstpass.dll", settings.PackageName + "-firstpass.dll"},
|
||||
{"H3VRCode-CSharp.dll", "Assembly-CSharp.dll"},
|
||||
{"H3VRCode-CSharp-firstpass.dll", "Assembly-CSharp-firstpass.dll"}
|
||||
};
|
||||
|
||||
ProcessBundle(assetBundlePath, assetBundlePath, replaceMap, AssetBundleCompressionType.LZ4);
|
||||
}
|
||||
|
||||
[MenuItem("MeatKit/Asset Bundle/Import", priority = 1)]
|
||||
public static void ImportBundle()
|
||||
{
|
||||
var assetBundlePath = EditorUtility.OpenFilePanel("Select asset bundle", Application.dataPath, "");
|
||||
var replaceMap = new Dictionary<string, string>
|
||||
{
|
||||
{"Assembly-CSharp.dll", "H3VRCode-CSharp.dll"},
|
||||
{"Assembly-CSharp-firstpass.dll", "H3VRCode-CSharp-firstpass.dll"}
|
||||
};
|
||||
|
||||
ProcessBundle(assetBundlePath, assetBundlePath + "-imported", replaceMap, AssetBundleCompressionType.NONE);
|
||||
}
|
||||
|
||||
public static void ClearCache()
|
||||
{
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
if (Directory.Exists(ManagedDirectory))
|
||||
Directory.Delete(ManagedDirectory, true);
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, "");
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user