using System;
using UnityEngine;
using Stary.Evo;

namespace Stary.Evo
{
    public class OnBecameInvisibleEventTrigger : MonoBehaviour
    {
        public readonly EasyEvent OnBecameInvisibleEvent = new EasyEvent();

        private void OnBecameInvisible()
        {
            OnBecameInvisibleEvent.Trigger();
        }
    }

    public static class OnBecameInvisibleEventTriggerExtension
    {
        public static IUnRegister OnBecameInvisibleEvent<T>(this T self, Action onBecameInvisible)
            where T : Component
        {
            return self.GetOrAddComponent<OnBecameInvisibleEventTrigger>().OnBecameInvisibleEvent
                .Register(onBecameInvisible);
        }

        public static IUnRegister OnBecameInvisibleEvent(this GameObject self, Action onBecameInvisible)
        {
            return self.GetOrAddComponent<OnBecameInvisibleEventTrigger>().OnBecameInvisibleEvent
                .Register(onBecameInvisible);
        }
    }
}