UIToolkit Sample uxml로 전환
This commit is contained in:
@@ -3,7 +3,6 @@ using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UVC.UIToolkit.Modal;
|
||||
|
||||
namespace UVC.UIToolkit
|
||||
{
|
||||
|
||||
@@ -4,9 +4,7 @@ using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UVC.UIToolkit.Common;
|
||||
|
||||
namespace UVC.UIToolkit.Modal
|
||||
namespace UVC.UIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// UIToolkit 기반 컬러 피커 모달
|
||||
|
||||
@@ -5,10 +5,8 @@ using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UVC.Locale;
|
||||
using UVC.UIToolkit.Common;
|
||||
using UVC.UIToolkit.Input;
|
||||
|
||||
namespace UVC.UIToolkit.Modal
|
||||
namespace UVC.UIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// UIToolkit 기반 날짜/시간 피커 모달
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UVC.UIToolkit.Modal;
|
||||
|
||||
namespace UVC.UIToolkit
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UVC.UIToolkit.Modal
|
||||
namespace UVC.UIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// 모달 뒤의 배경을 차단하고 클릭 시 닫힘 처리를 담당하는 컴포넌트
|
||||
|
||||
@@ -3,7 +3,6 @@ using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UVC.UIToolkit.Common;
|
||||
|
||||
namespace UVC.UIToolkit
|
||||
{
|
||||
@@ -163,12 +162,9 @@ namespace UVC.UIToolkit
|
||||
SubscribeToThemeChanges();
|
||||
|
||||
// UXML에서 로드될 때 속성이 설정된 후 UI 갱신
|
||||
RegisterCallback<AttachToPanelEvent>(_ =>
|
||||
{
|
||||
if (_titleLabel != null) _titleLabel.text = _title;
|
||||
if (_messageLabel != null) _messageLabel.text = _message;
|
||||
UpdateType();
|
||||
});
|
||||
// Unity 6의 소스 생성기는 Deserialize에서 필드에 직접 값을 할당하므로
|
||||
// AttachToPanelEvent를 사용하여 패널에 연결된 후 UI를 갱신
|
||||
RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
|
||||
}
|
||||
|
||||
public UTKNotification(string title, string message, NotificationType type = NotificationType.Info) : this()
|
||||
@@ -289,6 +285,15 @@ namespace UVC.UIToolkit
|
||||
{
|
||||
UTKThemeManager.Instance.ApplyThemeToElement(this);
|
||||
}
|
||||
|
||||
private void OnAttachToPanel(AttachToPanelEvent evt)
|
||||
{
|
||||
// UXML 속성이 설정된 후 한 번만 UI 갱신
|
||||
UnregisterCallback<AttachToPanelEvent>(OnAttachToPanel);
|
||||
if (_titleLabel != null) _titleLabel.text = _title;
|
||||
if (_messageLabel != null) _messageLabel.text = _message;
|
||||
UpdateType();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
@@ -35,17 +35,17 @@ namespace UVC.UIToolkit
|
||||
/// <code>
|
||||
/// <ui:UXML xmlns:utk="UVC.UIToolkit">
|
||||
/// <!-- 기본 패널 -->
|
||||
/// <utk:UTKPanel Title="제목">
|
||||
/// <utk:UTKPanel title="제목">
|
||||
/// <ui:Label text="패널 내용" />
|
||||
/// </utk:UTKPanel>
|
||||
///
|
||||
///
|
||||
/// <!-- 접을 수 있는 패널 -->
|
||||
/// <utk:UTKPanel Title="고급 설정" IsCollapsible="true">
|
||||
/// <utk:UTKPanel title="고급 설정" is-collapsible="true">
|
||||
/// <ui:Label text="내용" />
|
||||
/// </utk:UTKPanel>
|
||||
///
|
||||
///
|
||||
/// <!-- 외곽선 스타일 -->
|
||||
/// <utk:UTKPanel Title="외곽선" Variant="Outlined" />
|
||||
/// <utk:UTKPanel title="외곽선" variant="Outlined" />
|
||||
/// </ui:UXML>
|
||||
/// </code>
|
||||
/// </example>
|
||||
@@ -79,7 +79,7 @@ namespace UVC.UIToolkit
|
||||
|
||||
#region Properties
|
||||
/// <summary>패널 제목</summary>
|
||||
[UxmlAttribute]
|
||||
[UxmlAttribute("title")]
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
@@ -91,7 +91,7 @@ namespace UVC.UIToolkit
|
||||
}
|
||||
|
||||
/// <summary>헤더 표시 여부</summary>
|
||||
[UxmlAttribute]
|
||||
[UxmlAttribute("show-header")]
|
||||
public bool ShowHeader
|
||||
{
|
||||
get => _showHeader;
|
||||
@@ -106,7 +106,7 @@ namespace UVC.UIToolkit
|
||||
}
|
||||
|
||||
/// <summary>푸터 표시 여부</summary>
|
||||
[UxmlAttribute]
|
||||
[UxmlAttribute("show-footer")]
|
||||
public bool ShowFooter
|
||||
{
|
||||
get => _showFooter;
|
||||
@@ -121,7 +121,7 @@ namespace UVC.UIToolkit
|
||||
}
|
||||
|
||||
/// <summary>패널 스타일</summary>
|
||||
[UxmlAttribute]
|
||||
[UxmlAttribute("variant")]
|
||||
public PanelVariant Variant
|
||||
{
|
||||
get => _variant;
|
||||
@@ -133,7 +133,7 @@ namespace UVC.UIToolkit
|
||||
}
|
||||
|
||||
/// <summary>접기 가능 여부</summary>
|
||||
[UxmlAttribute]
|
||||
[UxmlAttribute("is-collapsible")]
|
||||
public bool IsCollapsible
|
||||
{
|
||||
get => _isCollapsible;
|
||||
@@ -145,15 +145,18 @@ namespace UVC.UIToolkit
|
||||
}
|
||||
|
||||
/// <summary>접힘 상태</summary>
|
||||
[UxmlAttribute]
|
||||
[UxmlAttribute("is-collapsed")]
|
||||
public bool IsCollapsed
|
||||
{
|
||||
get => _isCollapsed;
|
||||
set => SetCollapsed(value, true);
|
||||
}
|
||||
|
||||
/// <summary>콘텐츠 영역</summary>
|
||||
public VisualElement? ContentContainer => _content;
|
||||
/// <summary>
|
||||
/// UXML에서 자식 요소가 추가될 컨테이너.
|
||||
/// 이 속성을 오버라이드하여 자식 요소들이 _content 영역에 추가되도록 합니다.
|
||||
/// </summary>
|
||||
public override VisualElement contentContainer => _content ?? this;
|
||||
|
||||
/// <summary>푸터 영역</summary>
|
||||
public VisualElement? FooterContainer => _footer;
|
||||
@@ -175,8 +178,10 @@ namespace UVC.UIToolkit
|
||||
#region Constructor
|
||||
public UTKPanel()
|
||||
{
|
||||
// 1. 먼저 테마 스타일시트 적용 (변수 정의)
|
||||
UTKThemeManager.Instance.ApplyThemeToElement(this);
|
||||
|
||||
// 2. 컴포넌트 USS 적용 (변수 사용)
|
||||
var uss = Resources.Load<StyleSheet>(USS_PATH);
|
||||
if (uss != null)
|
||||
{
|
||||
@@ -186,6 +191,9 @@ namespace UVC.UIToolkit
|
||||
CreateUI();
|
||||
SetupEvents();
|
||||
SubscribeToThemeChanges();
|
||||
|
||||
// UXML에서 로드될 때 속성이 설정된 후 UI 갱신
|
||||
RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
|
||||
}
|
||||
|
||||
public UTKPanel(string title) : this()
|
||||
@@ -215,6 +223,7 @@ namespace UVC.UIToolkit
|
||||
// Content
|
||||
_content = new VisualElement { name = "content" };
|
||||
_content.AddToClassList("utk-panel__content");
|
||||
_content.RegisterCallback<GeometryChangedEvent>(OnContentGeometryChanged);
|
||||
hierarchy.Add(_content);
|
||||
|
||||
// Footer
|
||||
@@ -226,6 +235,25 @@ namespace UVC.UIToolkit
|
||||
UpdateVariant();
|
||||
}
|
||||
|
||||
private void OnContentGeometryChanged(GeometryChangedEvent evt)
|
||||
{
|
||||
// Content 영역 내 Label 요소에 스타일 클래스 추가
|
||||
ApplyContentLabelStyles();
|
||||
}
|
||||
|
||||
private void ApplyContentLabelStyles()
|
||||
{
|
||||
if (_content == null) return;
|
||||
|
||||
foreach (var child in _content.Children())
|
||||
{
|
||||
if (child is Label label && !label.ClassListContains("utk-panel__content-label"))
|
||||
{
|
||||
label.AddToClassList("utk-panel__content-label");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupEvents()
|
||||
{
|
||||
_header?.RegisterCallback<ClickEvent>(OnHeaderClick);
|
||||
@@ -247,6 +275,49 @@ namespace UVC.UIToolkit
|
||||
#endregion
|
||||
|
||||
#region Event Handlers
|
||||
private void OnAttachToPanel(AttachToPanelEvent evt)
|
||||
{
|
||||
// UXML 속성이 설정된 후 한 번만 UI 갱신
|
||||
UnregisterCallback<AttachToPanelEvent>(OnAttachToPanel);
|
||||
|
||||
// Title 적용
|
||||
if (_titleLabel != null)
|
||||
{
|
||||
_titleLabel.text = _title;
|
||||
}
|
||||
|
||||
// Header 표시 상태 적용
|
||||
if (_header != null)
|
||||
{
|
||||
_header.style.display = _showHeader ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
|
||||
// Footer 표시 상태 적용
|
||||
if (_footer != null)
|
||||
{
|
||||
_footer.style.display = _showFooter ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
|
||||
// Variant 적용
|
||||
UpdateVariant();
|
||||
|
||||
// Collapsible 상태 적용
|
||||
EnableInClassList("utk-panel--collapsible", _isCollapsible);
|
||||
|
||||
// Collapsed 상태 적용
|
||||
if (_isCollapsed)
|
||||
{
|
||||
EnableInClassList("utk-panel--collapsed", true);
|
||||
if (_content != null)
|
||||
{
|
||||
_content.style.display = DisplayStyle.None;
|
||||
}
|
||||
}
|
||||
|
||||
// UXML 자식 요소 스타일 적용 (지연 실행)
|
||||
schedule.Execute(ApplyContentLabelStyles);
|
||||
}
|
||||
|
||||
private void OnHeaderClick(ClickEvent evt)
|
||||
{
|
||||
if (!_isCollapsible) return;
|
||||
@@ -298,14 +369,6 @@ namespace UVC.UIToolkit
|
||||
AddToClassList(variantClass);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 콘텐츠 추가
|
||||
/// </summary>
|
||||
public new void Add(VisualElement element)
|
||||
{
|
||||
_content?.Add(element);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 헤더 액션 추가
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user