2018-11-04 04:00:06 -05:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
using UnityAtoms.Utils;
|
2019-04-07 10:03:16 -04:00
|
|
|
using UnityEngine.Serialization;
|
2018-11-04 04:00:06 -05:00
|
|
|
|
|
|
|
namespace UnityAtoms
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
public abstract class CreateListOnAwake<T, L, E, TEL, TELR, GA1, GA2, UER> : MonoBehaviour
|
2018-11-04 04:00:06 -05:00
|
|
|
where L : ScriptableObjectList<T, E> where E : GameEvent<T>
|
|
|
|
where TEL : GameEventListener<T, TELR, E, UER>
|
|
|
|
where TELR : GameAction<T>
|
|
|
|
where GA1 : GameAction<L> where GA2 : GameAction<L, GameObject>
|
|
|
|
where UER : UnityEvent<T>
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
[FormerlySerializedAs("CreateAddedEvent")]
|
2018-11-04 04:00:06 -05:00
|
|
|
[SerializeField]
|
2019-04-07 10:03:16 -04:00
|
|
|
private bool _createAddedEvent = true;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("CreateRemovedEvent")]
|
2018-11-04 04:00:06 -05:00
|
|
|
[SerializeField]
|
2019-04-07 10:03:16 -04:00
|
|
|
private bool _createRemovedEvent = true;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("CreateClearedEvent")]
|
2018-11-04 04:00:06 -05:00
|
|
|
[SerializeField]
|
2019-04-07 10:03:16 -04:00
|
|
|
private bool _createClearedEvent;
|
2018-11-04 04:00:06 -05:00
|
|
|
|
2019-04-07 10:03:16 -04:00
|
|
|
[FormerlySerializedAs("AddedListener")]
|
2018-11-04 04:00:06 -05:00
|
|
|
[SerializeField]
|
2019-04-07 10:03:16 -04:00
|
|
|
private TEL _addedListener;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("RemovedListener")]
|
2018-11-04 04:00:06 -05:00
|
|
|
[SerializeField]
|
2019-04-07 10:03:16 -04:00
|
|
|
private TEL _removedListener;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("ClearedListener")]
|
2018-11-04 04:00:06 -05:00
|
|
|
[SerializeField]
|
2019-04-07 10:03:16 -04:00
|
|
|
private VoidListener _clearedListener;
|
2018-11-04 04:00:06 -05:00
|
|
|
|
2019-04-07 10:03:16 -04:00
|
|
|
[FormerlySerializedAs("OnListCreate")]
|
2018-11-04 04:00:06 -05:00
|
|
|
[SerializeField]
|
2019-04-07 10:03:16 -04:00
|
|
|
private GA1 _onListCreate;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("OnListCreateWithGO")]
|
2018-11-04 04:00:06 -05:00
|
|
|
[SerializeField]
|
2019-04-07 10:03:16 -04:00
|
|
|
private GA2 _onListCreateWithGO;
|
2018-11-04 04:00:06 -05:00
|
|
|
|
2019-04-07 10:03:16 -04:00
|
|
|
private void Awake()
|
2018-11-04 04:00:06 -05:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
var list = DynamicAtoms.CreateList<T, L, E>(_createAddedEvent, _createRemovedEvent, _createClearedEvent);
|
2018-11-04 04:00:06 -05:00
|
|
|
|
|
|
|
if (list.Added != null)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_addedListener != null)
|
2018-11-04 04:00:06 -05:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
_addedListener.GameEvent = list.Added;
|
|
|
|
_addedListener.GameEvent.RegisterListener(_addedListener);
|
2018-11-04 04:00:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (list.Removed != null)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_removedListener != null)
|
2018-11-04 04:00:06 -05:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
_removedListener.GameEvent = list.Removed;
|
|
|
|
_removedListener.GameEvent.RegisterListener(_removedListener);
|
2018-11-04 04:00:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (list.Cleared != null)
|
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_clearedListener != null)
|
2018-11-04 04:00:06 -05:00
|
|
|
{
|
2019-04-07 10:03:16 -04:00
|
|
|
_clearedListener.GameEvent = list.Cleared;
|
|
|
|
_clearedListener.GameEvent.RegisterListener(_clearedListener);
|
2018-11-04 04:00:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-07 10:03:16 -04:00
|
|
|
if (_onListCreate != null) { _onListCreate.Do(list); }
|
|
|
|
if (_onListCreateWithGO != null) { _onListCreateWithGO.Do(list, gameObject); }
|
2018-11-04 04:00:06 -05:00
|
|
|
}
|
|
|
|
}
|
2019-03-17 18:43:20 -04:00
|
|
|
}
|