61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Simulator.Data;
|
|
|
|
public static class PrefabCatalogFromManager
|
|
{
|
|
public readonly struct Item
|
|
{
|
|
public readonly string Id; // 저장 키 = PrefabData.name
|
|
public readonly PrefabData Data;
|
|
|
|
public Item(string id, PrefabData data)
|
|
{
|
|
Id = id;
|
|
Data = data;
|
|
}
|
|
|
|
public string DisplayName =>
|
|
!string.IsNullOrWhiteSpace(Data?.label) ? Data.label :
|
|
!string.IsNullOrWhiteSpace(Data?.name) ? Data.name :
|
|
Id;
|
|
}
|
|
|
|
public static List<Item> GetSortedItems()
|
|
{
|
|
var dict = PrefabManager.Instance != null ? PrefabManager.Instance.prefabDict : null;
|
|
if (dict == null || dict.Count == 0) return new List<Item>();
|
|
|
|
return dict
|
|
.Select(kv => new Item(kv.Key, kv.Value))
|
|
.OrderBy(i => i.Data != null ? i.Data.priority_order : int.MaxValue)
|
|
.ThenBy(i => i.DisplayName)
|
|
.ToList();
|
|
}
|
|
|
|
public static bool TryGet(string prefabId, out Item item)
|
|
{
|
|
item = default;
|
|
|
|
if (PrefabManager.Instance == null) return false;
|
|
if (PrefabManager.Instance.prefabDict == null) return false;
|
|
|
|
if (!PrefabManager.Instance.prefabDict.TryGetValue(prefabId, out var data))
|
|
return false;
|
|
|
|
item = new Item(prefabId, data);
|
|
return true;
|
|
}
|
|
|
|
public static string ResolveDisplayName(string prefabId)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(prefabId))
|
|
return string.Empty;
|
|
|
|
if (TryGet(prefabId, out var item))
|
|
return item.DisplayName;
|
|
|
|
// 카탈로그에 없으면 그대로 표시
|
|
return prefabId;
|
|
}
|
|
} |