118 lines
3.1 KiB
C#
118 lines
3.1 KiB
C#
#nullable enable
|
|
|
|
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace UVC.UIToolkit
|
|
{
|
|
/// <summary>
|
|
/// 툴바 내 시각적 구분선 컴포넌트입니다.
|
|
/// 가로 배치 시 세로선, 세로 배치 시 가로선으로 표시됩니다.
|
|
/// </summary>
|
|
[UxmlElement]
|
|
public partial class UTKToolBarSeparator : VisualElement, IDisposable
|
|
{
|
|
#region Fields
|
|
|
|
private bool _disposed;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// UTKToolBarSeparator의 새 인스턴스를 초기화합니다.
|
|
/// </summary>
|
|
public UTKToolBarSeparator()
|
|
{
|
|
// 1. 테마 적용
|
|
UTKThemeManager.Instance.ApplyThemeToElement(this);
|
|
|
|
// 2. USS 로드
|
|
var uss = Resources.Load<StyleSheet>("UIToolkit/ToolBar/UTKToolBarSeparatorUss");
|
|
if (uss != null)
|
|
{
|
|
styleSheets.Add(uss);
|
|
}
|
|
|
|
// 3. UI 생성
|
|
CreateUI();
|
|
|
|
// 4. 테마 구독
|
|
SubscribeToThemeChanges();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Setup
|
|
|
|
/// <summary>
|
|
/// UI를 생성합니다.
|
|
/// </summary>
|
|
private void CreateUI()
|
|
{
|
|
var asset = Resources.Load<VisualTreeAsset>("UIToolkit/ToolBar/UTKToolBarSeparator");
|
|
if (asset != null)
|
|
{
|
|
var root = asset.Instantiate();
|
|
Add(root);
|
|
}
|
|
else
|
|
{
|
|
// Fallback
|
|
var separator = new VisualElement();
|
|
separator.AddToClassList("utk-toolbar-separator");
|
|
Add(separator);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Theme
|
|
|
|
private void SubscribeToThemeChanges()
|
|
{
|
|
UTKThemeManager.Instance.OnThemeChanged += OnThemeChanged;
|
|
RegisterCallback<AttachToPanelEvent>(OnAttachToPanelForTheme);
|
|
RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanelForTheme);
|
|
}
|
|
|
|
private void OnAttachToPanelForTheme(AttachToPanelEvent evt)
|
|
{
|
|
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
|
|
UTKThemeManager.Instance.OnThemeChanged += OnThemeChanged;
|
|
UTKThemeManager.Instance.ApplyThemeToElement(this);
|
|
}
|
|
|
|
private void OnDetachFromPanelForTheme(DetachFromPanelEvent evt)
|
|
{
|
|
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
|
|
}
|
|
|
|
private void OnThemeChanged(UTKTheme theme)
|
|
{
|
|
UTKThemeManager.Instance.ApplyThemeToElement(this);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IDisposable
|
|
|
|
/// <summary>
|
|
/// 리소스를 정리합니다.
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
if (_disposed) return;
|
|
_disposed = true;
|
|
|
|
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
|
|
UnregisterCallback<AttachToPanelEvent>(OnAttachToPanelForTheme);
|
|
UnregisterCallback<DetachFromPanelEvent>(OnDetachFromPanelForTheme);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|