BREAKING CHANGE: Turned ActionBase and ActionBaseWithDeactivations To Non-Abstract Classes

This commit is contained in:
Syntriax 2023-03-20 23:47:15 +03:00
parent 42c81ada1d
commit d45811ea77
6 changed files with 49 additions and 61 deletions

29
Runtime/Action.cs Normal file
View File

@ -0,0 +1,29 @@
using System;
using Syntriax.Modules.State;
using UnityEngine;
namespace Syntriax.Modules.Action
{
public class Action : MonoBehaviour, IAction
{
private IStateEnable _stateEnable = null;
public IStateEnable StateEnable
{
get
{
_stateEnable = _stateEnable ?? GetComponent<State.IStateEnable>() ?? gameObject.AddComponent<State.StateEnableMonoBehaviour>();
return _stateEnable;
}
}
public Action<IAction> OnActivated { get; set; } = null;
public void Activate()
{
if (!StateEnable.IsEnabledNullChecked())
return;
OnActivated?.Invoke(this);
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d07cd6f6a7a635c41add4964a6aba382
guid: f0778370286865d42a8453967944ab67
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,31 +0,0 @@
using System;
using Syntriax.Modules.State;
using UnityEngine;
namespace Syntriax.Modules.Action
{
public abstract class ActionBase : MonoBehaviour, IAction
{
public IStateEnable StateEnable { get; protected set; } = null;
public Action<IAction> OnActivated { get; set; } = null;
protected virtual void Awake()
{
StateEnable = new StateEnableMember(true);
OnActivated += (_) => OnActionActivated();
}
/// <summary>
/// Called when the current <see cref="ActionBase"/> gets activated
/// </summary>
protected abstract void OnActionActivated();
public virtual void Activate()
{
if (!StateEnable.IsEnabledNullChecked())
return;
OnActivated?.Invoke(this);
}
}
}

View File

@ -1,28 +0,0 @@
using System;
using Syntriax.Modules.State;
namespace Syntriax.Modules.Action
{
public abstract class ActionBaseWithDeactivation : ActionBase, IActionWithDeactivation
{
public Action<IAction> OnDeactivated { get; set; } = null;
protected override void Awake()
{
base.Awake();
OnDeactivated += (_) => OnActionDeactivated();
}
/// <summary>
/// Called when the current <see cref="ActionBase"/> gets deactivated
/// </summary>
protected abstract void OnActionDeactivated();
public virtual void Deactivate()
{
if (!StateEnable.IsEnabledNullChecked())
return;
OnDeactivated?.Invoke(this);
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using Syntriax.Modules.State;
namespace Syntriax.Modules.Action
{
public class ActionWithDeactivation : Action, IActionWithDeactivation
{
public Action<IAction> OnDeactivated { get; set; } = null;
public void Deactivate()
{
if (!StateEnable.IsEnabledNullChecked())
return;
OnDeactivated?.Invoke(this);
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7bce8bd8b35a51f4785a3933e3526ddf
guid: c41fb1050f19d6c479295ba680295261
MonoImporter:
externalObjects: {}
serializedVersion: 2