using AibisDream.Framework; using AibisDream.Kit; using AibisDream.Utility; using UnityEngine; namespace AibisDream.FixSystem { public class PipelineFactory { private Transform _root; private GameObject _productPrefab; private PipelineSystem _pipelineSystem; private SimpleObjectPool _pool; private SingleSelector _selector; public PipelineFactory(Transform root, PipelineSystem pipelineSystem, CheckData[] datas) { _root = root; _pool = new SimpleObjectPool(InstantiateProduct, ResetProduce); _selector = new SingleSelector(datas, _ => 1); _productPrefab = ResourceKit.LoadAssetSync(ConstRef.PipelinePrefabAddress); _pipelineSystem = pipelineSystem; } public PipelineProduct Create() { var product = _pool.Allocate(); var data = _selector.Select(); product.Init(_pipelineSystem.wayPoints, data, _pipelineSystem); product.OnRecycled += Recycle; return product; } private void Recycle(PipelineProduct product, bool isSuccess) { product.Reset(); _pool.Recycle(product); _pipelineSystem.OnProductEnd(product, isSuccess); } private PipelineProduct InstantiateProduct() { var product = Object.Instantiate(_productPrefab, _root).transform; product.position = _root.position; return product.GetComponent(); } private void ResetProduce(PipelineProduct product) { product.gameObject.SetActive(false); product.transform.position = _root.position; } } }