using System; using System.Linq; using UnityEngine; namespace KCM { public class PrefabManager { public static KCModHelper helper; public static AssetBundle assetBundle; public static GameObject serverBrowserPrefab; public static GameObject serverEntryItemPrefab; public static GameObject serverLobbyPrefab; public static GameObject serverLobbyPlayerEntryPrefab; public static GameObject serverChatEntryPrefab; public static GameObject serverChatSystemEntryPrefab; public static GameObject modalUIPrefab; public static void PreScriptLoad(KCModHelper _helper) { try { if (_helper != null) { helper = _helper; } else if (Main.helper != null) { helper = Main.helper; } if (helper == null) { Debug.Log("KCM: PrefabManager helper is null, cannot proceed."); return; } // LoadAssetBundle is a static method, so we call it on the class, not the instance. // We pass the modPath from the helper instance we have. assetBundle = KCModHelper.LoadAssetBundle(helper.modPath, "serverbrowserpkg"); if (assetBundle == null) { helper.Log("ERROR: Asset bundle 'serverbrowserpkg' not found! UI features will not work."); helper.Log("Please ensure the asset bundle file is in the mod directory."); return; } helper.Log("Asset bundle loaded successfully"); helper.Log("Assets in bundle: " + String.Join(", ", assetBundle.GetAllAssetNames())); serverBrowserPrefab = assetBundle.LoadAsset("assets/workspace/serverbrowser.prefab"); serverEntryItemPrefab = assetBundle.LoadAsset("assets/workspace/serverentryitem.prefab"); serverLobbyPrefab = assetBundle.LoadAsset("assets/workspace/serverlobby.prefab"); serverLobbyPlayerEntryPrefab = assetBundle.LoadAsset("assets/workspace/serverlobbyplayerentry.prefab"); serverChatEntryPrefab = assetBundle.LoadAsset("assets/workspace/serverchatentry.prefab"); serverChatSystemEntryPrefab = assetBundle.LoadAsset("assets/workspace/serverchatsystementry.prefab"); modalUIPrefab = assetBundle.LoadAsset("assets/workspace/modalui.prefab"); helper.Log("Loaded all UI prefabs successfully"); } catch (Exception ex) { if (helper != null) { helper.Log("ERROR loading asset bundle:"); helper.Log(ex.ToString()); } else { Debug.Log("ERROR in PrefabManager.PreScriptLoad, helper is null: " + ex.ToString()); } } } } }