Compare commits

..

No commits in common. "4f316e39cc85fc4f844e7037b35ef608ae5f446c" and "5c8ff0405c0456295bc36752fd2492d60eabdb45" have entirely different histories.

18 changed files with 99 additions and 107 deletions

View File

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

View File

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

View File

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

15
Runtime/IToggleState.cs Normal file
View File

@ -0,0 +1,15 @@
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,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: d72fab208f04d2f4983894530293b606 guid: 174255e0fce0b3a4e8b5e34afa96ffd3
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -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;
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,27 @@
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,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9017443f63486e0438e09eeb335eb8bc guid: 5be36869d5a2d95418a7db5213b80ccf
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -0,0 +1,30 @@
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,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 39e2c42e15ad5304db28ad23b5cb666f guid: d603bc1aca0fb74498aaa2270e82135b
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

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