2022-11-14 12:55:53 +03:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-11-14 13:01:16 +03:00
|
|
|
namespace Syntriax.Modules.ToggleState
|
2022-11-14 12:55:53 +03:00
|
|
|
{
|
2022-11-16 20:20:35 +03:00
|
|
|
public class ToggleStateMonoBehaviour : MonoBehaviour, IToggleState
|
2022-11-14 12:55:53 +03:00
|
|
|
{
|
2022-11-14 13:58:44 +03:00
|
|
|
private bool _isToggled = true;
|
|
|
|
public bool IsToggled
|
2022-11-14 12:55:53 +03:00
|
|
|
{
|
2022-11-14 13:58:44 +03:00
|
|
|
get => _isToggled;
|
2022-11-14 12:55:53 +03:00
|
|
|
set
|
|
|
|
{
|
2022-12-02 00:09:21 +03:00
|
|
|
if (value == _isToggled)
|
|
|
|
return;
|
2022-11-14 12:55:53 +03:00
|
|
|
|
2022-11-14 13:58:44 +03:00
|
|
|
_isToggled = value;
|
2022-12-02 00:09:21 +03:00
|
|
|
OnToggleStateChanged?.Invoke(value);
|
2022-11-14 12:55:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action<bool> OnToggleStateChanged { get; set; } = null;
|
2023-01-24 21:44:29 +03:00
|
|
|
|
|
|
|
protected void Awake()
|
|
|
|
=> OnToggleStateChanged += (state) => enabled = state;
|
|
|
|
|
|
|
|
protected void OnEnable() => IsToggled = true;
|
|
|
|
protected void OnDisable() => IsToggled = false;
|
2022-11-14 12:55:53 +03:00
|
|
|
}
|
|
|
|
}
|