r2mods/ilspy_dump/ror2_csproj/ToggleAction.cs

39 lines
655 B
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using System;
public class ToggleAction : IDisposable
{
private readonly Action activationAction;
private readonly Action deactivationAction;
public bool active { get; private set; }
public ToggleAction(Action activationAction, Action deactivationAction)
{
active = false;
this.activationAction = activationAction;
this.deactivationAction = deactivationAction;
}
public void SetActive(bool newActive)
{
if (active != newActive)
{
active = newActive;
if (active)
{
activationAction?.Invoke();
}
else
{
deactivationAction?.Invoke();
}
}
}
public void Dispose()
{
SetActive(newActive: false);
}
}