public ObjectPool(T template, List <T> list, Func <T, T> builder = null) { this.builder = builder; Template = template; originCount = list.Count; itemList = new List <PoolItem>(list.Count); for (int index = 0; index < list.Count; ++index) { if (list[index] == null) { continue; } PoolItem item = new PoolItem(list[index]); ++residueCount; itemList.Add(item); item.poolItem?.OnCreated(this); Created?.Invoke(item.instance); } version++; Builded?.Invoke(); }
private void Rebuild(int count) { for (int i = itemList.Count; i < count; ++i) { T instance = BuildImpl(Template); PoolItem item = new PoolItem(instance); ++residueCount; item.instance = instance; itemList.Add(item); item.poolItem?.OnCreated(this); Created?.Invoke(item.instance); } Builded?.Invoke(); }
private async void StartBuilding() { await UniTask.Delay(TimeSpan.FromSeconds(_structure.BuildingTime), ignoreTimeScale : true); Builded?.Invoke(this, EventArgs.Empty); }