mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-23 00:28:23 -05:00
27 lines
661 B
C#
27 lines
661 B
C#
|
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>
|
||
|
[AddComponentMenu("Unity Atoms/Sync GameObject To List")]
|
||
|
[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);
|
||
|
}
|
||
|
}
|
||
|
}
|