BITKit/Src/Unity/Scripts/UX/Utils/UXPanelEvent.cs

34 lines
857 B
C#
Raw Normal View History

2023-09-01 14:35:05 +08:00
using System;
2023-06-05 19:57:17 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
using UnityEngine.Events;
namespace BITKit.UX
{
2023-09-01 14:35:05 +08:00
/// <summary>
/// 基于<see cref="IUXPanel"/>的面板事件
/// </summary>
public class UXPanelEvent : MonoBehaviour
2023-06-05 19:57:17 +08:00
{
2023-09-01 14:35:05 +08:00
public UnityEvent<bool> onEntryOrExit = new();
public UnityEvent onEntry = new();
public UnityEvent onExit = new();
private void Awake()
2023-06-05 19:57:17 +08:00
{
2023-09-01 14:35:05 +08:00
var panel = GetComponent<IUXPanel>();
panel.OnEntry += OnEntry;
panel.OnExit += OnExit;
2023-06-05 19:57:17 +08:00
}
2023-09-01 14:35:05 +08:00
private void OnExit()
2023-06-29 14:57:11 +08:00
{
2023-09-01 14:35:05 +08:00
onEntryOrExit.Invoke(false);
onExit.Invoke();
}
private void OnEntry()
{
onEntryOrExit.Invoke(true);
onEntry.Invoke();
2023-06-29 14:57:11 +08:00
}
2023-06-05 19:57:17 +08:00
}
}