Files
aibis-dream/Assets/Scripts/Framework/OtherKit/BubbleSlotKit.cs
T

95 lines
2.4 KiB
C#

using System.Collections.Generic;
using AibisDream.Kit;
using UnityEngine;
namespace AibisDream.Framework
{
public class BubbleSlotKit : SingletonBase<BubbleSlotKit>
{
private readonly Dictionary<BubbleSlotEnum, BubbleSlotGroup> _slotDict = new();
private BubbleSlotKit()
{
}
public void Register(BubbleSlotEnum slotType, BubbleSlotGroup group)
{
if (slotType == BubbleSlotEnum.Default)
{
Debug.LogWarning("[BubbleSlotKit] 不能注册 Default 类型的气泡槽组。");
return;
}
if (_slotDict.TryGetValue(slotType, out var existing) && existing != null && existing != group)
{
Debug.LogWarning(
$"[BubbleSlotKit] {slotType} 已被 \"{existing.name}\" 注册,将被 \"{group.name}\" 覆盖");
}
_slotDict[slotType] = group;
}
public void Unregister(BubbleSlotEnum slotType)
{
_slotDict.Remove(slotType);
}
public void RemoveAll()
{
_slotDict.Clear();
}
public bool TryGet(BubbleSlotEnum slotType, out BubbleSlotGroup group)
{
if (_slotDict.TryGetValue(slotType, out group) && group != null)
{
return true;
}
group = null;
return false;
}
public BubbleSlotGroupData CollectData(BubbleSlotEnum slotType)
{
if (!TryGet(slotType, out var group))
{
Debug.LogWarning($"[BubbleSlotKit] CollectData: {slotType} 气泡槽组未注册");
return default;
}
return group.CollectData();
}
public void LoadBubbles(BubbleSlotEnum slotType)
{
if (!TryGet(slotType, out var group))
{
Debug.LogWarning($"[BubbleSlotKit] LoadBubbles: {slotType} 气泡槽组未注册");
return;
}
DialogUIManager.Instance.LoadBubbles(group.CollectData());
}
}
public enum BubbleSlotEnum
{
Default,
Clinic,
BodyModule,
Memory,
Eye,
Cut,
Open,
Sales,
Subway,
SubwayTV,
Outside,
Tarot,
Emo,
Expression,
Analysis
}
}