Compare commits

..

4 Commits

Author SHA1 Message Date
Syntriax 34c3a3bc8e 0.7.0 2023-03-20 22:28:24 +03:00
Syntriax d57961f5f1 0.7.0 2023-03-20 22:27:40 +03:00
Syntriax c8105122fb feat: Added State Enabled Integration to Editor Visualization Of Collider Triggers 2023-03-20 22:24:18 +03:00
Syntriax f2faa86f65 BREAKING CHANGE: State 0.2.0 2023-03-20 22:24:01 +03:00
9 changed files with 48 additions and 15 deletions

View File

@ -1,4 +1,4 @@
# Trigger
## Dependencies
1. [ToggleState Module](https://git.syntriax.com/Syntriax/ToggleState)
1. [State Module](https://git.syntriax.com/Syntriax/State)

View File

@ -11,7 +11,7 @@ namespace Syntriax.Modules.Trigger
private void OnDrawGizmosSelected()
{
if (UnityEditor.EditorApplication.isPlaying)
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
Gizmos.color = previousTriggerCount > 0 && StateEnable.IsEnabled ? Color.green : Color.red;
else
Gizmos.color = TriggerCount > 0 ? Color.green : Color.red;
Gizmos.DrawWireCube(transform.position, transform.lossyScale);

View File

@ -11,7 +11,7 @@ namespace Syntriax.Modules.Trigger
private void OnDrawGizmosSelected()
{
if (UnityEditor.EditorApplication.isPlaying)
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
Gizmos.color = previousTriggerCount > 0 && StateEnable.IsEnabled ? Color.green : Color.red;
else
Gizmos.color = TriggerCount > 0 ? Color.green : Color.red;
Gizmos.matrix = transform.localToWorldMatrix;

View File

@ -11,7 +11,7 @@ namespace Syntriax.Modules.Trigger
private void OnDrawGizmosSelected()
{
if (UnityEditor.EditorApplication.isPlaying)
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
Gizmos.color = previousTriggerCount > 0 && StateEnable.IsEnabled ? Color.green : Color.red;
else
Gizmos.color = TriggerCount > 0 ? Color.green : Color.red;

View File

@ -1,4 +1,4 @@
using Syntriax.Modules.ToggleState;
using Syntriax.Modules.State;
namespace Syntriax.Modules.Trigger
{
@ -13,7 +13,7 @@ namespace Syntriax.Modules.Trigger
private void FixedUpdate()
{
if (!ToggleStateMember.IsToggledNullChecked())
if (!StateEnable.IsEnabledNullChecked())
return;
IsTrigerred = colliderTrigger.Check();

View File

@ -45,5 +45,17 @@ namespace Syntriax.Modules.Trigger
return true;
}
#if UNITY_EDITOR
private State.IStateEnable stateEnable = null;
public State.IStateEnable StateEnable
{
get
{
stateEnable = stateEnable ?? GetComponent<State.IStateEnable>() ?? gameObject.AddComponent<State.StateEnableMonoBehaviour>();
return stateEnable;
}
}
#endif
}
}

View File

@ -1,14 +1,14 @@
using System;
using Syntriax.Modules.ToggleState;
using Syntriax.Modules.State;
namespace Syntriax.Modules.Trigger
{
public interface ITrigger
{
/// <summary>
/// Member <see cref="IToggleState"/> to switch on or off
/// <see cref="IStateEnable"/> to switch on or off
/// </summary>
IToggleState ToggleStateMember { get; }
IStateEnable StateEnable { get; }
/// <summary>
/// Called everytime the IsTrigerred field is changed

View File

@ -1,22 +1,43 @@
using System;
using Syntriax.Modules.ToggleState;
using Syntriax.Modules.State;
using UnityEngine;
namespace Syntriax.Modules.Trigger
{
public class TriggerBase : MonoBehaviour, ITrigger
{
public IToggleState ToggleStateMember { get; protected set; } = new ToggleStateMember(true);
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;
public bool IsTrigerred
{
get => _isTrigerred;
protected set
{
if (value == _isTrigerred || !ToggleStateMember.IsToggledNullChecked())
if (value == _isTrigerred || !StateEnable.IsEnabledNullChecked())
return;
_isTrigerred = value;

View File

@ -1,11 +1,11 @@
{
"name": "com.syntriax.trigger",
"version": "0.6.4",
"version": "0.7.0",
"displayName": "Trigger Module",
"unity": "2019.1",
"documentationUrl": "https://git.syntriax.com/Syntriax/Trigger.git",
"dependencies": {
"com.syntriax.toggle-state": "0.1.0"
"com.syntriax.state": "0.1.0"
},
"keywords": ["Trigger"],
"author": {