public override void Startup()
        {
            base.Startup();

            _bulletContainer =
                ContainerManagerComponent.Ensure <Container>("magazine_bullet_container", Owner, out var existed);

            if (existed)
            {
                foreach (var entity in _bulletContainer.ContainedEntities)
                {
                    _loadedBullets.Push(entity);
                }
                _updateAppearance();
            }
            else if (_fillType != null)
            {
                // Load up bullets from fill.
                for (var i = 0; i < Capacity; i++)
                {
                    var bullet = Owner.EntityManager.SpawnEntity(_fillType);
                    AddBullet(bullet);
                }
            }

            OnAmmoCountChanged?.Invoke();
            _appearance.SetData(BallisticMagazineVisuals.AmmoCapacity, Capacity);
        }
        public IEntity TakeBullet()
        {
            if (_loadedBullets.Count == 0)
            {
                return(null);
            }

            var bullet = _loadedBullets.Pop();

            _updateAppearance();
            OnAmmoCountChanged?.Invoke();
            return(bullet);
        }
        public void AddBullet(IEntity bullet)
        {
            if (!bullet.TryGetComponent(out BallisticBulletComponent component))
            {
                throw new ArgumentException("entity isn't a bullet.", nameof(bullet));
            }

            if (component.Caliber != Caliber)
            {
                throw new ArgumentException("entity is of the wrong caliber.", nameof(bullet));
            }

            _bulletContainer.Insert(bullet);
            _loadedBullets.Push(bullet);
            _updateAppearance();
            OnAmmoCountChanged?.Invoke();
        }
        /// <inheritdoc />
        protected override void Startup()
        {
            base.Startup();

            _bulletContainer =
                ContainerManagerComponent.Ensure <Container>("magazine_bullet_container", Owner, out var existed);

            if (existed)
            {
                foreach (var entity in _bulletContainer.ContainedEntities)
                {
                    _loadedBullets.Push(entity);
                }
            }

            _updateAppearance();

            OnAmmoCountChanged?.Invoke();
            _appearance.SetData(BallisticMagazineVisuals.AmmoCapacity, Capacity);
        }
        public IEntity TakeBullet()
        {
            IEntity bullet;

            if (_loadedBullets.Count == 0)
            {
                if (_availableSpawnCount == 0)
                {
                    return(null);
                }

                _availableSpawnCount -= 1;
                bullet = Owner.EntityManager.SpawnEntity(FillType);
            }
            else
            {
                bullet = _loadedBullets.Pop();
                _bulletContainer.Remove(bullet);
            }

            _updateAppearance();
            OnAmmoCountChanged?.Invoke();
            return(bullet);
        }