Files
AIGame/AIClient/Assets/HotUpdate/Scripts/UI/UiPrefabLoader.cs
T
udxandCursor c94b8fefeb Add MainHUD gameplay UI, net handshake updates, and server maintenance mode.
Introduce UiManager/MainHUD prefab flow, strengthen GameNet/WsClient, and add AIServer maintenance endpoint support.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-21 17:34:42 +08:00

40 lines
1.3 KiB
C#

using UnityEngine;
using YooAsset;
namespace HotUpdate.UI
{
/// <summary>
/// UI Prefab 加载:编辑器 AssetDatabase;运行时优先 DefaultPackage 寻址。
/// </summary>
public sealed class UiPrefabLoader
{
public const string PrefabFolder = "Assets/Bundles/UI/Prefab";
public GameObject Load(string prefabName)
{
if (string.IsNullOrEmpty(prefabName)) return null;
if (YooAssets.IsInitialized)
{
// DefaultPackage 或任意已初始化包
var packages = new[] { "DefaultPackage", "Art" };
foreach (var name in packages)
{
if (!YooAssets.TryGetPackage(name, out var pkg)) continue;
if (pkg.InitializeStatus != EOperationStatus.Succeeded) continue;
var handle = pkg.LoadAssetSync<GameObject>(prefabName);
if (handle.Status == EOperationStatus.Succeeded)
return handle.GetAssetObject<GameObject>();
}
}
#if UNITY_EDITOR
var path = $"{PrefabFolder}/{prefabName}.prefab";
return UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
#else
return null;
#endif
}
}
}