95 lines
2.8 KiB
C#
95 lines
2.8 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UVC.UI.Commands;
|
|
|
|
namespace UVC.UI.Toolbar
|
|
{
|
|
/// <summary>
|
|
/// 모든 버튼의 기본 추상 클래스입니다.
|
|
/// 공통적인 속성 (예: 텍스트, 아이콘, 활성화 상태) 및 동작을 정의합니다.
|
|
/// </summary>
|
|
public abstract class ToolbarButtonBase : IToolbarItem
|
|
{
|
|
public event Action OnStateChanged; // 상태 변경 알림 이벤트
|
|
|
|
protected string _text;
|
|
public string Text
|
|
{
|
|
get => _text;
|
|
set
|
|
{
|
|
if (_text != value)
|
|
{
|
|
_text = value;
|
|
OnStateChanged?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string _iconSpritePath;
|
|
public string IconSpritePath
|
|
{
|
|
get => _iconSpritePath;
|
|
set
|
|
{
|
|
if (_iconSpritePath != value)
|
|
{
|
|
_iconSpritePath = value;
|
|
OnStateChanged?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected bool _isEnabled = true;
|
|
public bool IsEnabled
|
|
{
|
|
get => _isEnabled;
|
|
set
|
|
{
|
|
if (_isEnabled != value)
|
|
{
|
|
_isEnabled = value;
|
|
OnStateChanged?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string _tooltipKey; // 툴팁 다국어 키
|
|
public string TooltipKey
|
|
{
|
|
get => _tooltipKey;
|
|
set
|
|
{
|
|
if (_tooltipKey != value)
|
|
{
|
|
_tooltipKey = value;
|
|
// TooltipKey 변경 시 OnStateChanged를 호출할 필요는 일반적으로 없으나,
|
|
// 만약 UI가 TooltipKey 자체를 표시하는 등의 로직이 있다면 필요할 수 있습니다.
|
|
// 여기서는 툴팁 내용이 동적으로 변경되는 경우가 적다고 가정하고 생략합니다.
|
|
}
|
|
}
|
|
}
|
|
|
|
public ICommand ClickCommand { get; set; }
|
|
|
|
/// <summary>
|
|
/// 버튼 클릭 로직을 실행합니다.
|
|
/// 이 메서드는 일반적으로 UI 이벤트에 의해 호출됩니다.
|
|
/// </summary>
|
|
/// <param name="parameter">커맨드에 전달할 파라미터입니다.</param>
|
|
public virtual void ExecuteClick(object parameter = null)
|
|
{
|
|
if (IsEnabled && ClickCommand != null)
|
|
{
|
|
ClickCommand.Execute(parameter); // 커맨드에 파라미터 전달
|
|
}
|
|
}
|
|
|
|
// OnStateChanged 이벤트를 외부에서 강제로 발생시켜야 할 때 사용 (예: 복합적인 상태 변경 후)
|
|
public void NotifyStateChanged()
|
|
{
|
|
OnStateChanged?.Invoke();
|
|
}
|
|
}
|
|
}
|