Add load bundle method

This commit is contained in:
Noah Pilarski 2025-08-04 21:04:42 -04:00
parent 9233d103ac
commit 43d70b21d9

View File

@ -98,13 +98,9 @@ namespace NewHorizons.Utility.Files
/// </summary> /// </summary>
public static bool AreRequiredAssetsLoaded() => _loadingBundles.Count == 0; public static bool AreRequiredAssetsLoaded() => _loadingBundles.Count == 0;
public static T Load<T>(string assetBundleRelativeDir, string pathInBundle, IModBehaviour mod) where T : UnityEngine.Object public static AssetBundle LoadBundle(string assetBundleRelativeDir, IModBehaviour mod, bool keepLoaded = false)
{ {
string key = Path.GetFileName(assetBundleRelativeDir); string key = Path.GetFileName(assetBundleRelativeDir);
T obj;
try
{
AssetBundle bundle; AssetBundle bundle;
if (AssetBundles.ContainsKey(key)) if (AssetBundles.ContainsKey(key))
@ -121,9 +117,20 @@ namespace NewHorizons.Utility.Files
return null; return null;
} }
AssetBundles[key] = (bundle, false); AssetBundles[key] = (bundle, keepLoaded);
} }
return bundle;
}
public static T Load<T>(string assetBundleRelativeDir, string pathInBundle, IModBehaviour mod) where T : UnityEngine.Object
{
T obj;
try
{
AssetBundle bundle = LoadBundle(assetBundleRelativeDir, mod);
obj = bundle.LoadAsset<T>(pathInBundle); obj = bundle.LoadAsset<T>(pathInBundle);
} }
catch (Exception e) catch (Exception e)