스타일 가이드 적용 완료. UTKCOlorPicker, UTKDatePicker 확인해야 함
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UVC.Locale;
|
||||
@@ -18,9 +19,12 @@ namespace UVC.Sample.UIToolkit
|
||||
private VisualElement? _root;
|
||||
private Label? _dateLabel;
|
||||
private Label? _dateTimeLabel;
|
||||
private Label? _dateRangeLabel;
|
||||
|
||||
private DateTime _selectedDate = DateTime.Today;
|
||||
private DateTime _selectedDateTime = DateTime.Now;
|
||||
private DateTime _rangeStartDate = DateTime.Today;
|
||||
private DateTime _rangeEndDate = DateTime.Today.AddDays(7);
|
||||
private UTKDatePicker? _currentPicker;
|
||||
|
||||
private void Start()
|
||||
@@ -78,6 +82,44 @@ namespace UVC.Sample.UIToolkit
|
||||
_dateTimeLabel.text = FormatDateTime(_selectedDateTime);
|
||||
container.Add(dateTimeSection.container);
|
||||
|
||||
// Async 섹션
|
||||
var asyncSection = new VisualElement();
|
||||
asyncSection.style.marginBottom = 15;
|
||||
|
||||
var asyncLabel = new Label("Async/Await Mode");
|
||||
asyncLabel.style.color = new Color(0.8f, 0.8f, 0.8f);
|
||||
asyncLabel.style.fontSize = 12;
|
||||
asyncLabel.style.marginBottom = 5;
|
||||
asyncSection.Add(asyncLabel);
|
||||
|
||||
var asyncBtn = new Button(() => OpenDatePickerAsync().Forget()) { text = "Open Date Picker (Async)" };
|
||||
asyncBtn.style.height = 32;
|
||||
asyncSection.Add(asyncBtn);
|
||||
|
||||
container.Add(asyncSection);
|
||||
|
||||
// Date Range 섹션
|
||||
var rangeSection = CreateSection("Date Range Mode", "Open Range Picker", OpenDateRangePicker);
|
||||
_dateRangeLabel = rangeSection.label;
|
||||
_dateRangeLabel.text = FormatDateRange(_rangeStartDate, _rangeEndDate);
|
||||
container.Add(rangeSection.container);
|
||||
|
||||
// Date Range Async 섹션
|
||||
var rangeAsyncSection = new VisualElement();
|
||||
rangeAsyncSection.style.marginBottom = 15;
|
||||
|
||||
var rangeAsyncLabel = new Label("Date Range Async Mode");
|
||||
rangeAsyncLabel.style.color = new Color(0.8f, 0.8f, 0.8f);
|
||||
rangeAsyncLabel.style.fontSize = 12;
|
||||
rangeAsyncLabel.style.marginBottom = 5;
|
||||
rangeAsyncSection.Add(rangeAsyncLabel);
|
||||
|
||||
var rangeAsyncBtn = new Button(() => OpenDateRangePickerAsync().Forget()) { text = "Open Range Picker (Async)" };
|
||||
rangeAsyncBtn.style.height = 32;
|
||||
rangeAsyncSection.Add(rangeAsyncBtn);
|
||||
|
||||
container.Add(rangeAsyncSection);
|
||||
|
||||
// 구분선
|
||||
var separator = new VisualElement();
|
||||
separator.style.height = 1;
|
||||
@@ -185,6 +227,34 @@ namespace UVC.Sample.UIToolkit
|
||||
_currentPicker.OnClosed += OnPickerClosed;
|
||||
}
|
||||
|
||||
private async UniTaskVoid OpenDatePickerAsync()
|
||||
{
|
||||
if (_root == null) return;
|
||||
|
||||
// ShowAsync를 사용하여 날짜 선택 대기
|
||||
// OK 클릭 시 선택된 날짜 반환, 취소/닫기 시 null 반환
|
||||
DateTime? result = await UTKDatePicker.ShowAsync(
|
||||
_root,
|
||||
_selectedDate,
|
||||
UTKDatePicker.PickerMode.DateOnly,
|
||||
"Select Date (Async)"
|
||||
);
|
||||
|
||||
if (result.HasValue)
|
||||
{
|
||||
_selectedDate = result.Value;
|
||||
if (_dateLabel != null)
|
||||
{
|
||||
_dateLabel.text = FormatDate(result.Value);
|
||||
}
|
||||
Debug.Log($"[Async] Date Result: {FormatDate(result.Value)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[Async] Date selection cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDateSelected(DateTime date)
|
||||
{
|
||||
_selectedDate = date;
|
||||
@@ -245,12 +315,75 @@ namespace UVC.Sample.UIToolkit
|
||||
return dateTime.ToString("yyyy-MM-dd HH:mm");
|
||||
}
|
||||
|
||||
private string FormatDateRange(DateTime start, DateTime end)
|
||||
{
|
||||
return $"{start:yyyy-MM-dd} ~ {end:yyyy-MM-dd}";
|
||||
}
|
||||
|
||||
private void OpenDateRangePicker()
|
||||
{
|
||||
if (_root == null || _currentPicker != null) return;
|
||||
|
||||
_currentPicker = UTKDatePicker.ShowRange(
|
||||
_root,
|
||||
_rangeStartDate,
|
||||
_rangeEndDate,
|
||||
false,
|
||||
"Select Date Range"
|
||||
);
|
||||
|
||||
_currentPicker.OnDateRangeSelected += OnDateRangeSelected;
|
||||
_currentPicker.OnClosed += OnPickerClosed;
|
||||
}
|
||||
|
||||
private async UniTaskVoid OpenDateRangePickerAsync()
|
||||
{
|
||||
if (_root == null) return;
|
||||
|
||||
// ShowRangeAsync를 사용하여 날짜 범위 선택 대기
|
||||
// OK 클릭 시 선택된 범위 반환, 취소/닫기 시 null 반환
|
||||
var result = await UTKDatePicker.ShowRangeAsync(
|
||||
_root,
|
||||
_rangeStartDate,
|
||||
_rangeEndDate,
|
||||
false,
|
||||
"Select Date Range (Async)"
|
||||
);
|
||||
|
||||
if (result.HasValue)
|
||||
{
|
||||
_rangeStartDate = result.Value.Start;
|
||||
_rangeEndDate = result.Value.End;
|
||||
if (_dateRangeLabel != null)
|
||||
{
|
||||
_dateRangeLabel.text = FormatDateRange(result.Value.Start, result.Value.End);
|
||||
}
|
||||
Debug.Log($"[Async] Range Result: {FormatDateRange(result.Value.Start, result.Value.End)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[Async] Date range selection cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDateRangeSelected(DateTime start, DateTime end)
|
||||
{
|
||||
_rangeStartDate = start;
|
||||
_rangeEndDate = end;
|
||||
if (_dateRangeLabel != null)
|
||||
{
|
||||
_dateRangeLabel.text = FormatDateRange(start, end);
|
||||
}
|
||||
Debug.Log($"Date Range Selected: {FormatDateRange(start, end)}");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_currentPicker != null)
|
||||
{
|
||||
_currentPicker.OnDateSelected -= OnDateSelected;
|
||||
_currentPicker.OnDateSelected -= OnDateTimeSelected;
|
||||
_currentPicker.OnDateRangeSelected -= OnDateRangeSelected;
|
||||
_currentPicker.OnClosed -= OnPickerClosed;
|
||||
_currentPicker.Dispose();
|
||||
_currentPicker = null;
|
||||
|
||||
Reference in New Issue
Block a user