public override bool HandlePropertyValuesChanged(
            IReadOnlyList <IPropertyValueChange> changes, TEntity entity, IEntityGroup <TEntity> group)
        {
            if (base.HandlePropertyValuesChanged(changes, entity, group))
            {
                return(true);
            }

            Component componentUsed = null;

            for (var i = 0; i < changes.Count; i++)
            {
                var change = changes[i];
                if (_sortValueGetter.PropertyUsed(change.ChangedComponent.ComponentId, change.ChangedPropertyName))
                {
                    componentUsed = change.ChangedComponent;
                    break;
                }

                // The component might have been removed by the previous change listener
                if (!entity.HasComponent(change.ChangedComponent.ComponentId))
                {
                    return(true);
                }
            }

            if (componentUsed == null)
            {
                return(false);
            }

            if (!KeyValueGetter.TryGetKey(entity, new IPropertyValueChange[0], getOldValue: false, out var key))
            {
                return(true);
            }

            var entities = GetOrAddEntities(key);

            if (_sortValueGetter.TryGetKey(entity, changes, getOldValue: true, out var oldSortKey))
            {
                entities.Remove(oldSortKey);
            }

            if (_sortValueGetter.TryGetKey(entity, changes, getOldValue: false, out var newSortKey))
            {
                entities.Add(newSortKey, entity);
            }

            if (entities.Count == 0)
            {
                Index.Remove(key);
            }

            return(true);
        }
Пример #2
0
 public void HandleEntityRemoved(
     TEntity entity, Component removedComponent, IEntityGroup <TEntity> group)
 {
     if (KeyValueGetter.TryGetKey(
             entity,
             new IPropertyValueChange[] { new PropertyValueChange <object>(removedComponent) },
             getOldValue: false,
             out var keyValue))
     {
         TryRemoveEntity(keyValue, entity, removedComponent);
     }
 }
Пример #3
0
        public virtual bool HandlePropertyValuesChanged(
            IReadOnlyList <IPropertyValueChange> changes, TEntity entity, IEntityGroup <TEntity> group)
        {
            Component componentUsed = null;

            for (var i = 0; i < changes.Count; i++)
            {
                var change = changes[i];
                if (KeyValueGetter.PropertyUsed(change.ChangedComponent.ComponentId, change.ChangedPropertyName))
                {
                    componentUsed = change.ChangedComponent;
                    break;
                }

                // The component might have been removed by the previous change listener
                if (!entity.HasComponent(change.ChangedComponent.ComponentId))
                {
                    return(true);
                }
            }

            if (componentUsed == null)
            {
                return(false);
            }

            if (KeyValueGetter.TryGetKey(entity, changes, getOldValue: true, out var oldKey))
            {
                TryRemoveEntity(oldKey, entity, componentUsed);
            }

            if (KeyValueGetter.TryGetKey(entity, changes, getOldValue: false, out var newKey))
            {
                TryAddEntity(newKey, entity, componentUsed);
            }

            return(true);
        }
 public bool ContainsEntity(TEntity entity)
 => KeyValueGetter.TryGetKey(entity, new IPropertyValueChange[0], getOldValue: false, out var referencedId) &&
 ReferencedGroup.ContainsEntity(referencedId);