using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

/// <summary>
/// 이거로 UI 동작 막게 할거면 @Canvas 아래다 넣으면서 SetAsLastSibling()로 가장 하단 넣어두면 댐 
/// </summary>
public class UIPanel : MonoBehaviour
{
    private Image _background;
    public event Action OnPanelClicked;
    
    void Awake()
    {
        _background = GetComponent<Image>();
        _background.raycastTarget = true;
        
        EventTrigger trigger = GetComponent<EventTrigger>();
        if (trigger == null)
            trigger = gameObject.AddComponent<EventTrigger>();
        
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;
        
        entry.callback.AddListener((eventData) => {
            OnPanelClicked?.Invoke();
        });
        
        trigger.triggers.Clear();
        trigger.triggers.Add(entry);
        
    }
    
}
