mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add load bundle method
This commit is contained in:
parent
9233d103ac
commit
43d70b21d9
@ -98,31 +98,38 @@ 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);
|
||||||
|
AssetBundle bundle;
|
||||||
|
|
||||||
|
if (AssetBundles.ContainsKey(key))
|
||||||
|
{
|
||||||
|
bundle = AssetBundles[key].bundle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var completePath = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, assetBundleRelativeDir);
|
||||||
|
bundle = AssetBundle.LoadFromFile(completePath);
|
||||||
|
if (bundle == null)
|
||||||
|
{
|
||||||
|
NHLogger.LogError($"Couldn't load AssetBundle at [{completePath}] for [{mod.ModHelper.Manifest.Name}]");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetBundles[key] = (bundle, keepLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T Load<T>(string assetBundleRelativeDir, string pathInBundle, IModBehaviour mod) where T : UnityEngine.Object
|
||||||
|
{
|
||||||
T obj;
|
T obj;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AssetBundle bundle;
|
AssetBundle bundle = LoadBundle(assetBundleRelativeDir, mod);
|
||||||
|
|
||||||
if (AssetBundles.ContainsKey(key))
|
|
||||||
{
|
|
||||||
bundle = AssetBundles[key].bundle;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var completePath = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, assetBundleRelativeDir);
|
|
||||||
bundle = AssetBundle.LoadFromFile(completePath);
|
|
||||||
if (bundle == null)
|
|
||||||
{
|
|
||||||
NHLogger.LogError($"Couldn't load AssetBundle at [{completePath}] for [{mod.ModHelper.Manifest.Name}]");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
AssetBundles[key] = (bundle, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
obj = bundle.LoadAsset<T>(pathInBundle);
|
obj = bundle.LoadAsset<T>(pathInBundle);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user