コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        private async void StartBuilding()
        {
            await UniTask.Delay(TimeSpan.FromSeconds(_structure.BuildingTime), ignoreTimeScale : true);

            Builded?.Invoke(this, EventArgs.Empty);
        }