ProjectDDD/Assets/_DDD/_Scripts/GameUi/BaseUi/PopupUis/BasePopupUi.cs

71 lines
1.9 KiB
C#
Raw Normal View History

2025-07-29 15:56:47 +00:00
using UnityEngine;
using UnityEngine.EventSystems;
namespace DDD
{
public abstract class BasePopupUi : BaseUi
{
2025-08-21 07:25:27 +00:00
public bool IsTopPopup => UiManager.Instance.UiState.IsTopPopup(this);
2025-08-21 09:15:51 +00:00
public InputActionMaps InputActionMaps { get; protected set; }
2025-08-14 10:39:27 +00:00
protected override void Awake()
{
_enableBlockImage = true;
2025-08-24 11:44:32 +00:00
base.Awake();
2025-08-20 09:08:41 +00:00
}
2025-07-29 15:56:47 +00:00
protected override void Update()
{
base.Update();
2025-08-24 11:44:32 +00:00
2025-08-21 10:11:47 +00:00
if (IsOpenPanel() == false || IsInitialized == false) return;
2025-08-17 07:23:05 +00:00
2025-07-29 15:56:47 +00:00
var currentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
2025-08-21 07:25:27 +00:00
if (!currentSelectedGameObject || currentSelectedGameObject.activeInHierarchy == false)
2025-07-29 15:56:47 +00:00
{
2025-08-20 09:08:41 +00:00
var initialSelected = GetInitialSelected();
2025-08-21 07:25:27 +00:00
if (initialSelected)
2025-08-20 09:08:41 +00:00
{
EventSystem.current.SetSelectedGameObject(initialSelected);
}
2025-07-29 15:56:47 +00:00
}
}
2025-08-24 11:44:32 +00:00
protected override void OnDestroy()
2025-08-20 09:08:41 +00:00
{
2025-08-24 11:44:32 +00:00
base.OnDestroy();
2025-08-20 09:08:41 +00:00
2025-08-24 11:44:32 +00:00
UiManager.Instance?.UiState?.UnregisterPopupUI(this);
2025-08-20 09:08:41 +00:00
}
2025-08-24 11:44:32 +00:00
protected override void OnCreatedInitialize()
2025-07-29 15:56:47 +00:00
{
2025-08-24 11:44:32 +00:00
base.OnCreatedInitialize();
2025-07-29 15:56:47 +00:00
2025-08-24 11:44:32 +00:00
UiManager.Instance.UiState.RegisterPopupUI(this);
2025-08-20 09:08:41 +00:00
}
public virtual void Open(OpenPopupUiEvent evt)
{
OpenPanel();
var initialSelected = GetInitialSelected();
if (initialSelected != null)
{
EventSystem.current.SetSelectedGameObject(initialSelected);
}
transform.SetAsLastSibling();
2025-07-29 15:56:47 +00:00
}
2025-08-05 04:00:01 +00:00
public virtual void Close()
{
var evt = GameEvents.ClosePopupUiEvent;
evt.UiType = GetType();
EventBus.Broadcast(evt);
}
2025-08-20 09:08:41 +00:00
protected abstract GameObject GetInitialSelected();
}
}