57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
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<PipelineProduct> _pool;
|
|
private SingleSelector<CheckData> _selector;
|
|
|
|
|
|
public PipelineFactory(Transform root, PipelineSystem pipelineSystem, CheckData[] datas)
|
|
{
|
|
_root = root;
|
|
_pool = new SimpleObjectPool<PipelineProduct>(InstantiateProduct, ResetProduce);
|
|
_selector = new SingleSelector<CheckData>(datas, _ => 1);
|
|
_productPrefab = ResourceKit.LoadAssetSync<GameObject>(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<PipelineProduct>();
|
|
}
|
|
|
|
private void ResetProduce(PipelineProduct product)
|
|
{
|
|
product.gameObject.SetActive(false);
|
|
product.transform.position = _root.position;
|
|
}
|
|
}
|
|
} |