State/ToggleStateMonobehaviour.cs

26 lines
576 B
C#

using System;
using UnityEngine;
namespace Syntriax.Modules.ToggleState
{
public class ToggleStateMonobehaviour : MonoBehaviour, IToggleState
{
private bool _isToggled = true;
public bool IsToggled
{
get => _isToggled;
set
{
bool oldValue = _isToggled;
_isToggled = value;
if (oldValue = !value)
OnToggleStateChanged?.Invoke(value);
}
}
public Action<bool> OnToggleStateChanged { get; set; } = null;
}
}