Files
RebootKit/Runtime/Engine/Code/Services/Simulation/Interactors/IInteractor.cs
2025-03-14 19:53:29 +01:00

30 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
namespace RebootKit.Engine.Services.Simulation.Interactors {
public interface IInteractorAsync<in TInteractable> {
UniTask Interact(TInteractable target, CancellationToken cancellationToken);
}
public interface IInteractor<in TInteractable> {
public static Type InteractableType() => typeof(TInteractable);
void Interact(TInteractable target);
}
public class GroupInteractor<TInteractable> : IInteractor<TInteractable> {
private readonly List<IInteractor<TInteractable>> _interactors = new();
public void Add(IInteractor<TInteractable> interactor) => _interactors.Add(interactor);
public void Remove(IInteractor<TInteractable> interactor) => _interactors.Remove(interactor);
public void RemoveAll() => _interactors.Clear();
public void Interact(TInteractable target) {
foreach (IInteractor<TInteractable> interactor in _interactors) {
interactor.Interact(target);
}
}
}
}