Neg_Utils/NEG/UI/UnityUi/Buttons/CloseWindow.cs
2023-02-02 16:36:57 +01:00

23 lines
620 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
{
[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>();
}
}
}