using System;
using UnityEngine;
namespace UnityAtoms
{
///
/// Static helper class for when creating Atoms a runtime (yes it is indeed possible 🤯).
///
public static class DynamicAtoms
{
///
/// Create a Variable at runtime.
///
/// Inital value of the Variable created.
/// Changed Event of type `E1`.
/// Changed with history Event of type `E2`.
/// The Variable value type.
/// The Variable type AtomVariable<T, E1, E2>`.
/// The type of the `changed` Event of type `AtomEvent<T>`.
/// The type of the `changedWithHistory` Event of type `AtomEvent<T, T>`.
/// The Variable created.
public static V CreateVariable(T initialValue, E1 changed = null, E2 changedWithHistory = null)
where V : AtomVariable
where E1 : AtomEvent where E2 : AtomEvent
{
var sov = ScriptableObject.CreateInstance();
sov.Changed = changed;
sov.ChangedWithHistory = changedWithHistory;
sov.Value = initialValue;
return sov;
}
///
/// Create a List at runtime.
///
/// Added Event of type `E`.
/// Removed Event of type `E`.
/// Cleared Event of type `Void`.
/// The list item type.
/// The List type to create of type `AtomList<T, E>`.
/// The Event tyoe used for `removed` and `added` of type `AtomEvent<T>`.
/// The List created.
public static L CreateList(E added = null, E removed = null, VoidEvent cleared = null)
where L : AtomList
where E : AtomEvent
{
var sol = ScriptableObject.CreateInstance();
sol.Added = added;
sol.Removed = removed;
sol.Cleared = cleared;
return sol;
}
///
/// Create an Action at runtime.
///
/// The action.
/// The Action created of type `AtomAction<T>`.
/// The type of the first parameter of the Action.
/// The Action created
public static A CreateAction(Action action)
where A : AtomAction
{
var ga = ScriptableObject.CreateInstance();
ga.Action = action;
return ga;
}
///
/// Create an Action at runtime.
///
/// The action.
/// The Action created of type `AtomAction<T1, T2>`.
/// The type of the first parameter of the Action.
/// The type of the second parameter of the Action.
/// The Action created
public static A CreateAction(Action action)
where A : AtomAction
{
var ga = ScriptableObject.CreateInstance();
ga.Action = action;
return ga;
}
///
/// Create an Action at runtime.
///
/// The action.
/// The Action created of type `AtomAction<T1, T2, T3>`.
/// The type of the first parameter of the Action.
/// The type of the second parameter of the Action.
/// The type of the third parameter of the Action.
/// The Action created
public static GA CreateAction(Action action)
where GA : AtomAction
{
var ga = ScriptableObject.CreateInstance();
ga.Action = action;
return ga;
}
///
/// Create an Action at runtime.
///
/// The action.
/// The Action created of type `AtomAction<T1, T2, T3, T4>`.
/// The type of the first parameter of the Action.
/// The type of the second parameter of the Action.
/// The type of the third parameter of the Action.
/// The type of the fourth parameter of the Action.
/// The Action created
public static GA CreateAction(Action action)
where GA : AtomAction
{
var ga = ScriptableObject.CreateInstance();
ga.Action = action;
return ga;
}
///
/// Create an Action at runtime.
///
/// The action.
/// The Action created of type `AtomAction<T1, T2, T3, T4, T5>`.
/// The type of the first parameter of the Action.
/// The type of the second parameter of the Action.
/// The type of the third parameter of the Action.
/// The type of the fourth parameter of the Action.
/// The type of the fifth parameter of the Action.
/// The Action created
public static GA CreateAction(Action action)
where GA : AtomAction
{
var ga = ScriptableObject.CreateInstance();
ga.Action = action;
return ga;
}
///
/// Create a Function at runtime.
///
/// The function.
/// The Function created of type `AtomFunction<R>`.
/// The return type.
/// The Function crated.
public static F CreateFunction(Func func)
where F : AtomFunction
{
var gf = ScriptableObject.CreateInstance();
gf.Func = func;
return gf;
}
///
/// Create a Function at runtime.
///
/// The function.
/// The Function created of type `AtomFunction<R, T1>`.
/// The return type.
/// The type of the first parameter of the Function.
/// The Function crated.
public static F CreateFunction(Func func)
where F : AtomFunction
{
var gf = ScriptableObject.CreateInstance();
gf.Func = func;
return gf;
}
///
/// Create a Function at runtime.
///
/// The function.
/// The Function created of type `AtomFunction<R, T1, T2>`.
/// The return type.
/// The type of the first parameter of the Function.
/// The type of the second parameter of the Function.
/// The Function crated.
public static F CreateFunction(Func func)
where F : AtomFunction
{
var gf = ScriptableObject.CreateInstance();
gf.Func = func;
return gf;
}
///
/// Create a Function at runtime.
///
/// The function.
/// The Function created of type `AtomFunction<R, T1, T2, T3>`.
/// The return type.
/// The type of the first parameter of the Function.
/// The type of the second parameter of the Function.
/// The type of the third parameter of the Function.
/// The Function crated.
public static F CreateFunction(Func func)
where F : AtomFunction
{
var gf = ScriptableObject.CreateInstance();
gf.Func = func;
return gf;
}
///
/// Create a Function at runtime.
///
/// The function.
/// The Function created of type `AtomFunction<R, T1, T2, T3, T4>`.
/// The return type.
/// The type of the first parameter of the Function.
/// The type of the second parameter of the Function.
/// The type of the third parameter of the Function.
/// The type of the fourth parameter of the Function.
/// The Function crated.
public static F CreateFunction(Func func)
where F : AtomFunction
{
var gf = ScriptableObject.CreateInstance();
gf.Func = func;
return gf;
}
///
/// Create a Function at runtime.
///
/// The function.
/// The Function created of type `AtomFunction<R, T1, T2, T3, T4, T5>`.
/// The return type.
/// The type of the first parameter of the Function.
/// The type of the second parameter of the Function.
/// The type of the third parameter of the Function.
/// The type of the fourth parameter of the Function.
/// The type of the fifth parameter of the Function.
/// The Function crated.
public static F CreateFunction(Func func)
where F : AtomFunction
{
var gf = ScriptableObject.CreateInstance();
gf.Func = func;
return gf;
}
}
}