Second commit
This commit is contained in:
commit
36840f3ad4
999 files changed
+61364
No files matched your search
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using R3;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.D.Cleaning
|
||||
{
|
||||
public interface ICleaningService
|
||||
{
|
||||
}
|
||||
|
||||
public class CleaningService : IDisposable, ICleaningService
|
||||
{
|
||||
private List<Cleanable> _cleanableSurfaces = new();
|
||||
|
||||
private IDisposable _surfaces;
|
||||
|
||||
public ReactiveProperty<bool> LevelCleaned { get; } = new();
|
||||
|
||||
public CleaningService(Cleanable[] cleanableSurfaces)
|
||||
{
|
||||
DisposableBuilder builder = new DisposableBuilder();
|
||||
|
||||
foreach (var cleanable in cleanableSurfaces)
|
||||
{
|
||||
_cleanableSurfaces.Add(cleanable);
|
||||
builder.Add(cleanable.Cleaned
|
||||
.Subscribe(x => CheckProgress(cleanable)));
|
||||
}
|
||||
|
||||
_surfaces = builder.Build();
|
||||
}
|
||||
|
||||
private void CheckProgress(Cleanable cleanable)
|
||||
{
|
||||
if(cleanable.Cleaned.CurrentValue) Debug.Log($"{cleanable.name} cleaned");
|
||||
|
||||
CheckOverallProgress();
|
||||
}
|
||||
|
||||
private void CheckOverallProgress()
|
||||
{
|
||||
if (LevelCleaned.CurrentValue)
|
||||
return;
|
||||
|
||||
foreach (var t in _cleanableSurfaces)
|
||||
if (!t.Cleaned.CurrentValue) return;
|
||||
|
||||
Debug.Log($"VICTORY!!!");
|
||||
LevelCleaned.Value = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_surfaces?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user