/// <summary>
        /// Removes an Id from the Ids Buffer
        /// </summary>
        /// <param name="entityManager"></param>
        /// <param name="id"></param>
        private static void RemoveId(EntityManager entityManager, int id)
        {
            DynamicBuffer <IntBufferElement> _Ids          = Ids.GetValue(entityManager);
            DynamicBuffer <IntBufferElement> _AvailibleIds = AvailibleIds.GetValue(entityManager);
            bool match = false;

            for (int i = 0; i < _Ids.Length; i++)
            {
                if (id == _Ids[i].Value)
                {
                    // if id is at the end then we just remove it
                    if (i == _Ids.Length - 1)
                    {
                        _Ids.RemoveAt(i);
                        // add it to availible ids so we can reuse ids
                    }
                    else
                    {
                        _Ids.RemoveAt(i);
                        _AvailibleIds.Add(new IntBufferElement {
                            Value = id
                        });
                    }
                    match = true;
                }
            }
            if (!match)
            {
                Debug.LogWarning("ProceduralgenerationSpawnData: Failed to remove id: id not found");
            }
        }
    private static void MoveTailToAndCut(ref DynamicBuffer <BufferHashSetElementData> hashMapBuffer, int hashMapIndex)
    {
        var lastIndex = hashMapBuffer.Length - 1;

        if (lastIndex == hashMapIndex)
        {
            hashMapBuffer.RemoveAt(lastIndex);
            return;
        }

        var lastItem = hashMapBuffer[lastIndex];

        var prevItem = hashMapBuffer[lastItem.PrevItem];

        prevItem.NextItem = hashMapIndex;
        hashMapBuffer[lastItem.PrevItem] = prevItem;

        if (lastItem.NextItem >= 0)
        {
            var nextItem = hashMapBuffer[lastItem.NextItem];
            nextItem.PrevItem = hashMapIndex;
            hashMapBuffer[lastItem.NextItem] = nextItem;
        }

        hashMapBuffer[hashMapIndex] = lastItem;

        hashMapBuffer.RemoveAt(lastIndex);
    }
    public static void AddAmountOf(this DynamicBuffer <InventoryBufferElement> buffer, FixedString32 resourceName, float addedAmount)
    {
        var index = -1;

        for (int i = 0; i < buffer.Length; i++)
        {
            if (buffer[i].ResourceName == resourceName)
            {
                index = i;
                break;
            }
        }
        float currentAmount;

        if (index != -1)
        {
            currentAmount = buffer[index].ResourceAmount;
            buffer.RemoveAt(index);
        }
        else
        {
            currentAmount = 0f;
        }

        if (currentAmount + addedAmount != 0f)
        {
            buffer.Add(new InventoryBufferElement {
                ResourceName = resourceName, ResourceAmount = currentAmount + addedAmount
            });
        }
    }
Пример #4
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            BufferAccessor <TriggerEventBufferElement> triggerEventsBufferAccessor = chunk.GetBufferAccessor(TriggerEventBufferType);

            for (int i = 0; i < chunk.Count; i++)
            {
                DynamicBuffer <TriggerEventBufferElement> triggerEventsBuffer = triggerEventsBufferAccessor[i];

                for (int j = triggerEventsBuffer.Length - 1; j >= 0; j--)
                {
                    TriggerEventBufferElement triggerEvent = triggerEventsBuffer[j];

                    if (triggerEvent._isStale)
                    {
                        if (triggerEvent.State == PhysicsEventState.Exit)
                        {
                            triggerEventsBuffer.RemoveAt(j);
                        }
                        else
                        {
                            triggerEvent.State     = PhysicsEventState.Exit;
                            triggerEventsBuffer[j] = triggerEvent;
                        }
                    }
                }
            }
        }
Пример #5
0
    // Start is called before the first frame update
    void Start()
    {
        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        //²éѯ
        EntityQuery          entityQuery = entityManager.CreateEntityQuery(typeof(BufferComponent8));
        NativeArray <Entity> entities    = entityQuery.ToEntityArray(Allocator.TempJob);


        foreach (var entity in entities)
        {
            DynamicBuffer <BufferComponent8> dynamicbuffer = entityManager.GetBuffer <BufferComponent8>(entity);

            //ɾ³ý
            dynamicbuffer.RemoveAt(0);

            //²åÈë
            dynamicbuffer.Insert(0, new BufferComponent8()
            {
                data = 5, data2 = 6
            });

            var i = 0;
            foreach (var buffer in dynamicbuffer)
            {
                Debug.Log("EntityIndex: " + entity.Index + ", BufferIndex: " + i + ", data = " + buffer.data + ", data2 = " + buffer.data2);
                ++i;
            }
        }



        entities.Dispose();
    }
            public void Execute(ArchetypeChunk chunk,
                                int chunkIndex,
                                int firstEntityIndex)
            {
                if (chunk.Has(collisionEventBufferType))
                {
                    BufferAccessor <StatefulCollisionEvent> collisionEventsBufferAccessor =
                        chunk.GetBufferAccessor(collisionEventBufferType);

                    for (var i = 0; i < chunk.Count; i++)
                    {
                        DynamicBuffer <StatefulCollisionEvent> collisionEventsBuffer =
                            collisionEventsBufferAccessor[i];

                        for (var j = collisionEventsBuffer.Length - 1; j >= 0; j--)
                        {
                            StatefulCollisionEvent collisionEvent = collisionEventsBuffer[j];

                            if (collisionEvent._isStale)
                            {
                                if (collisionEvent.State == PhysicsEventState.Exit)
                                {
                                    collisionEventsBuffer.RemoveAt(j);
                                }
                                else
                                {
                                    collisionEvent.State     = PhysicsEventState.Exit;
                                    collisionEventsBuffer[j] = collisionEvent;
                                }
                            }
                        }
                    }
                }
            }
Пример #7
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <PlayerStatComponent>  stats        = chunk.GetNativeArray <PlayerStatComponent>(StatsChunk);
            BufferAccessor <ChangeVitalBuffer> VitalChanges = chunk.GetBufferAccessor <ChangeVitalBuffer>(IncreaseChunk);

            for (int i = 0; i < chunk.Count; i++)
            {
                PlayerStatComponent stat = stats[i];
                DynamicBuffer <ChangeVitalBuffer> buffer = VitalChanges[i];
                for (int j = 0; j < buffer.Length; j++)
                {
                    VitalChange change = buffer[j];
                    if (change.Iterations > 0)
                    {
                        if (change.Timer > 0.0f)
                        {
                            change.Timer -= DeltaTime;
                            buffer[j]     = change;
                        }
                        else
                        {
                            switch (change.type)
                            {
                            case VitalType.Health:
                                if (change.Increase)
                                {
                                    stat.CurHealth += change.value;
                                }
                                else
                                {
                                    stat.CurHealth -= change.value;
                                }
                                break;

                            case VitalType.Mana:
                                if (change.Increase)
                                {
                                    stat.CurMana += change.value;
                                }
                                else
                                {
                                    stat.CurMana -= change.value;
                                }
                                break;
                            }

                            change.Timer = change.Frequency;
                            change.Iterations--;

                            stats[i]  = stat;
                            buffer[j] = change;
                        }
                    }
                    else
                    {
                        buffer.RemoveAt(j);
                    }
                }
            }
        }
Пример #8
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                NativeArray <Entity>     entities = chunk.GetNativeArray(EntityType);
                NativeArray <TTweenInfo> infos    = chunk.GetNativeArray(InfoType);

                for (int i = 0; i < entities.Length; i++)
                {
                    Entity entity = entities[i];

                    DynamicBuffer <TweenState> tweenBuffer = TweenBufferFromEntity[entity];
                    for (int j = 0; j < tweenBuffer.Length; j++)
                    {
                        TweenState tween = tweenBuffer[j];
                        if (infos[i].GetTweenId() == tween.Id && tween.IsPendingDestroy())
                        {
                            tweenBuffer.RemoveAt(j);
                            ParallelWriter.RemoveComponent <TTweenInfo>(chunkIndex, entity);
                            break;
                        }
                    }

                    if (tweenBuffer.IsEmpty)
                    {
                        ParallelWriter.RemoveComponent <TweenState>(chunkIndex, entity);
                    }
                }
            }
Пример #9
0
        public static bool InvokeDeserialize <T>(BufferFromEntity <T> snapshotFromEntity,
                                                 Entity entity, uint snapshot, uint baseline, uint baseline2, uint baseline3,
                                                 DataStreamReader reader, ref DataStreamReader.Context ctx, NetworkCompressionModel compressionModel)
            where T : struct, ISnapshotData <T>
        {
            DynamicBuffer <T> snapshotArray = snapshotFromEntity[entity];
            var baselineData = default(T);

            if (baseline != snapshot)
            {
                for (int i = 0; i < snapshotArray.Length; ++i)
                {
                    if (snapshotArray[i].Tick == baseline)
                    {
                        baselineData = snapshotArray[i];
                        break;
                    }
                }

                if (baselineData.Tick == 0)
                {
                    return(false); // Ack desync detected
                }
            }

            if (baseline3 != snapshot)
            {
                var baselineData2 = default(T);
                var baselineData3 = default(T);
                for (int i = 0; i < snapshotArray.Length; ++i)
                {
                    if (snapshotArray[i].Tick == baseline2)
                    {
                        baselineData2 = snapshotArray[i];
                    }

                    if (snapshotArray[i].Tick == baseline3)
                    {
                        baselineData3 = snapshotArray[i];
                    }
                }

                if (baselineData2.Tick == 0 || baselineData3.Tick == 0)
                {
                    return(false); // Ack desync detected
                }
                baselineData.PredictDelta(snapshot, ref baselineData2, ref baselineData3);
            }

            var data = default(T);

            data.Deserialize(snapshot, ref baselineData, reader, ref ctx, compressionModel);
            // Replace the oldest snapshot and add a new one
            if (snapshotArray.Length == GhostSystemConstants.SnapshotHistorySize)
            {
                snapshotArray.RemoveAt(0);
            }
            snapshotArray.Add(data);
            return(true);
        }
        public static void FindAndRemove <T>(this DynamicBuffer <T> buffer, T value) where T : struct, IBufferElementData, IEquatable <T>
        {
            int idx = buffer.Find(value);

            if (idx != -1)
            {
                buffer.RemoveAt(idx);
            }
        }
        public static T Pop <T>(this DynamicBuffer <T> buffer) where T : struct, IBufferElementData
        {
            Assert.IsTrue(buffer.Length > 0, "Tried to Pop() from an empty buffer");
            var last   = buffer.Length - 1;
            var result = buffer[last];

            buffer.RemoveAt(last);
            return(result);
        }
Пример #12
0
 public static void RemoveAll <T>(this DynamicBuffer <T> buffer, T element) where T : struct, IEquatable <T>
 {
     for (int i = buffer.Length - 1; i >= 0; i--)
     {
         if (buffer[i].Equals(element))
         {
             buffer.RemoveAt(i);
         }
     }
 }
Пример #13
0
            public void Execute()
            {
                while (Interpolator.CurrentTime > PrevNextArray[1].Timestamp && Buffer.Length > 0)
                {
                    if (Buffer.Length == 1)
                    {
                        PrevNextArray[1] = Buffer[0];
                        Buffer.RemoveAt(0); // FIFO
                        PrevNextArray[0] = PrevNextArray[1];
                    }
                    else
                    {
                        PrevNextArray[0] = Buffer[0];
                        PrevNextArray[1] = Buffer[1];

                        Buffer.RemoveAt(0); // FIFO
                    }
                }
            }
        public void Execute(Entity entity, int index, DynamicBuffer <TrailBufferElement> buffer, ref Translation _Translation, ref TrailComponent _TrailComponent)
        {
            if (buffer.Length > _TrailComponent.MeshCount)
            {
                buffer.RemoveAt(0);
            }
            DynamicBuffer <float3> rbuffer = buffer.Reinterpret <float3>();

            rbuffer.Add(_Translation.Value);
        }
 void RemoveChildrenFromParent(Entity parent, DynamicBuffer <Child> children)
 {
     if (ParentChildrenToRemove.TryGetFirstValue(parent, out var child, out var it))
     {
         do
         {
             var childIndex = FindChildIndex(children, child);
             children.RemoveAt(childIndex);
         }while (ParentChildrenToRemove.TryGetNextValue(out child, ref it));
     }
 }
Пример #16
0
        public static bool RemoveFirst <T>(this DynamicBuffer <T> buffer, Predicate <T> predicate) where T : struct, IBufferElementData
        {
            var indexOfExistingElement = buffer.IndexOf(predicate);

            if (indexOfExistingElement >= 0)
            {
                buffer.RemoveAt(indexOfExistingElement);
            }

            return(indexOfExistingElement >= 0);
        }
 public static void Remove <T>(this DynamicBuffer <T> buffer, T item) where T : struct
 {
     for (var i = 0; i < buffer.Length; ++i)
     {
         if (buffer[i].Equals(item))
         {
             buffer.RemoveAt(i);
             return;
         }
     }
 }
Пример #18
0
 public static bool RemoveFirst <T>(this DynamicBuffer <T> buffer, T element) where T : struct, IEquatable <T>
 {
     for (int i = 0; i < buffer.Length; i++)
     {
         if (buffer[i].Equals(element))
         {
             buffer.RemoveAt(i);
             return(true);
         }
     }
     return(false);
 }
Пример #19
0
 public static bool Remove <TElement>(this DynamicBuffer <TElement> buffer, TElement value) where TElement : struct, IEquatable <TElement>
 {
     for (int i = 0; i < buffer.Length; i++)
     {
         if (buffer[i].Equals(value))
         {
             buffer.RemoveAt(i);
             return(true);
         }
     }
     return(false);
 }
Пример #20
0
 public void Execute(DynamicBuffer <FailedPlanLog> buffer)
 {
     for (var i = buffer.Length - 1; i >= 0; i--)
     {
         var log = buffer[i];
         if (!(CurrentTime - log.Time >= CoolDownTime))
         {
             continue;
         }
         buffer.RemoveAt(i);
     }
 }
Пример #21
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                NativeArray <Entity>                 entities       = chunk.GetNativeArray(EntityType);
                NativeArray <TTweenInfo>             infos          = chunk.GetNativeArray(InfoType);
                BufferAccessor <TweenState>          tweenBuffers   = chunk.GetBufferAccessor(TweenBufferType);
                BufferAccessor <TweenDestroyCommand> destroyBuffers = chunk.GetBufferAccessor(DestroyCommandType);

                for (int i = 0; i < entities.Length; i++)
                {
                    Entity entity = entities[i];

                    bool shouldDestroy = false;
                    DynamicBuffer <TweenDestroyCommand> destroyBuffer = destroyBuffers[i];
                    for (int j = destroyBuffer.Length - 1; j >= 0; j--)
                    {
                        TweenDestroyCommand command = destroyBuffer[j];
                        if (infos[i].GetTweenId() == command.Id)
                        {
                            shouldDestroy = true;
                            destroyBuffer.RemoveAt(j);
                        }
                    }

                    if (!shouldDestroy)
                    {
                        // Shouldn't go here
                        continue;
                    }

                    DynamicBuffer <TweenState> tweenBuffer = tweenBuffers[i];
                    for (int j = tweenBuffer.Length - 1; j >= 0; j--)
                    {
                        TweenState tween = tweenBuffer[j];
                        if (infos[i].GetTweenId() == tween.Id)
                        {
                            tweenBuffer.RemoveAt(j);
                            ParallelWriter.RemoveComponent <TTweenInfo>(chunkIndex, entity);
                            break;
                        }
                    }

                    if (tweenBuffer.IsEmpty)
                    {
                        ParallelWriter.RemoveComponent <TweenState>(chunkIndex, entity);
                    }

                    if (destroyBuffer.IsEmpty)
                    {
                        ParallelWriter.RemoveComponent <TweenDestroyCommand>(chunkIndex, entity);
                    }
                }
            }
    protected override void OnUpdate()
    {
        DynamicBuffer <EffectGroupBufferSingleton> effectGroupBufferSingleton = GetSingletonBuffer <EffectGroupBufferSingleton>();

        for (int i = effectGroupBufferSingleton.Length - 1; i >= 0; i--)
        {
            EffectGroupBufferSingleton effectGroupBuffer = effectGroupBufferSingleton[i];
            if (Time.ElapsedTime >= effectGroupBuffer.TimeStamp + effectGroupBuffer.Delay)
            {
                effectGroupBufferSingleton.RemoveAt(i);
            }
        }
    }
Пример #23
0
            private InputFieldCaretState ProcessInput(Entity inputFieldEntity, DynamicBuffer <KeyboardInputBuffer> inputBuffer,
                                                      DynamicBuffer <TextData> textData, InputFieldCaretState caretState, int chunkIndex)
            {
                for (int i = 0; i < inputBuffer.Length; i++)
                {
                    var key = inputBuffer[i];
                    if (key.EventType == KeyboardEventType.Key)
                    {
                        switch ((KeyCode)key.KeyCode)
                        {
                        case KeyCode.Backspace:
                            if (caretState.CaretPosition > 0)
                            {
                                textData.RemoveAt(caretState.CaretPosition - 1);
                                caretState.CaretPosition--;
                            }
                            break;

                        case KeyCode.LeftArrow:
                            caretState.CaretPosition = math.max(0, caretState.CaretPosition - 1);
                            break;

                        case KeyCode.RightArrow:
                            caretState.CaretPosition = math.min(textData.Length, caretState.CaretPosition + 1);
                            break;

                        case KeyCode.Home:
                            caretState.CaretPosition = 0;
                            break;

                        case KeyCode.End:
                            caretState.CaretPosition = textData.Length;
                            break;

                        case KeyCode.Return:
                        case KeyCode.KeypadEnter:
                            CommandBuff.AddComponent(chunkIndex, inputFieldEntity, new InputFieldReturnEvent());
                            return(caretState);
                        }
                    }
                    else
                    {
                        textData.Insert(caretState.CaretPosition, new TextData()
                        {
                            Value = key.Character
                        });
                        caretState.CaretPosition++;
                    }
                }
                return(caretState);
            }
Пример #24
0
        /// <summary>
        /// Remove an element from a <see cref="DynamicBuffer{T}"/>.
        /// </summary>
        /// <typeparam name="T">The type of NativeList</typeparam>
        /// <typeparam name="TI">The type of element.</typeparam>
        /// <param name="buffer">The DynamicBuffer.</param>
        /// <param name="element">The element.</param>
        /// <returns>True if removed, else false.</returns>
        public static bool Remove <T, TI>(this DynamicBuffer <T> buffer, TI element)
            where T : struct, IEquatable <TI>
            where TI : struct
        {
            var index = buffer.IndexOf(element);

            if (index < 0)
            {
                return(false);
            }

            buffer.RemoveAt(index);
            return(true);
        }
Пример #25
0
        protected override void OnUpdate()
        {
            GameDataComponent gameDataComponent = GetSingleton <GameDataComponent>();

            Entity wagonEntity = GetSingletonEntity <WagonTagComponent>();

            if (!EntityManager.HasComponent <Child>(wagonEntity))
            {
                EntityManager.AddBuffer <Child>(wagonEntity);
            }

            DynamicBuffer <Child> bufferChildren = EntityManager.GetBuffer <Child>(wagonEntity);

            Entities
            .WithAll <DispatchEventBoxComponent>()
            .WithStructuralChanges()
            .ForEach((Entity entity, ref Translation position, ref Parent parent, ref PreviousParent previousParent, in ColorBoxComponent colorBoxComponent) =>
            {
                EntityManager.RemoveComponent <DispatchEventBoxComponent>(entity);

                if (gameDataComponent.Color == colorBoxComponent.ColorsType)
                {
                    EntityManager.AddComponent <ToWagonTagComponent>(parent.Value);
                    return;
                }

                if (bufferChildren.Length == 0)
                {
                    Entity playerEntity = GetSingletonEntity <PlayerTagComponent>();
                    EntityManager.AddComponent <GameOverComponent>(playerEntity);
                    EntityManager.AddComponent <RemoveInStartLevelComponent>(playerEntity);
                    return;
                }
                ;
                var last = bufferChildren[bufferChildren.Length - 1];
                bufferChildren.RemoveAt(bufferChildren.Length - 1);
                EntityManager.AddComponent <RemoveFromWagonTagComponent>(last.Value);
            }).Run();


            SetToWagon(bufferChildren);
            RemoveFromWagon(bufferChildren);
        }
    private static void RemoveItemAt <T>(int index, DynamicBuffer <T> buffer, DynamicBuffer <BufferHashSetElementData> hashMapBuffer)
        where T : struct, IBufferElementData, IEqualityComparer <T>
    {
        int lastItemIndex = buffer.Length - 1;

        buffer[index] = buffer[lastItemIndex];
        buffer.RemoveAt(lastItemIndex);

        if (lastItemIndex != index)
        {
            SetHashItemIndex(ref hashMapBuffer, index, lastItemIndex);
            RemoveHashItem(ref hashMapBuffer, hashMapBuffer[index].HashMapIndex, index, buffer.Capacity);
            SetHashItemHashIndex(ref hashMapBuffer, hashMapBuffer[lastItemIndex].HashMapIndex, index);
            SetHashItemHashIndex(ref hashMapBuffer, -1, lastItemIndex);
        }
        else
        {
            RemoveHashItem(ref hashMapBuffer, hashMapBuffer[lastItemIndex].HashMapIndex, lastItemIndex, buffer.Capacity);
            SetHashItemHashIndex(ref hashMapBuffer, -1, lastItemIndex);
        }
    }
Пример #27
0
        /// <summary>
        /// Applies percent modifiers on a stat.
        /// </summary>
        protected static void ApplyModifiers <T>(ref float stat, DynamicBuffer <T> modifierBuffer)
            where T : struct, IBufferElementData
        {
            DynamicBuffer <float> modifiers = modifierBuffer.Reinterpret <float>();

            for (int i = modifiers.Length - 1; i >= 0; i--)
            {
                float modifier = modifiers[i];
                modifiers.RemoveAt(i);

                if (stat <= 0)
                {
                    continue;         // Don't multiply negative values
                }
                stat *= 1 + modifier; // Multiply stat
                if (stat < 0)
                {
                    stat = 0;           // Don't reduce stat below 0
                }
            }
        }
Пример #28
0
            private int2 RemoveFirst(ref DynamicBuffer <SearchNode> searchNodeBuffer, out int2 prevCoord, out int prevDistanceFromStart)
            {
                int2 firstItem = searchNodeBuffer[0].Coord;

                prevCoord = searchNodeBuffer[0].PrevNode;

                prevDistanceFromStart = searchNodeBuffer[0].DistanceFromStart;

                CloseSet.TryAdd(firstItem.GetHashCode(), searchNodeBuffer[0].PrevNode);

                int lastIndex = searchNodeBuffer.Length - 1;

                var lastNode = searchNodeBuffer[lastIndex];

                lastNode.HeapIndex = 0;

                searchNodeBuffer[0] = lastNode;

                searchNodeBuffer.RemoveAt(lastIndex);

                SortDown(ref searchNodeBuffer);

                return(firstItem);
            }
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity>       entityArray       = chunk.GetNativeArray(entityType);
            NativeArray <RemoveAction> removeActionArray = chunk.GetNativeArray(removeActionType);
            BufferAccessor <Action>    buffers           = chunk.GetBufferAccessor <Action>(actionBufferType);

            for (int i = 0; i < chunk.Count; i++)
            {
                Entity entity = entityArray[i];
                DynamicBuffer <Action> actions = buffers[i];
                RemoveAction           removal = removeActionArray[i];

                if (actions.Length > 0) //if there are actions
                {
                    int j = 0;
                    while (j < actions.Length && actions[j].id != removal.id) // find the index of the action
                    {
                        j++;
                    }
                    if (j < actions.Length) // if the action was found before the end of the buffer
                    {
                        Debug.Log("Removing Action " + "!");
                        ActionType aType = actions[j].type;                                   // get the type of the action that was removed
                        entityCommandBuffer.DestroyEntity(chunkIndex, actions[j].dataHolder); // delete the data holder for the action
                        actions.RemoveAt(j);                                                  //remove the action
                        entityCommandBuffer.AddComponent <ChangeAction>(chunkIndex, entity, new ChangeAction {
                        });                                                                   // tell the system that the current action should be changed
                    }
                    else
                    {
                        Debug.Log("Failed to remove " + "!");
                    }
                }
                entityCommandBuffer.RemoveComponent <RemoveAction>(chunkIndex, entity); // remove this component
            }
        }
    public static void SetAmountOf(this DynamicBuffer <InventoryBufferElement> buffer, FixedString32 resourceName, float newAmount)
    {
        var index = -1;

        for (int i = 0; i < buffer.Length; i++)
        {
            if (buffer[i].ResourceName == resourceName)
            {
                index = i;
                break;
            }
        }
        if (index != -1)
        {
            buffer.RemoveAt(index);
        }

        if (newAmount != 0f)
        {
            buffer.Add(new InventoryBufferElement {
                ResourceName = resourceName, ResourceAmount = newAmount
            });
        }
    }