Exemple #1
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);
                    }
                }
            }
        }
      public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
      {
          selfEntityRef = entity;
          var data = new PlayerStatComponent()
          {
              MaxHealth = MaxHealth, MaxMana = MaxMana, CurHealth = CurHealth, CurMana = CurMana
          };

          dstManager.AddComponentData(entity, data);
          dstManager.AddComponent <Unity.Transforms.CopyTransformFromGameObject>(entity);
          dstManager.AddBuffer <ChangeVitalBuffer>(entity);
          StatusBuffers = dstManager.AddBuffer <EffectStatusBuffer>(entity);
          StatUpdate();
      }