update
This commit is contained in:
@@ -22,6 +22,7 @@ namespace UVC.UI.Window.PropertyWindow
|
||||
DateTime,
|
||||
Enum,
|
||||
DropdownList,
|
||||
Button,
|
||||
RadioGroup,
|
||||
IntRange,
|
||||
FloatRange,
|
||||
@@ -233,6 +234,30 @@ namespace UVC.UI.Window.PropertyWindow
|
||||
}
|
||||
}
|
||||
|
||||
public class ButtonProperty : PropertyItem<string>
|
||||
{
|
||||
public override PropertyType PropertyType => PropertyType.Button;
|
||||
|
||||
private Action? _onClick;
|
||||
|
||||
public ButtonProperty(string id, string name, string initialValue = "")
|
||||
: base(id, name, initialValue) { }
|
||||
|
||||
public ButtonProperty BindClick(Action? onClick)
|
||||
{
|
||||
_onClick = onClick;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI에서 버튼 클릭 시 호출
|
||||
/// </summary>
|
||||
public void InvokeClick()
|
||||
{
|
||||
if (IsReadOnly) return;
|
||||
_onClick?.Invoke();
|
||||
}
|
||||
}
|
||||
public class BoolProperty : PropertyItem<bool>
|
||||
{
|
||||
public override PropertyType PropertyType => PropertyType.Bool;
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace UVC.UI.Window.PropertyWindow
|
||||
[SerializeField] private GameObject _enumPropertyPrefab;
|
||||
[SerializeField] private GameObject _listPropertyPrefab;
|
||||
[SerializeField] private GameObject _radioGroupPropertyPrefab;
|
||||
[SerializeField] private GameObject _buttonPropertyPrefab;
|
||||
[SerializeField] private GameObject _numberRangePropertyPrefab;
|
||||
[SerializeField] private GameObject _dateRangePropertyPrefab;
|
||||
[SerializeField] private GameObject _dateTimeRangePropertyPrefab;
|
||||
@@ -283,6 +284,8 @@ namespace UVC.UI.Window.PropertyWindow
|
||||
return _listPropertyPrefab;
|
||||
case PropertyType.RadioGroup:
|
||||
return _radioGroupPropertyPrefab;
|
||||
case PropertyType.Button:
|
||||
return _buttonPropertyPrefab;
|
||||
case PropertyType.IntRange:
|
||||
return _numberRangePropertyPrefab;
|
||||
case PropertyType.FloatRange:
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UVC.UI.Tooltip;
|
||||
using UVC.UI.Window.PropertyWindow;
|
||||
|
||||
public class ButtonPropertyUI : MonoBehaviour, IPropertyUI
|
||||
{
|
||||
[Header("UI Components")]
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _nameLabel; // 속성 이름을 표시할 Text
|
||||
[SerializeField]
|
||||
private Button _button; // 열거형 값을 선택할 Dropdown
|
||||
|
||||
private ButtonProperty _propertyItem;
|
||||
private PropertyWindow _controller;
|
||||
|
||||
/// <summary>
|
||||
/// PropertyView에 의해 호출되어 UI를 초기화하고 데이터를 설정합니다.
|
||||
/// </summary>
|
||||
public void Setup(IPropertyItem item, PropertyWindow controller)
|
||||
{
|
||||
if (!(item is ButtonProperty enumItem))
|
||||
{
|
||||
Debug.LogError($"EnumPropertyUI에 잘못된 타입의 PropertyItem이 전달되었습니다. {item.GetType()}");
|
||||
return;
|
||||
}
|
||||
|
||||
_propertyItem = enumItem;
|
||||
_controller = controller;
|
||||
|
||||
// --- 데이터 바인딩 ---
|
||||
_nameLabel.text = _propertyItem.Name;
|
||||
|
||||
// 읽기 전용 상태 설정
|
||||
_button.interactable = !_propertyItem.IsReadOnly;
|
||||
|
||||
// --- 이벤트 리스너 등록 ---
|
||||
_button.onClick.RemoveAllListeners();
|
||||
_button.onClick.AddListener(OnButtonClickedChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 사용자가 Dropdown의 선택 항목을 변경했을 때 호출됩니다.
|
||||
/// </summary>
|
||||
/// <param name="index">새로 선택된 항목의 인덱스</param>
|
||||
private void OnButtonClickedChanged()
|
||||
{
|
||||
_propertyItem.InvokeClick();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI의 읽기 전용 상태를 설정합니다.
|
||||
/// </summary>
|
||||
/// <param name="isReadOnly">읽기 전용 여부 (true: 비활성화, false: 활성화)</param>
|
||||
public void SetReadOnly(bool isReadOnly)
|
||||
{
|
||||
if (_propertyItem != null)
|
||||
{
|
||||
_propertyItem.IsReadOnly = isReadOnly;
|
||||
}
|
||||
if (_button != null) _button.interactable = !isReadOnly;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 이 UI 오브젝트가 파괴될 때 Unity에 의해 호출됩니다.
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_button != null)
|
||||
{
|
||||
_button.onClick.RemoveAllListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f377f3befdce7964cad62bd7a8d89894
|
||||
Reference in New Issue
Block a user