diff --git a/IToggleState.cs b/IToggleState.cs index e5dc145..3034a69 100644 --- a/IToggleState.cs +++ b/IToggleState.cs @@ -4,7 +4,12 @@ namespace Syntriax.Modules.ToggleState { public interface IToggleState { - bool Toggled { get; set; } + bool IsToggled { get; set; } + + /// + /// Called everytime the IsToggled field is changed + /// + /// The new value of IsToggled Action OnToggleStateChanged { get; set; } } } diff --git a/IToggleStateExtensions.cs b/IToggleStateExtensions.cs new file mode 100644 index 0000000..9d68fdb --- /dev/null +++ b/IToggleStateExtensions.cs @@ -0,0 +1,14 @@ +namespace Syntriax.Modules.ToggleState +{ + public static class IToggleStateExtensions + { + /// + /// Checks if the provided parameter IToggleState is toggled, if the parameter is null returns the nullValue parameter + /// + /// IToggleState to be checked if toggled or not + /// The value that will be returned if toggleState is null. Default value: true + /// IToggleState's toggle value, or if null return nullValue parameter + public static bool IsToggledNullChecked(this IToggleState toggleState, bool nullValue = true) + => toggleState == null ? nullValue : toggleState.IsToggled; + } +} diff --git a/IToggleStateExtensions.cs.meta b/IToggleStateExtensions.cs.meta new file mode 100644 index 0000000..7bec1ab --- /dev/null +++ b/IToggleStateExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d321123fb56053e49b20da45bfda3a65 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ToggleStateMember.cs b/ToggleStateMember.cs index 2379245..f6f0edb 100644 --- a/ToggleStateMember.cs +++ b/ToggleStateMember.cs @@ -4,15 +4,15 @@ namespace Syntriax.Modules.ToggleState { public class ToggleStateMember : IToggleState { - private bool _toggled = true; - public bool Toggled + private bool _isToggled = true; + public bool IsToggled { - get => _toggled; + get => _isToggled; set { - bool oldValue = _toggled; + bool oldValue = _isToggled; - _toggled = value; + _isToggled = value; if (oldValue = !value) OnToggleStateChanged?.Invoke(value); diff --git a/ToggleStateMonobehaviour.cs b/ToggleStateMonobehaviour.cs index 62fa2b9..e644306 100644 --- a/ToggleStateMonobehaviour.cs +++ b/ToggleStateMonobehaviour.cs @@ -5,15 +5,15 @@ namespace Syntriax.Modules.ToggleState { public class ToggleStateMonobehaviour : MonoBehaviour, IToggleState { - private bool _toggled = true; - public bool Toggled + private bool _isToggled = true; + public bool IsToggled { - get => _toggled; + get => _isToggled; set { - bool oldValue = _toggled; + bool oldValue = _isToggled; - _toggled = value; + _isToggled = value; if (oldValue = !value) OnToggleStateChanged?.Invoke(value);