unity-atoms/Packages/Core/Runtime/Utils/DynamicAtoms.cs

119 lines
3.7 KiB
C#
Raw Normal View History

2019-04-12 04:19:40 -04:00
using System;
using UnityEngine;
2019-10-01 11:27:22 -04:00
namespace UnityAtoms
{
public static class DynamicAtoms
{
2019-04-12 03:41:53 -04:00
public static V CreateVariable<T, V, E1, E2>(T initialValue, E1 changed = null, E2 changedWithHistory = null)
where V : AtomVariable<T, E1, E2>
where E1 : AtomEvent<T> where E2 : AtomEvent<T, T>
{
var sov = ScriptableObject.CreateInstance<V>();
2019-04-12 03:41:53 -04:00
sov.Changed = changed;
sov.ChangedWithHistory = changedWithHistory;
sov.Value = initialValue;
return sov;
}
2019-04-12 03:41:53 -04:00
public static L CreateList<T, L, E>(E added = null, E removed = null, VoidEvent cleared = null)
where L : AtomList<T, E>
where E : AtomEvent<T>
{
var sol = ScriptableObject.CreateInstance<L>();
2019-04-12 03:41:53 -04:00
sol.Added = added;
sol.Removed = removed;
sol.Cleared = cleared;
return sol;
}
2019-04-12 04:19:40 -04:00
public static GA CreateAction<GA, T1>(Action<T1> action)
where GA : AtomAction<T1>
2019-04-12 04:19:40 -04:00
{
var ga = ScriptableObject.CreateInstance<GA>();
ga.Action = action;
return ga;
}
public static GA CreateAction<GA, T1, T2>(Action<T1, T2> action)
where GA : AtomAction<T1, T2>
2019-04-12 04:19:40 -04:00
{
var ga = ScriptableObject.CreateInstance<GA>();
ga.Action = action;
return ga;
}
public static GA CreateAction<GA, T1, T2, T3>(Action<T1, T2, T3> action)
where GA : AtomAction<T1, T2, T3>
2019-04-12 04:19:40 -04:00
{
var ga = ScriptableObject.CreateInstance<GA>();
ga.Action = action;
return ga;
}
public static GA CreateAction<GA, T1, T2, T3, T4>(Action<T1, T2, T3, T4> action)
where GA : AtomAction<T1, T2, T3, T4>
2019-04-12 04:19:40 -04:00
{
var ga = ScriptableObject.CreateInstance<GA>();
ga.Action = action;
return ga;
}
public static GA CreateAction<GA, T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> action)
where GA : AtomAction<T1, T2, T3, T4, T5>
2019-04-12 04:19:40 -04:00
{
var ga = ScriptableObject.CreateInstance<GA>();
ga.Action = action;
return ga;
}
public static GF CreateFunction<GF, R>(Func<R> func)
where GF : AtomFunction<R>
2019-04-12 04:19:40 -04:00
{
var gf = ScriptableObject.CreateInstance<GF>();
gf.Func = func;
return gf;
}
public static GF CreateFunction<GF, R, T1>(Func<T1, R> func)
where GF : AtomFunction<R, T1>
2019-04-12 04:19:40 -04:00
{
var gf = ScriptableObject.CreateInstance<GF>();
gf.Func = func;
return gf;
}
public static GF CreateFunction<GF, R, T1, T2>(Func<T1, T2, R> func)
where GF : AtomFunction<R, T1, T2>
2019-04-12 04:19:40 -04:00
{
var gf = ScriptableObject.CreateInstance<GF>();
gf.Func = func;
return gf;
}
public static GF CreateFunction<GF, R, T1, T2, T3>(Func<T1, T2, T3, R> func)
where GF : AtomFunction<R, T1, T2, T3>
2019-04-12 04:19:40 -04:00
{
var gf = ScriptableObject.CreateInstance<GF>();
gf.Func = func;
return gf;
}
public static GF CreateFunction<GF, R, T1, T2, T3, T4>(Func<T1, T2, T3, T4, R> func)
where GF : AtomFunction<R, T1, T2, T3, T4>
2019-04-12 04:19:40 -04:00
{
var gf = ScriptableObject.CreateInstance<GF>();
gf.Func = func;
return gf;
}
public static GF CreateFunction<GF, R, T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, R> func)
where GF : AtomFunction<R, T1, T2, T3, T4, T5>
2019-04-12 04:19:40 -04:00
{
var gf = ScriptableObject.CreateInstance<GF>();
gf.Func = func;
return gf;
}
}
}