BREAKING CHANGES: Repo Overhaul

- Renamed the repo to use State rather than ToggleState
- IToggleState renamed to IStateEnable
This commit is contained in:
2023-03-20 22:15:21 +03:00
parent af1e30058b
commit f7f4dcf08c
18 changed files with 107 additions and 99 deletions

View File

@@ -0,0 +1,15 @@
using System;
namespace Syntriax.Modules.State
{
public interface IStateEnable
{
/// <summary>
/// Called everytime the <see cref="IsEnabled"/>> field is changed
/// </summary>
/// <value>The new value of <see cref="IsEnabled"/>></value>
Action<bool> OnEnabledChanged { get; set; }
bool IsEnabled { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9017443f63486e0438e09eeb335eb8bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
namespace Syntriax.Modules.State
{
public static class IStateEnableExtensions
{
/// <summary>
/// Checks if the provided parameter <see cref="IStateEnable"/> is enabled, if the parameter is null returns the nullValue parameter
/// </summary>
/// <param name="StateEnable"><see cref="IStateEnable"/> to be checked if enabled or not</param>
/// <param name="nullValue">The value that will be returned if <see cref="IEnabledState"/> is null. Default value: true</param>
/// <returns><see cref="IStateEnable"/>'s toggle value, or if null return nullValue parameter</returns>
public static bool IsEnabledNullChecked(this IStateEnable stateEnable, bool nullValue = true)
=> stateEnable == null ? nullValue : stateEnable.IsEnabled;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ff97669ed76e39540b7aa38be50a5e1a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
using System;
namespace Syntriax.Modules.State
{
public class StateEnableMember : IStateEnable
{
private bool _isEnabled = true;
public StateEnableMember() { }
public StateEnableMember(bool isEnabled) => IsEnabled = isEnabled;
public bool IsEnabled
{
get => _isEnabled;
set
{
if (value == _isEnabled)
return;
_isEnabled = value;
OnEnabledChanged?.Invoke(value);
}
}
public Action<bool> OnEnabledChanged { get; set; } = null;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39e2c42e15ad5304db28ad23b5cb666f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
using System;
using UnityEngine;
namespace Syntriax.Modules.State
{
public class StateEnableMonoBehaviour : MonoBehaviour, IStateEnable
{
private bool _isEnabled = true;
public bool IsEnabled
{
get => _isEnabled;
set
{
if (value == _isEnabled)
return;
_isEnabled = value;
OnEnabledChanged?.Invoke(value);
}
}
public Action<bool> OnEnabledChanged { get; set; } = null;
protected void Awake()
=> OnEnabledChanged += (state) => enabled = state;
protected void OnEnable() => IsEnabled = true;
protected void OnDisable() => IsEnabled = false;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d72fab208f04d2f4983894530293b606
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: