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.Packets;
using KCM.Packets.Handlers;
@@ -142,4 +142,4 @@ namespace KCM
{
}
}
}
}

View File

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

View File

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