78 lines
3.0 KiB
C#
78 lines
3.0 KiB
C#
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.instance != null)
|
|
{
|
|
helper = Main.instance.helper;
|
|
}
|
|
|
|
if (helper == null)
|
|
{
|
|
Debug.Log("KCM: PrefabManager helper is null, cannot proceed.");
|
|
return;
|
|
}
|
|
|
|
assetBundle = helper.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<GameObject>("assets/workspace/serverbrowser.prefab");
|
|
serverEntryItemPrefab = assetBundle.LoadAsset<GameObject>("assets/workspace/serverentryitem.prefab");
|
|
|
|
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)
|
|
{
|
|
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());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |