44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using System;
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
public class TentRemovalSystem : GameSystem, IInitializable, IDisposable
|
|
{
|
|
[InjectService]
|
|
private ISignalBus _signalBus;
|
|
|
|
[InjectService]
|
|
private IDeleteBuildingService _deleteBuildingService;
|
|
|
|
[InjectService]
|
|
private IEntityCache _entityCache;
|
|
|
|
public TentRemovalSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
public UniTask InitializeAsync()
|
|
{
|
|
_signalBus.Subscribe<DayStartedSignal>(OnDayStarted);
|
|
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_signalBus.Unsubscribe<DayStartedSignal>(OnDayStarted);
|
|
}
|
|
|
|
private void OnDayStarted(DayStartedSignal signal)
|
|
{
|
|
var tents = _entityCache.GetTentBuildings();
|
|
|
|
for (var i = tents.Count - 1; i >= 0; i--)
|
|
{
|
|
var tent = tents[i];
|
|
_deleteBuildingService.Delete(tent, DeleteBuildingOptions.Silent);
|
|
}
|
|
}
|
|
}
|
|
} |