Files
aibis-dream/Assets/Scripts/UI/DialogUI/Bubbles/BubbleFactory.cs
T
2025-06-06 22:58:50 +08:00

36 lines
989 B
C#

using AibisDream.Framework;
using AibisDream.Kit;
using AibisDream.Utility;
using UnityEngine;
namespace AibisDream
{
public class BubbleFactory
{
private readonly SimpleObjectPool<Bubble> _pool;
private readonly GameObject _bubblePrefab;
private readonly Transform _bubbleRoot;
public BubbleFactory(Transform bubbleRoot)
{
_bubbleRoot = bubbleRoot;
_bubblePrefab = ResourceKit.LoadAssetSync<GameObject>(ConstRef.BubblePrefab);
_pool = new SimpleObjectPool<Bubble>(InstantiateBubble);
}
public Bubble Create(BubbleSlotData data)
{
var bubble = _pool.Allocate();
bubble.OnDisposed += o => _pool.Recycle(o);
bubble.LoadConfig(data);
return bubble;
}
private Bubble InstantiateBubble()
{
return Object.Instantiate(_bubblePrefab, _bubbleRoot).GetComponent<Bubble>();
}
}
}