2020-03-17 21:00:18 -04:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Assertions;
|
|
|
|
|
|
|
|
namespace UnityAtoms.BaseAtoms
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Adds a GameObject to a GameObject Value List on OnEnable and removes it on OnDestroy.
|
|
|
|
/// </summary>
|
2020-03-19 03:20:15 -04:00
|
|
|
[AddComponentMenu("Unity Atoms/MonoBehaviour Helpers/Sync GameObject To List")]
|
2020-03-17 21:00:18 -04:00
|
|
|
[EditorIcon("atom-icon-delicate")]
|
|
|
|
public class SyncGameObjectToList : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private GameObjectValueList _list = default;
|
|
|
|
|
|
|
|
void OnEnable()
|
|
|
|
{
|
|
|
|
Assert.IsNotNull(_list);
|
|
|
|
_list.Add(gameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnDestroy()
|
|
|
|
{
|
|
|
|
_list.Remove(gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|