public int New() { int id; if (_reservedItemsCount > 0) { id = _reservedItems[--_reservedItemsCount]; } else { id = _itemsCount; if (_itemsCount == Items.Length) { Array.Resize(ref Items, _itemsCount << 1); } #if DEBUG if (EcsComponentType <T> .NeedCheckAutoReset && _autoReset == null) { throw new Exception($"AutoReset handler for component \"{ItemType.Name}\" should be initialized first."); } #endif // reset brand new instance if custom AutoReset was registered. _autoReset?.Invoke(ref Items[_itemsCount]); _itemsCount++; } return(id); }
public int Get() { if (_recycledItemsCount > 0) { return(_recycledItems[--_recycledItemsCount]); } if (Items.Length == _itemsCount) { Array.Resize(ref Items, _itemsCount << 1); } // reset brand new instance if custom AutoReset was registered. _autoReset?.Invoke(ref Items[_itemsCount]); return(_itemsCount++); }