ProjectDDD/Assets/_DDD/_Scripts/Game/GameUi/BaseUi/BaseUi.cs
2025-08-29 12:53:54 +09:00

114 lines
3.2 KiB
C#

using System.ComponentModel;
using UnityEngine;
namespace DDD
{
public enum UiType
{
None = 0,
Hud,
Interaction,
Popup,
Common
}
public abstract class BaseUi : MonoBehaviour
{
[field: SerializeField] public UiType UiType { get; set; }
[SerializeField] protected bool _enableBlockImage;
protected CanvasGroup _canvasGroup;
protected GameObject _blockImage;
protected GameObject _panel;
protected BindingContext _bindingContext;
public bool IsInitialized { get; protected set; }
public bool IsBlockingTime => false;
public bool IsOpen => _panel != null && _panel.activeSelf;
protected virtual void OnEnable() { }
protected virtual void Start() { }
protected virtual void Update() { }
protected virtual void OnDisable() { }
protected virtual void OnDestroy()
{
_bindingContext?.Dispose();
UiManager.Instance.UiState.UnregisterUI(this);
}
public void CreateInitialize()
{
UiManager.Instance.UiState.RegisterUI(this);
_canvasGroup = GetComponent<CanvasGroup>();
_panel = transform.Find(CommonConstants.Panel).gameObject;
_blockImage = transform.Find(CommonConstants.BlockImage).gameObject;
_panel.SetActive(false);
_bindingContext = new BindingContext();
OnCreatedInitialize();
if (_enableBlockImage)
{
_blockImage.SetActive(false);
}
}
protected abstract void OnCreatedInitialize();
protected abstract void OnOpenedEvents();
protected abstract void OnClosedEvents();
protected void OpenPanel()
{
if (_enableBlockImage)
{
_blockImage.SetActive(true);
}
_panel.SetActive(true);
OnOpenedEvents();
}
protected void ClosePanel()
{
if (_enableBlockImage)
{
_blockImage.SetActive(false);
}
_panel.SetActive(false);
OnClosedEvents();
IsInitialized = false;
}
public void SetUiInteractable(bool active)
{
if (_canvasGroup)
{
_canvasGroup.interactable = active;
_canvasGroup.blocksRaycasts = active;
}
}
public bool IsOpenPanel() => _panel && _panel.activeInHierarchy;
/// <summary>
/// ViewModel 속성 변경 이벤트 핸들러
/// </summary>
protected void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
{
HandleCustomPropertyChanged(e.PropertyName);
}
/// <summary>
/// 커스텀 속성 변경 처리 (하위 클래스에서 오버라이드)
/// </summary>
protected virtual void HandleCustomPropertyChanged(string propertyName)
{
// 하위 클래스에서 구현
}
}
}