Fix formatting issues and improve error handling in PrefabManager and LobbyManager

This commit is contained in:
2025-12-14 21:49:32 +01:00
parent 11a4660881
commit 4277098e13
3 changed files with 47 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
using Harmony; using Harmony;
using KCM.Enums; using KCM.Enums;
using KCM.Packets; using KCM.Packets;
using KCM.Packets.Handlers; using KCM.Packets.Handlers;
@@ -142,4 +142,4 @@ namespace KCM
{ {
} }
} }
} }

View File

@@ -1,14 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
namespace KCM namespace KCM
{ {
public class PrefabManager public class PrefabManager
{ {
public static KCModHelper helper;
public static AssetBundle assetBundle; public static AssetBundle assetBundle;
public static GameObject serverBrowserPrefab; public static GameObject serverBrowserPrefab;
public static GameObject serverEntryItemPrefab; public static GameObject serverEntryItemPrefab;
@@ -22,44 +20,59 @@ namespace KCM
public static void PreScriptLoad(KCModHelper _helper) public static void PreScriptLoad(KCModHelper _helper)
{ {
helper = _helper; try
if (helper == null)
{ {
helper = Main.instance.helper; if (_helper != null)
} {
helper = _helper;
}
else if (Main.instance != null)
{
helper = Main.instance.helper;
}
var assetBundle = helper.LoadAssetBundle(helper.modPath, "serverbrowserpkg"); if (helper == null)
{
if (assetBundle == null) Debug.Log("KCM: PrefabManager helper is null, cannot proceed.");
{
Main.helper.Log("ERROR: Asset bundle 'serverbrowserpkg' not found! UI features will not work.");
Main.helper.Log("Please ensure the asset bundle file is in the mod directory.");
return; return;
} }
Main.helper.Log("Asset bundle loaded successfully"); assetBundle = helper.LoadAssetBundle(helper.modPath, "serverbrowserpkg");
Main.helper.Log("Assets in bundle: " + String.Join(", ", assetBundle.GetAllAssetNames()));
serverBrowserPrefab = assetBundle.LoadAsset("assets/workspace/serverbrowser.prefab") as GameObject; if (assetBundle == null)
serverEntryItemPrefab = assetBundle.LoadAsset("assets/workspace/serverentryitem.prefab") as GameObject; {
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;
}
serverLobbyPrefab = assetBundle.LoadAsset("assets/workspace/serverlobby.prefab") as GameObject; helper.Log("Asset bundle loaded successfully");
serverLobbyPlayerEntryPrefab = assetBundle.LoadAsset("assets/workspace/serverlobbyplayerentry.prefab") as GameObject; helper.Log("Assets in bundle: " + String.Join(", ", assetBundle.GetAllAssetNames()));
serverChatEntryPrefab = assetBundle.LoadAsset("assets/workspace/serverchatentry.prefab") as GameObject;
serverChatSystemEntryPrefab = assetBundle.LoadAsset("assets/workspace/serverchatsystementry.prefab") as GameObject;
modalUIPrefab = assetBundle.LoadAsset("assets/workspace/modalui.prefab") as GameObject; serverBrowserPrefab = assetBundle.LoadAsset<GameObject>("assets/workspace/serverbrowser.prefab");
serverEntryItemPrefab = assetBundle.LoadAsset<GameObject>("assets/workspace/serverentryitem.prefab");
Main.helper.Log("Loaded all UI prefabs successfully"); serverLobbyPrefab = assetBundle.LoadAsset<GameObject>("assets/workspace/serverlobby.prefab");
serverLobbyPlayerEntryPrefab = assetBundle.LoadAsset<GameObject>("assets/workspace/serverlobbyplayerentry.prefab");
serverChatEntryPrefab = assetBundle.LoadAsset<GameObject>("assets/workspace/serverchatentry.prefab");
serverChatSystemEntryPrefab = assetBundle.LoadAsset<GameObject>("assets/workspace/serverchatsystementry.prefab");
modalUIPrefab = assetBundle.LoadAsset<GameObject>("assets/workspace/modalui.prefab");
helper.Log("Loaded all UI prefabs successfully");
} }
catch (Exception ex) catch (Exception ex)
{ {
Main.helper.Log("ERROR loading asset bundle:"); if (helper != null)
Main.helper.Log(ex.ToString()); {
Main.helper.Log(ex.Message); helper.Log("ERROR loading asset bundle:");
Main.helper.Log(ex.StackTrace); helper.Log(ex.ToString());
}
else
{
Debug.Log("ERROR in PrefabManager.PreScriptLoad, helper is null: " + ex.ToString());
}
} }
} }
} }
} }

View File

@@ -1,4 +1,4 @@
using KCM; using KCM;
using KCM.Enums; using KCM.Enums;
using KCM.Packets.Handlers; using KCM.Packets.Handlers;
using Steamworks; using Steamworks;
@@ -187,4 +187,4 @@ namespace Riptide.Demos.Steam.PlayerHosted
} }
} }
} }
} }