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

137 lines
3.4 KiB
C#
Raw Normal View History

2025-07-29 15:56:47 +00:00
using System;
2025-08-20 09:08:41 +00:00
using System.ComponentModel;
using System.Linq;
using System.Reflection;
2025-08-21 07:25:27 +00:00
using TMPro;
2025-07-21 07:53:39 +00:00
using UnityEngine;
2025-08-20 09:08:41 +00:00
using UnityEngine.UI;
2025-07-21 07:53:39 +00:00
namespace DDD
{
2025-08-21 07:25:27 +00:00
public enum UiType
{
None = 0,
Hud,
Interaction,
Popup,
Common
}
2025-07-21 07:53:39 +00:00
public abstract class BaseUi : MonoBehaviour
{
2025-08-21 07:25:27 +00:00
[field: SerializeField] public UiType UiType { get; set; }
2025-08-20 09:08:41 +00:00
[SerializeField] protected bool _enableBlockImage;
2025-08-05 05:14:39 +00:00
protected CanvasGroup _canvasGroup;
2025-08-14 10:39:27 +00:00
protected GameObject _blockImage;
2025-07-22 07:46:37 +00:00
protected GameObject _panel;
2025-08-20 09:08:41 +00:00
protected BindingContext _bindingContext;
2025-07-21 07:53:39 +00:00
public virtual bool IsBlockingTime => false;
2025-08-20 09:08:41 +00:00
public virtual bool IsOpen => _panel != null && _panel.activeSelf;
2025-08-14 10:39:27 +00:00
2025-07-22 07:46:37 +00:00
protected virtual void Awake()
{
2025-08-05 05:14:39 +00:00
_canvasGroup = GetComponent<CanvasGroup>();
2025-08-20 09:08:41 +00:00
_panel = transform.Find(CommonConstants.Panel)?.gameObject;
_blockImage = transform.Find(CommonConstants.BlockImage)?.gameObject;
_bindingContext = new BindingContext();
SetupBindings();
2025-07-22 07:46:37 +00:00
}
2025-08-14 08:21:17 +00:00
protected virtual void OnEnable()
{
2025-08-20 09:08:41 +00:00
2025-08-14 08:21:17 +00:00
}
2025-08-14 10:39:27 +00:00
2025-07-21 07:53:39 +00:00
protected virtual void Start()
{
2025-08-05 04:00:01 +00:00
ClosePanel();
2025-07-21 07:53:39 +00:00
}
2025-07-29 15:56:47 +00:00
protected virtual void Update()
{
2025-08-20 09:08:41 +00:00
2025-07-29 15:56:47 +00:00
}
2025-08-14 08:21:17 +00:00
protected virtual void OnDisable()
{
2025-08-20 09:08:41 +00:00
2025-08-14 08:21:17 +00:00
}
2025-07-21 07:53:39 +00:00
protected virtual void OnDestroy()
{
TryUnregister();
2025-08-20 09:08:41 +00:00
_bindingContext?.Dispose();
2025-07-21 07:53:39 +00:00
}
2025-08-14 10:39:27 +00:00
2025-08-21 07:25:27 +00:00
public virtual void CreateInitialize()
{
TryRegister();
}
protected virtual void TryRegister()
{
UiManager.Instance.UiState.RegisterUI(this);
}
protected virtual void TryUnregister()
{
UiManager.Instance.UiState.UnregisterUI(this);
}
2025-07-21 07:53:39 +00:00
2025-08-20 09:08:41 +00:00
// BaseUi 메서드들을 직접 구현
2025-08-14 10:39:27 +00:00
public virtual void OpenPanel()
{
if (_enableBlockImage)
{
_blockImage.SetActive(true);
}
_panel.SetActive(true);
}
public virtual void ClosePanel()
{
if (_enableBlockImage)
{
_blockImage.SetActive(false);
}
_panel.SetActive(false);
}
2025-08-05 05:14:39 +00:00
public virtual void SetUiInteractable(bool active)
{
2025-08-20 09:08:41 +00:00
if (_canvasGroup != null)
{
_canvasGroup.interactable = active;
_canvasGroup.blocksRaycasts = active;
}
}
public bool IsOpenPanel() => _panel && _panel.activeInHierarchy;
/// <summary>
/// 추가 바인딩 설정 - 하위 클래스에서 구현
/// </summary>
protected virtual void SetupBindings() { }
/// <summary>
/// ViewModel 속성 변경 이벤트 핸들러
/// </summary>
protected virtual void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
{
HandleCustomPropertyChanged(e.PropertyName);
2025-08-05 05:14:39 +00:00
}
2025-08-17 07:23:05 +00:00
2025-08-20 09:08:41 +00:00
/// <summary>
/// 커스텀 속성 변경 처리 (하위 클래스에서 오버라이드)
/// </summary>
protected virtual void HandleCustomPropertyChanged(string propertyName)
{
// 하위 클래스에서 구현
}
2025-07-21 07:53:39 +00:00
}
}