This commit is contained in:
Syntriax 2023-03-20 22:16:07 +03:00
commit 4f316e39cc
18 changed files with 107 additions and 99 deletions

View File

@ -1,2 +1,2 @@
# ToggleState
# State

8
Runtime/Enable.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 488baa4b12357c44d83fcdba794ce57c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5be36869d5a2d95418a7db5213b80ccf
guid: 9017443f63486e0438e09eeb335eb8bc
MonoImporter:
externalObjects: {}
serializedVersion: 2

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

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 174255e0fce0b3a4e8b5e34afa96ffd3
guid: ff97669ed76e39540b7aa38be50a5e1a
MonoImporter:
externalObjects: {}
serializedVersion: 2

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

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d603bc1aca0fb74498aaa2270e82135b
guid: 39e2c42e15ad5304db28ad23b5cb666f
MonoImporter:
externalObjects: {}
serializedVersion: 2

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

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d321123fb56053e49b20da45bfda3a65
guid: d72fab208f04d2f4983894530293b606
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,15 +0,0 @@
using System;
namespace Syntriax.Modules.ToggleState
{
public interface IToggleState
{
/// <summary>
/// Called everytime the IsToggled field is changed
/// </summary>
/// <value>The new value of IsToggled</value>
Action<bool> OnToggleStateChanged { get; set; }
bool IsToggled { get; set; }
}
}

View File

@ -1,14 +0,0 @@
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;
}
}

View File

@ -0,0 +1,3 @@
{
"name": "Syntriax.Modules.State"
}

View File

@ -1,3 +0,0 @@
{
"name": "Syntriax.Modules.ToggleState"
}

View File

@ -1,27 +0,0 @@
using System;
namespace Syntriax.Modules.ToggleState
{
public class ToggleStateMember : IToggleState
{
private bool _isToggled = true;
public ToggleStateMember() { }
public ToggleStateMember(bool isToggled) => IsToggled = isToggled;
public bool IsToggled
{
get => _isToggled;
set
{
if (value == _isToggled)
return;
_isToggled = value;
OnToggleStateChanged?.Invoke(value);
}
}
public Action<bool> OnToggleStateChanged { get; set; } = null;
}
}

View File

@ -1,30 +0,0 @@
using System;
using UnityEngine;
namespace Syntriax.Modules.ToggleState
{
public class ToggleStateMonoBehaviour : MonoBehaviour, IToggleState
{
private bool _isToggled = true;
public bool IsToggled
{
get => _isToggled;
set
{
if (value == _isToggled)
return;
_isToggled = value;
OnToggleStateChanged?.Invoke(value);
}
}
public Action<bool> OnToggleStateChanged { get; set; } = null;
protected void Awake()
=> OnToggleStateChanged += (state) => enabled = state;
protected void OnEnable() => IsToggled = true;
protected void OnDisable() => IsToggled = false;
}
}

View File

@ -1,11 +1,11 @@
{
"name": "com.syntriax.toggle-state",
"version": "0.1.1",
"displayName": "Toggle State Module",
"name": "com.syntriax.state",
"version": "0.2.0",
"displayName": "State Module",
"unity": "2019.1",
"documentationUrl": "https://git.syntriax.com/Syntriax/ToggleState.git",
"documentationUrl": "https://git.syntriax.com/Syntriax/State.git",
"dependencies": {},
"keywords": ["Toggle State", "Switch"],
"keywords": ["State"],
"author": {
"name": "Syntriax",
"email": "Syntriax@gmail.com",