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 Awake() { _canvasGroup = GetComponent(); _panel = transform.Find(CommonConstants.Panel).gameObject; _blockImage = transform.Find(CommonConstants.BlockImage).gameObject; if (_enableBlockImage) { _blockImage.SetActive(false); } _panel.SetActive(false); } protected virtual void Start() { } protected virtual void Update() { } protected virtual void OnDestroy() { _bindingContext?.Dispose(); UiManager.Instance.UiState.UnregisterUI(this); } public void CreateInitialize() { OnCreatedInitialize(); } protected virtual void OnCreatedInitialize() { UiManager.Instance.UiState.RegisterUI(this); _bindingContext = new BindingContext(); SetupBindings(); } protected virtual void OnOpenedEvents() { } protected virtual void OnClosedEvents() { } // BaseUi 메서드들을 직접 구현 public virtual void OpenPanel() { if (_enableBlockImage) { _blockImage.SetActive(true); } _panel.SetActive(true); OnOpenedEvents(); } public virtual void ClosePanel() { if (_enableBlockImage) { _blockImage.SetActive(false); } _panel.SetActive(false); OnClosedEvents(); IsInitialized = false; } public virtual void SetUiInteractable(bool active) { if (_canvasGroup) { _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) { // 하위 클래스에서 구현 } } }