Exemplo n.º 1
0
        /// <summary> Destroys the given <see cref="Entity" />. </summary>
        /// <param name="entity"> [in,out] The <see cref="Entity" />. </param>
        public void Destroy(ref Entity entity)
        {
            // ReSharper disable once InconsistentlySynchronizedField
            if (_entityMap.TryGetValue(entity, out int index))
            {
                lock (_thisLock)
                {
                    _entityMap.Remove(entity);

                    _entitiesCount--;
                    _entities[index]          = _entities[_entitiesCount];
                    _entities[_entitiesCount] = null !;
                }
                lock (_toRemove)
                {
                    _toRemove.Add(entity);
                }
            }

            foreach (object component in entity.Components)
            {
                EntityComponentPool.Release((dynamic)component);
            }

            _entityPool.Release(entity);

            entity = null !;
        }
Exemplo n.º 2
0
        /// <summary> Removes a <typeparamref name="TComponent" /> from the specified <paramref name="entity" /> instance. </summary>
        /// <typeparam name="TComponent"> Type of the component. </typeparam>
        /// <param name="entity">     The entity. </param>
        /// <param name="usePooling"> True to use pooling. </param>
        /// <param name="action">     (Optional) The action. </param>
        /// <returns> An <see cref="EntityManager" />. </returns>
        public EntityManager Remove <TComponent>(Entity entity, bool usePooling, Action <TComponent>?action = null)
            where TComponent : class
        {
            if (entity.Get(out TComponent component))
            {
                entity.Remove <TComponent>();
                action?.Invoke(component);
                if (usePooling)
                {
                    EntityComponentPool <TComponent> .Release(component);
                }

                if (!entity.IsInitialized)
                {
                    return(this);
                }

                lock (_toChanged)
                {
                    _toChanged.Add(entity);
                }
            }
            return(this);
        }
Exemplo n.º 3
0
 public static void Release <TComponent>(TComponent component)
     where TComponent : class
 {
     EntityComponentPool <TComponent> .Release(component);
 }