public T GetItem() { ObjectPoolContainer <T> container = null; for (int i = 0; i < list.Count; i++) { lastIndex++; if (lastIndex > list.Count - 1) { lastIndex = 0; } if (list[lastIndex].Used) { continue; } else { container = list[lastIndex]; break; } } if (container == null) { container = CreateConatiner(); } container.Consume(); lookup.Add(container.Item, container); return(container.Item); }
private ObjectPoolContainer <T> CreateConatiner() { var container = new ObjectPoolContainer <T>(); container.Item = factoryFunc(); list.Add(container); return(container); }
public EtlPipelineContext(IEtlPipelineConfig config) { State = new ConcurrentDictionary <string, object>(); ObjectPool = new ObjectPoolContainer(); Config = config; _dbConnectionFactory = new DbConnectionFactory(); _errors = new ConcurrentBag <EtlOperationError>(); }
public void RemoveContainer(int size = 1) { for (int i = 0; i < size; i++) { ObjectPoolContainer <T> container = unUsedStack.Pop(); container.Release(); GameObject.Destroy(container.item); currentSize--; } }
// === break 202004210343 === // ?统一以 transform 或 gameObject 做标识 ... public bool Release(T item) { //public bool Release(GameObject item) { //temp2 = item; //temp4 = item.gameObject; if (usedDict.ContainsKey(item)) { ObjectPoolContainer <T> container = usedDict[item]; container.Release(); usedDict.Remove(item); unUsedStack.Push(container); //Debug.Log(item.name + " pool T"); return(true); } else { //Debug.Log(item.name + " pool F"); return(false); } }
//public T temp1; //public T temp2; //public GameObject temp3; //public GameObject temp4; //public ObjectPoolContainer<T> temp5; #region 对象获取和释放 public T Get(Vector3 pos = default(Vector3), Vector3 ang = default(Vector3)) { if (unUsedStack.Count <= 0) { IncreContainer(); } ObjectPoolContainer <T> container = unUsedStack.Pop(); T returnObj = container.Consume(); usedDict.Add(returnObj, container); //usedDict.Add(returnObj.gameObject, container); //returnObj.transform.SetParent(parentTf, true); returnObj.transform.position = pos; returnObj.transform.eulerAngles = ang; //temp1 = returnObj; // ?GetType() : transform ... // ?GameObject.Instantiate<Component>(prefab) 得到的是 transform ... //temp3 = returnObj.gameObject; //temp5 = container; return(returnObj); }
void OnDestroy() { instance = null; }
private void Awake() { sharedInstance = this; InstantiateAllObjects(); }
private void Awake() { Instance = this; }