Initial Commit

This commit is contained in:
Simeon Radivoev 2022-02-12 12:53:50 +02:00
commit ee5c2f922d
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
2255 changed files with 547750 additions and 0 deletions

View file

@ -0,0 +1,33 @@
using Events;
using Unity.Entities;
using UnityEngine;
namespace DefaultNamespace
{
[UpdateInGroup(typeof(PresentationSystemGroup)), UpdateAfter(typeof(ItemPickupSystem)), UpdateBefore(typeof(InventoryPickupSystem))]
public class AmmoPickupSystem : AdvancedComponentSystem
{
protected override void OnSystemUpdate()
{
Entities.WithAll<Transform>()
.ForEach(
(Entity entity, AmmoDropComponent ammo, ref ItemPickupEventData pickup, ref ItemContainerAmountData amount) =>
{
if (EntityManager.TryGetComponentData<ActorWeaponReferenceData>(pickup.PlayerEntity, out var weaponReference) &&
EntityManager.TryGetSharedComponentData<ActorWeaponPropertiesData>(pickup.PlayerEntity, out var weapon))
{
var weaponEntity = weaponReference.Weapon;
var weaponData = EntityManager.GetComponentData<WeaponData>(weaponEntity);
var transform = EntityManager.GetComponentObject<Transform>(entity);
if (weaponData.Ammo < weapon.Weapon.Data.AmmoCapacity)
{
weaponData.Ammo = Mathf.Min(weaponData.Ammo + amount.Amount, weapon.Weapon.Data.AmmoCapacity);
EntityManager.SetComponentData(weaponEntity, weaponData);
PostUpdateActions.Enqueue(() => Object.Destroy(transform.gameObject));
}
}
});
}
}
}