unity-atoms/Source/Base/CreateOnAwake/CreateVariableOnAwake.cs
Jeff Campbell e5f6659eda Removed unused namepaces
* Removed unused namespaces across all files in Unity.Atoms assembly.
* Removed unused namspaces in runtime and Test assembly code.
2019-04-07 11:15:23 +02:00

54 lines
2.0 KiB
C#

using UnityEngine;
using UnityEngine.Events;
using UnityAtoms.Utils;
namespace UnityAtoms
{
public class CreateVariableOnAwake<T, V, E1, E2, L1, L2, GA1, GA2, GA3, GA4, UER1, UER2> : MonoBehaviour
where V : ScriptableObjectVariable<T, E1, E2> where E1 : GameEvent<T> where E2 : GameEvent<T, T>
where L1 : GameEventListener<T, GA1, E1, UER1> where L2 : GameEventListener<T, T, GA2, E2, UER2>
where GA1 : GameAction<T> where GA2 : GameAction<T, T>
where GA3 : GameAction<V> where GA4 : GameAction<V, GameObject>
where UER1 : UnityEvent<T> where UER2 : UnityEvent<T, T>
{
[SerializeField]
private bool CreateChangedEvent = true;
[SerializeField]
private bool CreateChangedWithHistoryEvent = false;
[SerializeField]
private L1 Listener = null;
[SerializeField]
private L2 ListenerWithHistory = null;
[SerializeField]
private GA3 OnVariableCreate = null;
[SerializeField]
private GA4 OnVariableCreateWithGO = null;
void Awake()
{
var variable = DynamicAtoms.CreateVariable<T, V, E1, E2>(CreateChangedEvent, CreateChangedWithHistoryEvent);
if (variable.Changed != null)
{
if (Listener != null)
{
Listener.GameEvent = variable.Changed;
Listener.GameEvent.RegisterListener(Listener);
}
}
if (variable.ChangedWithHistory != null)
{
if (ListenerWithHistory != null)
{
ListenerWithHistory.GameEvent = variable.ChangedWithHistory;
ListenerWithHistory.GameEvent.RegisterListener(ListenerWithHistory);
}
}
if (OnVariableCreate != null) { OnVariableCreate.Do(variable); }
if (OnVariableCreateWithGO != null) { OnVariableCreateWithGO.Do(variable, gameObject); }
}
}
}