BREAKING CHANGE: State 0.2.0
This commit is contained in:
parent
e97119befc
commit
f2faa86f65
@ -1,4 +1,4 @@
|
|||||||
# Trigger
|
# Trigger
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
1. [ToggleState Module](https://git.syntriax.com/Syntriax/ToggleState)
|
1. [State Module](https://git.syntriax.com/Syntriax/State)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Trigger
|
namespace Syntriax.Modules.Trigger
|
||||||
{
|
{
|
||||||
@ -13,7 +13,7 @@ namespace Syntriax.Modules.Trigger
|
|||||||
|
|
||||||
private void FixedUpdate()
|
private void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (!ToggleStateMember.IsToggledNullChecked())
|
if (!StateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IsTrigerred = colliderTrigger.Check();
|
IsTrigerred = colliderTrigger.Check();
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Trigger
|
namespace Syntriax.Modules.Trigger
|
||||||
{
|
{
|
||||||
public interface ITrigger
|
public interface ITrigger
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Member <see cref="IToggleState"/> to switch on or off
|
/// <see cref="IStateEnable"/> to switch on or off
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IToggleState ToggleStateMember { get; }
|
IStateEnable StateEnable { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called everytime the IsTrigerred field is changed
|
/// Called everytime the IsTrigerred field is changed
|
||||||
|
@ -1,22 +1,43 @@
|
|||||||
using System;
|
using System;
|
||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Trigger
|
namespace Syntriax.Modules.Trigger
|
||||||
{
|
{
|
||||||
public class TriggerBase : MonoBehaviour, ITrigger
|
public class TriggerBase : MonoBehaviour, ITrigger
|
||||||
{
|
{
|
||||||
public IToggleState ToggleStateMember { get; protected set; } = new ToggleStateMember(true);
|
|
||||||
|
|
||||||
public Action<bool> OnTriggerStateChanged { get; set; } = null;
|
public Action<bool> OnTriggerStateChanged { get; set; } = null;
|
||||||
|
|
||||||
|
private IStateEnable stateEnable = null;
|
||||||
|
public IStateEnable StateEnable
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (stateEnable == null)
|
||||||
|
{
|
||||||
|
stateEnable = GetComponent<IStateEnable>() ?? gameObject.AddComponent<StateEnableMonoBehaviour>();
|
||||||
|
stateEnable.OnEnabledChanged += OnEnabledChanged;
|
||||||
|
}
|
||||||
|
return stateEnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnabledChanged(bool enabled)
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isTrigerred = false;
|
||||||
|
OnTriggerStateChanged?.Invoke(false);
|
||||||
|
}
|
||||||
|
|
||||||
private bool _isTrigerred = false;
|
private bool _isTrigerred = false;
|
||||||
public bool IsTrigerred
|
public bool IsTrigerred
|
||||||
{
|
{
|
||||||
get => _isTrigerred;
|
get => _isTrigerred;
|
||||||
protected set
|
protected set
|
||||||
{
|
{
|
||||||
if (value == _isTrigerred || !ToggleStateMember.IsToggledNullChecked())
|
if (value == _isTrigerred || !StateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_isTrigerred = value;
|
_isTrigerred = value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user