SHA256
Refactor Asset Loading
This commit is contained in:
9 files changed
+102
-162
No files matched your search
+27
-28
@@ -4,41 +4,40 @@ using System.Resources;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ADOFAIRenderer.Util
|
||||
namespace ADOFAIRenderer.Util;
|
||||
|
||||
internal static class BundleLoader
|
||||
{
|
||||
internal static class BundleLoader
|
||||
private static readonly string BundlePlatform;
|
||||
private static readonly Assembly? ExecutingAssembly;
|
||||
|
||||
static BundleLoader()
|
||||
{
|
||||
private static readonly string BundlePlatform;
|
||||
private static readonly Assembly? ExecutingAssembly;
|
||||
|
||||
static BundleLoader()
|
||||
BundlePlatform = Application.platform switch
|
||||
{
|
||||
BundlePlatform = Application.platform switch
|
||||
{
|
||||
RuntimePlatform.WindowsPlayer => "Win64",
|
||||
RuntimePlatform.OSXPlayer => "OSX",
|
||||
_ => "Linux"
|
||||
};
|
||||
ExecutingAssembly = Assembly.GetExecutingAssembly();
|
||||
}
|
||||
RuntimePlatform.WindowsPlayer => "Win64",
|
||||
RuntimePlatform.OSXPlayer => "OSX",
|
||||
_ => "Linux"
|
||||
};
|
||||
ExecutingAssembly = Assembly.GetExecutingAssembly();
|
||||
}
|
||||
|
||||
public static AssetBundle GetBundle(string resourcePath)
|
||||
public static AssetBundle GetBundle(string resourcePath)
|
||||
{
|
||||
if (ExecutingAssembly != null)
|
||||
{
|
||||
if (ExecutingAssembly != null)
|
||||
var bundlePath = $"ADOFAIRenderer.Bundle.{BundlePlatform}.{resourcePath}";
|
||||
using var resourceStream = ExecutingAssembly.GetManifestResourceStream(bundlePath);
|
||||
if (resourceStream != null)
|
||||
{
|
||||
var bundlePath = $"ADOFAIRenderer.Bundle.{BundlePlatform}.{resourcePath}";
|
||||
using var resourceStream = ExecutingAssembly.GetManifestResourceStream(bundlePath);
|
||||
if (resourceStream != null)
|
||||
{
|
||||
return AssetBundle.LoadFromStream(resourceStream);
|
||||
}
|
||||
|
||||
Melon<RenderMod>.Logger.Error($"Could not find bundle resource in DLL.\n{bundlePath}");
|
||||
throw new MissingManifestResourceException("Could not find bundle resource in DLL.");
|
||||
return AssetBundle.LoadFromStream(resourceStream);
|
||||
}
|
||||
|
||||
Melon<RenderMod>.Logger.Error("Executing assembly has not been set properly.");
|
||||
throw new InvalidOperationException("ExecutingAssembly has not been set.");
|
||||
|
||||
Melon<RenderMod>.Logger.Error($"Could not find bundle resource in DLL.\n{bundlePath}");
|
||||
throw new MissingManifestResourceException("Could not find bundle resource in DLL.");
|
||||
}
|
||||
|
||||
Melon<RenderMod>.Logger.Error("Executing assembly has not been set properly.");
|
||||
throw new InvalidOperationException("ExecutingAssembly has not been set.");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user