Fix formatting issues and improve error handling in PrefabManager and LobbyManager
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Harmony;
|
||||
using Harmony;
|
||||
using KCM.Enums;
|
||||
using KCM.Packets;
|
||||
using KCM.Packets.Handlers;
|
||||
|
||||
@@ -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;
|
||||
@@ -21,44 +19,59 @@ namespace KCM
|
||||
public static GameObject modalUIPrefab;
|
||||
|
||||
public static void PreScriptLoad(KCModHelper _helper)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_helper != null)
|
||||
{
|
||||
helper = _helper;
|
||||
if (helper == null)
|
||||
}
|
||||
else if (Main.instance != null)
|
||||
{
|
||||
helper = Main.instance.helper;
|
||||
}
|
||||
|
||||
var assetBundle = helper.LoadAssetBundle(helper.modPath, "serverbrowserpkg");
|
||||
|
||||
if (assetBundle == null)
|
||||
if (helper == 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.");
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using KCM;
|
||||
using KCM;
|
||||
using KCM.Enums;
|
||||
using KCM.Packets.Handlers;
|
||||
using Steamworks;
|
||||
|
||||
Reference in New Issue
Block a user