Files
MonoGame.Extended/Source/Demos/Sandbox/Systems/ExpirySystem.cs
T

38 lines
1.0 KiB
C#

using Microsoft.Xna.Framework;
using MonoGame.Extended;
using MonoGame.Extended.Entities;
using MonoGame.Extended.Entities.Systems;
using Sandbox.Components;
namespace Sandbox.Systems
{
public class ExpirySystem : EntityProcessingSystem
{
private ComponentMapper<Expiry> _expiryMapper;
public ExpirySystem()
: base(Aspect.All(typeof(Expiry)))
{
}
public override void Initialize(IComponentMapperService mapperService)
{
_expiryMapper = mapperService.GetMapper<Expiry>();
}
public override void Process(GameTime gameTime, int entityId)
{
var expiry = _expiryMapper.Get(entityId);
expiry.TimeRemaining -= gameTime.GetElapsedSeconds();
if (expiry.TimeRemaining <= 0)
{
// TODO: We shouldn't need to delete the components ourselves!
_expiryMapper.Delete(entityId);
DestroyEntity(entityId);
}
}
}
}