feat: prefab loader
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
@@ -10,6 +11,9 @@ namespace IngameReveries
|
||||
public class IngameReveries : ModBehaviour
|
||||
{
|
||||
private GameObject _ingameReveriesUI;
|
||||
|
||||
private AssetBundle _reveriesBundle;
|
||||
private GameObject _reveriesPrefab;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -23,6 +27,8 @@ namespace IngameReveries
|
||||
|
||||
private void Start()
|
||||
{
|
||||
InitializeAssets();
|
||||
|
||||
SceneManager.sceneLoaded += (scene, mode) =>
|
||||
{
|
||||
// Check if UI already instantiated
|
||||
@@ -58,5 +64,56 @@ namespace IngameReveries
|
||||
Debug.Log("Good bye! " + mod.metadata.id);
|
||||
harmony.UnpatchAll();
|
||||
}
|
||||
|
||||
private void InitializeAssets()
|
||||
{
|
||||
string bundlePath = Path.Combine(mod.path, "assets", "bundle");
|
||||
|
||||
if (!File.Exists(bundlePath))
|
||||
{
|
||||
Debug.LogError($"[IngameReveries] Bundle not found at: {bundlePath}");
|
||||
return;
|
||||
}
|
||||
|
||||
_reveriesBundle = AssetBundle.GetAllLoadedAssetBundles()
|
||||
.FirstOrDefault(b => b.name == "logosteal" || b.mainAsset != null);
|
||||
|
||||
if (_reveriesBundle == null)
|
||||
{
|
||||
// If it isn't loaded yet, load it from disk
|
||||
Debug.Log("[IngameReveries] Loading Bundle");
|
||||
_reveriesBundle = AssetBundle.LoadFromFile(bundlePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[IngameReveries] Bundle already loaded");
|
||||
}
|
||||
|
||||
if (_reveriesBundle == null)
|
||||
{
|
||||
Debug.LogError("[IngameReveries] Failed to load AssetBundle!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the prefab from the bundle
|
||||
string assetName = _reveriesBundle.GetAllAssetNames().First();
|
||||
_reveriesPrefab = _reveriesBundle.LoadAsset<GameObject>(assetName);
|
||||
|
||||
if (_reveriesPrefab == null)
|
||||
{
|
||||
Debug.LogError("[IngameReveries] Failed to load prefab!");
|
||||
|
||||
// List what's in the bundle for debugging
|
||||
string[] assetNames = _reveriesBundle.GetAllAssetNames();
|
||||
Debug.Log("[IngameReveries] Assets in bundle:");
|
||||
foreach (string name in assetNames)
|
||||
{
|
||||
Debug.Log($" - {name}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("[IngameReveries] Successfully loaded prefab!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user