using AibisDream.Framework; using AibisDream.Kit; using AibisDream.Utility; using UnityEngine; namespace AibisDream { public class BubbleFactory { private readonly SimpleObjectPool _pool; private readonly GameObject _bubblePrefab; private readonly Transform _bubbleRoot; private readonly BubbleGroup _bubbleGroup; public BubbleFactory(Transform bubbleRoot) { _bubbleRoot = bubbleRoot; _bubblePrefab = ResourceKit.LoadAssetSync(ConstRef.BubblePrefab); _pool = new SimpleObjectPool(InstantiateBubble); } public BubbleFactory(BubbleGroup bubbleGroup) { _bubbleGroup = bubbleGroup; _bubbleRoot = bubbleGroup.transform; _bubblePrefab = ResourceKit.LoadAssetSync(ConstRef.BubblePrefab); _pool = new SimpleObjectPool(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(); } } }