加入很多新内容,这波一块交了
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Bansonic
|
||||
{
|
||||
public static class gItemGet
|
||||
{
|
||||
private const string PrefabResourcePath = "itemGet";
|
||||
private static readonly Color FallbackColor = Color.white;
|
||||
|
||||
private static GameObject currentInstance;
|
||||
private static itemGetPrefab currentController;
|
||||
private static ItemRarityColorConfigSO cachedRarityConfig;
|
||||
|
||||
public struct ItemEntry
|
||||
{
|
||||
public Sprite icon;
|
||||
public string displayName;
|
||||
public int amount;
|
||||
public ItemRarity rarity;
|
||||
public bool useCustomColor;
|
||||
public Color customColor;
|
||||
}
|
||||
|
||||
public static void display(params ItemEntry[] items)
|
||||
{
|
||||
display((IEnumerable<ItemEntry>)items);
|
||||
}
|
||||
|
||||
public static void display(IEnumerable<ItemEntry> items)
|
||||
{
|
||||
EnsureInstance();
|
||||
if (currentController == null)
|
||||
{
|
||||
Debug.LogWarning("[gItemGet] itemGet prefab missing itemGetPrefab component.");
|
||||
return;
|
||||
}
|
||||
|
||||
currentController.ClearItems();
|
||||
|
||||
if (items == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (ItemEntry entry in items)
|
||||
{
|
||||
get_item_prefab item = currentController.AddItem();
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Color qualityColor = entry.useCustomColor
|
||||
? entry.customColor
|
||||
: ResolveRarityColor(entry.rarity);
|
||||
|
||||
item.Bind(entry.icon, entry.displayName, entry.amount, qualityColor);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemEntry Create(string displayName, Sprite icon, int amount = 1, ItemRarity rarity = ItemRarity.None)
|
||||
{
|
||||
return new ItemEntry
|
||||
{
|
||||
displayName = displayName,
|
||||
icon = icon,
|
||||
amount = Mathf.Max(1, amount),
|
||||
rarity = rarity,
|
||||
useCustomColor = false,
|
||||
customColor = default
|
||||
};
|
||||
}
|
||||
|
||||
public static ItemEntry Create(string displayName, Sprite icon, int amount, Color qualityColor)
|
||||
{
|
||||
return new ItemEntry
|
||||
{
|
||||
displayName = displayName,
|
||||
icon = icon,
|
||||
amount = Mathf.Max(1, amount),
|
||||
rarity = ItemRarity.None,
|
||||
useCustomColor = true,
|
||||
customColor = qualityColor
|
||||
};
|
||||
}
|
||||
|
||||
public static ItemEntry FromStoreItem(storeItemSO item, int amount = 1)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return Create("未知物品", null, amount, ItemRarity.None);
|
||||
}
|
||||
|
||||
return Create(item.itemName, item.itemIcon, amount, item.itemRarity);
|
||||
}
|
||||
|
||||
public static ItemEntry FromExpBottle(expBottlesSO item, int amount = 1)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return Create("未知经验瓶", null, amount, ItemRarity.None);
|
||||
}
|
||||
|
||||
return Create(item.expBottleName, item.expBottleSprite, amount, item.itemRarity);
|
||||
}
|
||||
|
||||
public static ItemEntry FromGrowthMaterial(growthMaterialSO item, int amount = 1)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return Create("未知培养材料", null, amount, ItemRarity.None);
|
||||
}
|
||||
|
||||
return Create(item.growthMaterialName, item.growthMaterialSprite, amount, item.itemRarity);
|
||||
}
|
||||
|
||||
public static ItemEntry FromEquipmentConsumable(equipmentConsumableSO item, int amount = 1)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return Create("未知装备材料", null, amount, ItemRarity.None);
|
||||
}
|
||||
|
||||
return Create(item.consumableName, item.consumableSprite, amount, item.itemRarity);
|
||||
}
|
||||
|
||||
public static ItemEntry FromEquipment(equipmentSO equipment, int amount = 1)
|
||||
{
|
||||
if (equipment == null)
|
||||
{
|
||||
return Create("未知记忆", null, amount, ItemRarity.None);
|
||||
}
|
||||
|
||||
return Create(
|
||||
equipment.GetDisplayTierName(),
|
||||
equipment.GetCurrentEquipmentSprite(),
|
||||
amount,
|
||||
ResolveEquipmentColor(equipment));
|
||||
}
|
||||
|
||||
private static void EnsureInstance()
|
||||
{
|
||||
if (currentInstance != null && currentController != null)
|
||||
{
|
||||
if (!currentInstance.activeInHierarchy)
|
||||
{
|
||||
currentInstance.SetActive(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject prefab = Resources.Load<GameObject>(PrefabResourcePath);
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogWarning("[gItemGet] Failed to load Resources/itemGet.prefab");
|
||||
return;
|
||||
}
|
||||
|
||||
Transform parent = ResolveParent();
|
||||
currentInstance = parent != null
|
||||
? Object.Instantiate(prefab, parent, false)
|
||||
: Object.Instantiate(prefab);
|
||||
|
||||
currentInstance.name = prefab.name;
|
||||
currentController = currentInstance.GetComponent<itemGetPrefab>();
|
||||
}
|
||||
|
||||
private static Transform ResolveParent()
|
||||
{
|
||||
Canvas[] canvases = Object.FindObjectsByType<Canvas>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
||||
Canvas best = null;
|
||||
|
||||
for (int i = 0; i < canvases.Length; i++)
|
||||
{
|
||||
Canvas canvas = canvases[i];
|
||||
if (canvas == null || !canvas.gameObject.activeInHierarchy || !canvas.isRootCanvas)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (best == null || canvas.sortingOrder >= best.sortingOrder)
|
||||
{
|
||||
best = canvas;
|
||||
}
|
||||
}
|
||||
|
||||
return best != null ? best.transform : null;
|
||||
}
|
||||
|
||||
private static Color ResolveRarityColor(ItemRarity rarity)
|
||||
{
|
||||
if (cachedRarityConfig == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
cachedRarityConfig = UnityEditor.AssetDatabase.LoadAssetAtPath<ItemRarityColorConfigSO>(
|
||||
"Assets/playerBagSystem/ItemRarityColorConfig.asset");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (cachedRarityConfig != null)
|
||||
{
|
||||
return cachedRarityConfig.GetColor(rarity, FallbackColor);
|
||||
}
|
||||
|
||||
switch (rarity)
|
||||
{
|
||||
case ItemRarity.Common:
|
||||
return new Color32(95, 155, 107, 255);
|
||||
case ItemRarity.Uncommon:
|
||||
return new Color32(74, 134, 184, 255);
|
||||
case ItemRarity.Rare:
|
||||
return new Color32(106, 76, 156, 255);
|
||||
case ItemRarity.Epic:
|
||||
return new Color32(184, 134, 69, 255);
|
||||
case ItemRarity.Legendary:
|
||||
return new Color32(184, 76, 76, 255);
|
||||
case ItemRarity.Mythic:
|
||||
return new Color32(217, 108, 158, 255);
|
||||
case ItemRarity.Supreme:
|
||||
return new Color32(255, 103, 164, 255);
|
||||
default:
|
||||
return FallbackColor;
|
||||
}
|
||||
}
|
||||
|
||||
private static Color ResolveEquipmentColor(equipmentSO equipment)
|
||||
{
|
||||
if (equipment == null)
|
||||
{
|
||||
return FallbackColor;
|
||||
}
|
||||
|
||||
int index = equipment.GetVisualQualityColorIndex();
|
||||
switch (index)
|
||||
{
|
||||
case 1:
|
||||
return new Color32(95, 155, 107, 255);
|
||||
case 2:
|
||||
return new Color32(74, 134, 184, 255);
|
||||
case 3:
|
||||
return new Color32(106, 76, 156, 255);
|
||||
case 4:
|
||||
return new Color32(184, 134, 69, 255);
|
||||
case 5:
|
||||
return new Color32(184, 76, 76, 255);
|
||||
default:
|
||||
return new Color32(255, 103, 164, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82dd3d62659b6a64e88a02d137a400ac
|
||||
Reference in New Issue
Block a user