State/ToggleStateMonobehaviour.cs

26 lines
576 B
C#
Raw Normal View History

2022-11-14 12:55:53 +03:00
using System;
using UnityEngine;
namespace Syntriax.Modules.ToggleState
2022-11-14 12:55:53 +03:00
{
public class ToggleStateMonobehaviour : MonoBehaviour, IToggleState
2022-11-14 12:55:53 +03:00
{
private bool _isToggled = true;
public bool IsToggled
2022-11-14 12:55:53 +03:00
{
get => _isToggled;
2022-11-14 12:55:53 +03:00
set
{
bool oldValue = _isToggled;
2022-11-14 12:55:53 +03:00
_isToggled = value;
2022-11-14 12:55:53 +03:00
if (oldValue = !value)
OnToggleStateChanged?.Invoke(value);
}
}
public Action<bool> OnToggleStateChanged { get; set; } = null;
}
}