Neg_Utils/NEG/UI/UnityUi/Buttons/CloseWindow.cs

24 lines
673 B
C#

using NEG.UI.UnityUi.Window;
using NEG.UI.Window;
using System;
using UnityEngine;
namespace NEG.UI.UnityUi.Buttons
{
[RequireComponent(typeof(BaseButton))]
public class CloseWindow : MonoBehaviour
{
[Header("Set by hand or use editor button")]
[SerializeField] private MonoWindow windowToClose;
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked;
private void OnClicked() => windowToClose.Close();
private void OnValidate()
{
if(windowToClose != null)
return;
windowToClose = GetComponentInParent<MonoWindow>();
}
}
}