using System; using System.ComponentModel; using System.Linq; using System.Reflection; using TMPro; using UnityEngine; using UnityEngine.UI; 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 Awake() { _canvasGroup = GetComponent(); _panel = transform.Find(CommonConstants.Panel)?.gameObject; _blockImage = transform.Find(CommonConstants.BlockImage)?.gameObject; _bindingContext = new BindingContext(); SetupBindings(); } protected virtual void OnEnable() { } protected virtual void Start() { ClosePanel(); } protected virtual void Update() { } protected virtual void OnDisable() { } protected virtual void OnDestroy() { TryUnregister(); _bindingContext?.Dispose(); } public virtual void CreateInitialize() { TryRegister(); } protected virtual void TryRegister() { UiManager.Instance.UiState.RegisterUI(this); } protected virtual void TryUnregister() { UiManager.Instance.UiState.UnregisterUI(this); } // BaseUi 메서드들을 직접 구현 public virtual void OpenPanel() { if (_enableBlockImage) { _blockImage.SetActive(true); } _panel.SetActive(true); } public virtual void ClosePanel() { if (_enableBlockImage) { _blockImage.SetActive(false); } _panel.SetActive(false); IsInitialized = false; } public virtual void SetUiInteractable(bool active) { if (_canvasGroup != null) { _canvasGroup.interactable = active; _canvasGroup.blocksRaycasts = active; } } public bool IsOpenPanel() => _panel && _panel.activeInHierarchy; /// /// 추가 바인딩 설정 - 하위 클래스에서 구현 /// protected virtual void SetupBindings() { } /// /// ViewModel 속성 변경 이벤트 핸들러 /// protected virtual void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e) { HandleCustomPropertyChanged(e.PropertyName); } /// /// 커스텀 속성 변경 처리 (하위 클래스에서 오버라이드) /// protected virtual void HandleCustomPropertyChanged(string propertyName) { // 하위 클래스에서 구현 } } }