unity-atoms/Packages/Core/Runtime/Actions/AtomAction.cs

200 lines
6.0 KiB
C#
Raw Normal View History

using System;
2018-10-30 15:05:06 -04:00
using UnityEngine;
namespace UnityAtoms
{
2019-10-15 13:19:44 -04:00
/// <summary>
/// Base abstract class for Actions. Inherits from `BaseAtom`.
/// </summary>
public abstract class AtomAction : BaseAtom
{
/// <summary>
/// The actual Action.
/// </summary>
[HideInInspector]
public Action ActionNoValue;
/// <summary>
/// Perform the Action.
/// </summary>
public virtual void Do()
{
if (ActionNoValue != null)
{
ActionNoValue();
return;
}
}
}
/// <summary>
/// Generic abstract base class for Actions. Inherits from `AtomAction`.
2019-10-15 13:19:44 -04:00
/// </summary>
/// <typeparam name="T1">The type for this Action.</typeparam>
public abstract class AtomAction<T1> : AtomAction
2018-10-30 15:05:06 -04:00
{
2019-10-15 14:44:25 -04:00
/// <summary>
/// The actual Action.
/// </summary>
[HideInInspector]
public Action<T1> Action;
2019-10-15 14:44:25 -04:00
/// <summary>
/// Perform the Action.
/// </summary>
/// <param name="t1">The first parameter.</param>
public virtual void Do(T1 t1)
{
base.Do();
if (Action != null)
{
Action(t1);
return;
}
throw new Exception("Either set Action or override the Do method.");
}
2018-10-30 15:05:06 -04:00
}
2019-10-15 14:44:25 -04:00
/// <summary>
/// Generic abstract base class for Actions. Inherits from `AtomAction`.
2019-10-15 14:44:25 -04:00
/// </summary>
/// <typeparam name="T1">The first type for this Action.</typeparam>
/// <typeparam name="T2">The second type for this Action.</typeparam>
public abstract class AtomAction<T1, T2> : AtomAction
2018-10-30 15:05:06 -04:00
{
2019-10-15 14:44:25 -04:00
/// <summary>
/// The actual Action.
/// </summary>
[HideInInspector]
public Action<T1, T2> Action;
2019-10-15 14:44:25 -04:00
/// <summary>
/// Perform the Action.
/// </summary>
/// <param name="t1">The first parameter.</param>
/// <param name="t2">The second parameter.</param>
public virtual void Do(T1 t1, T2 t2)
{
base.Do();
if (Action != null)
{
Action(t1, t2);
return;
}
throw new Exception("Either set Action or override the Do method.");
}
2018-10-30 15:05:06 -04:00
}
2019-10-15 14:44:25 -04:00
/// <summary>
/// Generic abstract base class for Actions. Inherits from `AtomAction`.
2019-10-15 14:44:25 -04:00
/// </summary>
/// <typeparam name="T1">The first type for this Action.</typeparam>
/// <typeparam name="T2">The second type for this Action.</typeparam>
/// <typeparam name="T3">The third type for this Action.</typeparam>
public abstract class AtomAction<T1, T2, T3> : AtomAction
2018-10-30 15:05:06 -04:00
{
2019-10-15 14:44:25 -04:00
/// <summary>
/// The actual Action.
/// </summary>
[HideInInspector]
public Action<T1, T2, T3> Action;
2019-10-15 14:44:25 -04:00
/// <summary>
/// Perform the Action.
/// </summary>
/// <param name="t1">The first parameter.</param>
/// <param name="t2">The second parameter.</param>
/// <param name="t3">The third parameter.</param>
public virtual void Do(T1 t1, T2 t2, T3 t3)
{
base.Do();
if (Action != null)
{
Action(t1, t2, t3);
return;
}
throw new Exception("Either set Action or override the Do method.");
}
2018-10-30 15:05:06 -04:00
}
2019-10-15 14:44:25 -04:00
/// <summary>
/// Generic abstract base class for Actions. Inherits from `AtomAction`.
2019-10-15 14:44:25 -04:00
/// </summary>
/// <typeparam name="T1">The first type for this Action.</typeparam>
/// <typeparam name="T2">The second type for this Action.</typeparam>
/// <typeparam name="T3">The third type for this Action.</typeparam>
/// <typeparam name="T4">The fourth type for this Action.</typeparam>
public abstract class AtomAction<T1, T2, T3, T4> : AtomAction
2018-10-30 15:05:06 -04:00
{
2019-10-15 14:44:25 -04:00
/// <summary>
/// The actual Action.
/// </summary>
[HideInInspector]
public Action<T1, T2, T3, T4> Action;
2019-10-15 14:44:25 -04:00
/// <summary>
/// Perform the Action.
/// </summary>
/// <param name="t1">The first parameter.</param>
/// <param name="t2">The second parameter.</param>
/// <param name="t3">The third parameter.</param>
/// <param name="t4">The fourth parameter.</param>
public virtual void Do(T1 t1, T2 t2, T3 t3, T4 t4)
{
base.Do();
if (Action != null)
{
Action(t1, t2, t3, t4);
return;
}
throw new Exception("Either set Action or override the Do method.");
}
2018-10-30 15:05:06 -04:00
}
2019-10-15 14:44:25 -04:00
/// <summary>
/// Generic abstract base class for Actions. Inherits from `AtomAction`.
2019-10-15 14:44:25 -04:00
/// </summary>
/// <typeparam name="T1">The first type for this Action.</typeparam>
/// <typeparam name="T2">The second type for this Action.</typeparam>
/// <typeparam name="T3">The third type for this Action.</typeparam>
/// <typeparam name="T4">The fourth type for this Action.</typeparam>
/// <typeparam name="T5">The fifth type for this Action.</typeparam>
public abstract class AtomAction<T1, T2, T3, T4, T5> : AtomAction
2018-10-30 15:05:06 -04:00
{
2019-10-15 14:44:25 -04:00
/// <summary>
/// The actual Action.
/// </summary>
[HideInInspector]
public Action<T1, T2, T3, T4, T5> Action;
2019-10-15 14:44:25 -04:00
/// <summary>
/// Perform the Action.
/// </summary>
/// <param name="t1">The first parameter.</param>
/// <param name="t2">The second parameter.</param>
/// <param name="t3">The third parameter.</param>
/// <param name="t4">The fourth parameter.</param>
/// <param name="t5">The fifth parameter.</param>
public virtual void Do(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
base.Do();
if (Action != null)
{
Action(t1, t2, t3, t4, t5);
return;
}
throw new Exception("Either set Action or override the Do method.");
}
2018-10-30 15:05:06 -04:00
}
}