예제 #1
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                BufferAccessor <AbilityBuffer> abilityBufffers   = chunk.GetBufferAccessor(AbilityBufferChunk);
                BufferAccessor <COST_BUFFER>   costBuffers       = chunk.GetBufferAccessor(CostBufferChunk);
                NativeArray <RESOURCE>         resourceComponent = chunk.GetNativeArray(ResourceComponent);

                for (int entityIndex = 0; entityIndex < chunk.Count; ++entityIndex)
                {
                    NativeArray <AbilityBuffer> AbilityBufferArray = abilityBufffers[entityIndex].AsNativeArray();
                    NativeArray <COST_BUFFER>   costBufferArray    = costBuffers[entityIndex].AsNativeArray();
                    for (int abilityIndex = 0; abilityIndex < AbilityBufferArray.Length; ++abilityIndex)
                    {
                        Ability Ability = AbilityBufferArray[abilityIndex];


                        if (Ability.State != AbilityState.Active)
                        {
                            continue;
                        }
                        for (int costIndex = 0; costIndex < costBufferArray.Length; costIndex++)
                        {
                            COST_BUFFER costBuffer = costBufferArray[costIndex];
                            if (costBuffer.AbilityIndex != abilityIndex)
                            {
                                continue;
                            }
                            RESOURCE resource = resourceComponent[entityIndex];
                            CostConsumer.ConsumeCost(costBuffer.Cost, ref resource);
                            resourceComponent[entityIndex] = resource;
                        }
                    }
                }
            }
예제 #2
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                BufferAccessor <AbilityBuffer> abilityBufffers = chunk.GetBufferAccessor(AbilityBufferChunk);
                BufferAccessor <COST_BUFFER>   costBuffers     = chunk.GetBufferAccessor(CostBufferChunk);
                NativeArray <RESOURCE>         resources       = chunk.GetNativeArray(ResourceChunk);

                for (int entityIndex = 0; entityIndex < chunk.Count; ++entityIndex)
                {
                    NativeArray <AbilityBuffer> AbilityBufferArray = abilityBufffers[entityIndex].AsNativeArray();
                    NativeArray <COST_BUFFER>   costBufferArray    = costBuffers[entityIndex].AsNativeArray();
                    RESOURCE resource = resources[entityIndex];
                    for (int abilityIndex = 0; abilityIndex < AbilityBufferArray.Length; ++abilityIndex)
                    {
                        Ability Ability = AbilityBufferArray[abilityIndex];
                        bool    temp    = true;
                        for (int costIndex = 0; costIndex < costBufferArray.Length; ++costIndex)
                        {
                            COST_BUFFER CostBuffer = costBufferArray[costIndex];
                            if (CostBuffer.AbilityIndex != abilityIndex)
                            {
                                continue;
                            }
                            temp &= CostChecker.HasEnougthResourceLeft(CostBuffer.Cost, in resource);
                        }
                        Ability.HasEnougthRessource     &= temp;
                        AbilityBufferArray[abilityIndex] = Ability;
                    }
                }
            }