Added Null Checked IToggleState Extension and Added Some Documentation
This commit is contained in:
parent
7574769637
commit
636056b82e
|
@ -4,7 +4,12 @@ namespace Syntriax.Modules.ToggleState
|
|||
{
|
||||
public interface IToggleState
|
||||
{
|
||||
bool Toggled { get; set; }
|
||||
bool IsToggled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called everytime the IsToggled field is changed
|
||||
/// </summary>
|
||||
/// <value>The new value of IsToggled</value>
|
||||
Action<bool> OnToggleStateChanged { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
namespace Syntriax.Modules.ToggleState
|
||||
{
|
||||
public static class IToggleStateExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if the provided parameter IToggleState is toggled, if the parameter is null returns the nullValue parameter
|
||||
/// </summary>
|
||||
/// <param name="toggleState">IToggleState to be checked if toggled or not</param>
|
||||
/// <param name="nullValue">The value that will be returned if toggleState is null. Default value: true</param>
|
||||
/// <returns>IToggleState's toggle value, or if null return nullValue parameter</returns>
|
||||
public static bool IsToggledNullChecked(this IToggleState toggleState, bool nullValue = true)
|
||||
=> toggleState == null ? nullValue : toggleState.IsToggled;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d321123fb56053e49b20da45bfda3a65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue