unity-atoms/Packages/Core/Runtime/Functions/AtomFunction.cs

144 lines
3.5 KiB
C#
Raw Normal View History

using System;
2018-10-30 15:05:06 -04:00
using UnityEngine;
namespace UnityAtoms
{
[UseIcon("atom-icon-sand")]
public abstract class AtomFunction<R> : BaseAtom, IAtomFunctionIcon
2018-10-30 15:05:06 -04:00
{
[HideInInspector]
public Func<R> Func;
public virtual R Call()
{
if (Func != null)
{
return Func();
}
throw new Exception("Either set Func or override the Call method.");
}
2019-04-12 10:41:54 -04:00
public AtomFunction<R> SetFunc(Func<R> func)
2019-04-12 10:41:54 -04:00
{
Func = func;
return this;
}
2018-10-30 15:05:06 -04:00
}
[UseIcon("atom-icon-sand")]
public abstract class AtomFunction<R, T1> : BaseAtom, IAtomFunctionIcon
2018-10-30 15:05:06 -04:00
{
[HideInInspector]
public Func<T1, R> Func;
public virtual R Call(T1 t1)
{
if (Func != null)
{
return Func(t1);
}
throw new Exception("Either set Func or override the Call method.");
}
2019-04-12 10:41:54 -04:00
public AtomFunction<R, T1> SetFunc(Func<T1, R> func)
2019-04-12 10:41:54 -04:00
{
Func = func;
return this;
}
2018-10-30 15:05:06 -04:00
}
[UseIcon("atom-icon-sand")]
public abstract class AtomFunction<R, T1, T2> : BaseAtom, IAtomFunctionIcon
2018-10-30 15:05:06 -04:00
{
[HideInInspector]
public Func<T1, T2, R> Func;
public virtual R Call(T1 t1, T2 t2)
{
if (Func != null)
{
return Func(t1, t2);
}
throw new Exception("Either set Func or override the Call method.");
}
2019-04-12 10:41:54 -04:00
public AtomFunction<R, T1, T2> SetFunc(Func<T1, T2, R> func)
2019-04-12 10:41:54 -04:00
{
Func = func;
return this;
}
2018-10-30 15:05:06 -04:00
}
[UseIcon("atom-icon-sand")]
public abstract class AtomFunction<R, T1, T2, T3> : BaseAtom, IAtomFunctionIcon
2018-10-30 15:05:06 -04:00
{
[HideInInspector]
public Func<T1, T2, T3, R> Func;
public virtual R Call(T1 t1, T2 t2, T3 t3)
{
if (Func != null)
{
return Func(t1, t2, t3);
}
throw new Exception("Either set Func or override the Call method.");
}
2019-04-12 10:41:54 -04:00
public AtomFunction<R, T1, T2, T3> SetFunc(Func<T1, T2, T3, R> func)
2019-04-12 10:41:54 -04:00
{
Func = func;
return this;
}
2018-10-30 15:05:06 -04:00
}
[UseIcon("atom-icon-sand")]
public abstract class AtomFunction<R, T1, T2, T3, T4> : BaseAtom, IAtomFunctionIcon
2018-10-30 15:05:06 -04:00
{
[HideInInspector]
public Func<T1, T2, T3, T4, R> Func;
public virtual R Call(T1 t1, T2 t2, T3 t3, T4 t4)
{
if (Func != null)
{
return Func(t1, t2, t3, t4);
}
throw new Exception("Either set Func or override the Call method.");
}
2019-04-12 10:41:54 -04:00
public AtomFunction<R, T1, T2, T3, T4> SetFunc(Func<T1, T2, T3, T4, R> func)
2019-04-12 10:41:54 -04:00
{
Func = func;
return this;
}
2018-10-30 15:05:06 -04:00
}
[UseIcon("atom-icon-sand")]
public abstract class AtomFunction<R, T1, T2, T3, T4, T5> : BaseAtom, IAtomFunctionIcon
2018-10-30 15:05:06 -04:00
{
[HideInInspector]
public Func<T1, T2, T3, T4, T5, R> Func;
public virtual R Call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
if (Func != null)
{
return Func(t1, t2, t3, t4, t5);
}
throw new Exception("Either set Func or override the Call method.");
}
2019-04-12 10:41:54 -04:00
public AtomFunction<R, T1, T2, T3, T4, T5> SetFunc(Func<T1, T2, T3, T4, T5, R> func)
2019-04-12 10:41:54 -04:00
{
Func = func;
return this;
}
2018-10-30 15:05:06 -04:00
}
}