152 lines
4.3 KiB
C#
152 lines
4.3 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UVC.UI.Window.PropertyWindow
|
|
{
|
|
/// <summary>
|
|
/// 속성 그룹의 UI를 담당하는 View 클래스입니다.
|
|
/// 접이식 헤더와 자식 아이템들의 컨테이너를 관리합니다.
|
|
/// </summary>
|
|
public class PropertyGroupView : MonoBehaviour
|
|
{
|
|
[Header("Header")]
|
|
[SerializeField] private Button _headerButton;
|
|
[SerializeField] private TextMeshProUGUI _groupNameLabel;
|
|
[SerializeField] private Image _expandIcon;
|
|
|
|
[Header("Icons")]
|
|
[SerializeField] private Sprite _expandedIcon;
|
|
[SerializeField] private Sprite _collapsedIcon;
|
|
|
|
[Header("Content")]
|
|
[SerializeField] private Transform _itemContainer;
|
|
[SerializeField] private GameObject _contentPanel;
|
|
|
|
private IPropertyGroup _group;
|
|
private PropertyWindow _controller;
|
|
|
|
/// <summary>
|
|
/// 자식 PropertyItem UI들이 생성될 컨테이너입니다.
|
|
/// </summary>
|
|
public Transform ItemContainer => _itemContainer;
|
|
|
|
/// <summary>
|
|
/// 그룹 데이터
|
|
/// </summary>
|
|
public IPropertyGroup Group => _group;
|
|
|
|
/// <summary>
|
|
/// 그룹 ID
|
|
/// </summary>
|
|
public string GroupId => _group?.GroupId;
|
|
|
|
/// <summary>
|
|
/// PropertyGroupView를 초기화합니다.
|
|
/// </summary>
|
|
/// <param name="group">표시할 그룹 데이터</param>
|
|
/// <param name="controller">상호작용할 컨트롤러</param>
|
|
public void Setup(IPropertyGroup group, PropertyWindow controller)
|
|
{
|
|
_group = group;
|
|
_controller = controller;
|
|
|
|
// 그룹명 설정
|
|
if (_groupNameLabel != null)
|
|
{
|
|
_groupNameLabel.text = group.GroupName;
|
|
}
|
|
|
|
// 헤더 버튼 이벤트 등록
|
|
if (_headerButton != null)
|
|
{
|
|
_headerButton.onClick.RemoveAllListeners();
|
|
_headerButton.onClick.AddListener(OnHeaderClicked);
|
|
}
|
|
|
|
// 펼침/접힘 상태 반영
|
|
UpdateExpandedState();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 헤더 클릭 시 호출됩니다.
|
|
/// </summary>
|
|
private void OnHeaderClicked()
|
|
{
|
|
if (_controller != null && _group != null)
|
|
{
|
|
_controller.ToggleGroupExpanded(_group.GroupId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 펼침/접힘 상태를 UI에 반영합니다.
|
|
/// </summary>
|
|
public void UpdateExpandedState()
|
|
{
|
|
if (_group == null) return;
|
|
|
|
bool isExpanded = _group.IsExpanded;
|
|
|
|
// 컨텐츠 패널 표시/숨김
|
|
if (_contentPanel != null)
|
|
{
|
|
_contentPanel.SetActive(isExpanded);
|
|
}
|
|
|
|
// 아이콘 변경
|
|
if (_expandIcon != null)
|
|
{
|
|
if (isExpanded && _expandedIcon != null)
|
|
{
|
|
_expandIcon.sprite = _expandedIcon;
|
|
}
|
|
else if (!isExpanded && _collapsedIcon != null)
|
|
{
|
|
_expandIcon.sprite = _collapsedIcon;
|
|
}
|
|
|
|
// 아이콘 회전으로 표현할 경우
|
|
_expandIcon.transform.rotation = Quaternion.Euler(0, 0, isExpanded ? 0 : -90);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 그룹 내 모든 아이템 UI를 제거합니다.
|
|
/// </summary>
|
|
public void ClearItems()
|
|
{
|
|
if (_itemContainer == null) return;
|
|
|
|
foreach (Transform child in _itemContainer)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 풀에 반환하기 전에 정리합니다.
|
|
/// </summary>
|
|
public void Reset()
|
|
{
|
|
_group = null;
|
|
_controller = null;
|
|
|
|
if (_headerButton != null)
|
|
{
|
|
_headerButton.onClick.RemoveAllListeners();
|
|
}
|
|
|
|
ClearItems();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_headerButton != null)
|
|
{
|
|
_headerButton.onClick.RemoveAllListeners();
|
|
}
|
|
}
|
|
}
|
|
}
|