Files
aibis-dream/Assets/Scripts/UI/DialogUI/Bubbles/BubbleFactory.cs
T
dingyuntian 24d23b29d1 问题修复
1. CenterText效果异常修复
2. 部分气泡宽度不合预期修复
3. 删除切割日志
2026-01-03 17:40:11 +08:00

46 lines
1.4 KiB
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;
private readonly BubbleGroup _bubbleGroup;
public BubbleFactory(Transform bubbleRoot)
{
_bubbleRoot = bubbleRoot;
_bubblePrefab = ResourceKit.LoadAssetSync<GameObject>(ConstRef.BubblePrefab);
_pool = new SimpleObjectPool<Bubble>(InstantiateBubble);
}
public BubbleFactory(BubbleGroup bubbleGroup)
{
_bubbleGroup = bubbleGroup;
_bubbleRoot = bubbleGroup.transform;
_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, _bubbleGroup);
bubble.Hide();
return bubble;
}
private Bubble InstantiateBubble()
{
return Object.Instantiate(_bubblePrefab, _bubbleRoot).GetComponent<Bubble>();
}
}
}