2026-01-08 20:15:57 +09:00
|
|
|
#nullable enable
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UIElements;
|
2026-01-20 20:18:47 +09:00
|
|
|
using UVC.UIToolkit;
|
2026-01-08 20:15:57 +09:00
|
|
|
|
|
|
|
|
namespace UVC.Sample.UIToolkit
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// UTKPropertyWindow 샘플 코드
|
|
|
|
|
/// 기존 PropertyWindowSample과 동일한 데이터를 UTKPropertyWindow로 표시
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class UTKPropertyWindowSample : MonoBehaviour
|
|
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
[SerializeField] private UIDocument _uiDocument;
|
2026-01-08 20:15:57 +09:00
|
|
|
|
2026-02-02 19:33:27 +09:00
|
|
|
[SerializeField]
|
|
|
|
|
[Tooltip("시작 시 적용할 테마")]
|
|
|
|
|
private UTKTheme initialTheme = UTKTheme.Dark;
|
|
|
|
|
|
|
|
|
|
private UTKToggle _themeToggle;
|
|
|
|
|
|
|
|
|
|
private UTKPropertyWindow _propertyWindow;
|
2026-01-08 20:15:57 +09:00
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
// UIDocument 참조 확인
|
|
|
|
|
var doc = GetComponent<UIDocument>();
|
|
|
|
|
if (doc == null)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
Debug.LogError("UIDocument가 할당되지 않았습니다.");
|
2026-01-08 20:15:57 +09:00
|
|
|
return;
|
|
|
|
|
}
|
2026-02-02 19:33:27 +09:00
|
|
|
_uiDocument = doc;
|
|
|
|
|
|
|
|
|
|
var toggle = _uiDocument.rootVisualElement.Q<UTKToggle>("toggle");
|
|
|
|
|
if (toggle == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("UXML에서 UTKToggle을 찾을 수 없습니다.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_themeToggle = toggle;
|
|
|
|
|
|
|
|
|
|
var window = _uiDocument.rootVisualElement.Q<UTKPropertyWindow>("window");
|
|
|
|
|
if (window == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("UXML에서 UTKPropertyWindow를 찾을 수 없습니다.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_propertyWindow = window;
|
|
|
|
|
|
|
|
|
|
UTKThemeManager.Instance.RegisterRoot(_uiDocument.rootVisualElement);
|
|
|
|
|
UTKThemeManager.Instance.SetTheme(initialTheme);
|
|
|
|
|
|
|
|
|
|
_themeToggle.OnValueChanged += (isOn) =>
|
|
|
|
|
{
|
|
|
|
|
UTKThemeManager.Instance.SetTheme(!isOn ? UTKTheme.Dark : UTKTheme.Light);
|
|
|
|
|
};
|
2026-01-08 20:15:57 +09:00
|
|
|
|
|
|
|
|
var root = _uiDocument.rootVisualElement;
|
|
|
|
|
CreateSamplePropertyWindow(root);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateSamplePropertyWindow(VisualElement root)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// 세로 높이를 부모에 맞게 꽉 채우기
|
|
|
|
|
_propertyWindow.style.position = Position.Absolute;
|
|
|
|
|
_propertyWindow.style.top = 0;
|
|
|
|
|
_propertyWindow.style.bottom = 0;
|
|
|
|
|
_propertyWindow.style.right = 0;
|
|
|
|
|
_propertyWindow.style.width = 300;
|
|
|
|
|
_propertyWindow.OnCloseClicked += () =>
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Property Window Close clicked");
|
|
|
|
|
_propertyWindow?.Hide();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_propertyWindow.OnPropertyValueChanged += args =>
|
|
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
Debug.Log($"Property Changed: {args.PropertyId} {args.PropertyName} ({args.PropertyType}) = {args.NewValue}");
|
2026-01-08 20:15:57 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 샘플 데이터 생성
|
|
|
|
|
var entries = CreateSampleEntries();
|
|
|
|
|
_propertyWindow.LoadMixedProperties(entries);
|
|
|
|
|
|
|
|
|
|
root.Add(_propertyWindow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<IUTKPropertyEntry> CreateSampleEntries()
|
|
|
|
|
{
|
|
|
|
|
var entries = new List<IUTKPropertyEntry>();
|
|
|
|
|
|
|
|
|
|
// 기본 속성 그룹
|
|
|
|
|
var basicGroup = new UTKPropertyGroup("basic", "Basic Properties");
|
|
|
|
|
basicGroup.AddItem(new UTKStringPropertyItem("name", "Name", "Sample Object"));
|
|
|
|
|
basicGroup.AddItem(new UTKStringPropertyItem("description", "Description", "This is a sample object") { IsMultiline = true });
|
|
|
|
|
basicGroup.AddItem(new UTKBoolPropertyItem("active", "Is Active", true));
|
|
|
|
|
basicGroup.AddItem(new UTKIntPropertyItem("count", "Count", 10, 0, 100, true));
|
|
|
|
|
basicGroup.AddItem(new UTKFloatPropertyItem("speed", "Speed", 1.5f, 0f, 10f, true));
|
|
|
|
|
entries.Add(basicGroup);
|
|
|
|
|
|
|
|
|
|
// Transform 그룹
|
|
|
|
|
var transformGroup = new UTKPropertyGroup("transform", "Transform");
|
|
|
|
|
transformGroup.AddItem(new UTKVector3PropertyItem("position", "Position", new Vector3(0, 1, 0)));
|
|
|
|
|
transformGroup.AddItem(new UTKVector3PropertyItem("rotation", "Rotation", Vector3.zero));
|
|
|
|
|
transformGroup.AddItem(new UTKVector3PropertyItem("scale", "Scale", Vector3.one));
|
|
|
|
|
entries.Add(transformGroup);
|
|
|
|
|
|
|
|
|
|
// Appearance 그룹
|
|
|
|
|
var appearanceGroup = new UTKPropertyGroup("appearance", "Appearance");
|
|
|
|
|
appearanceGroup.AddItem(new UTKColorPropertyItem("mainColor", "Main Color", Color.blue));
|
|
|
|
|
appearanceGroup.AddItem(new UTKColorPropertyItem("emissionColor", "Emission Color", Color.yellow, true));
|
|
|
|
|
appearanceGroup.AddItem(new UTKFloatPropertyItem("alpha", "Alpha", 1f, 0f, 1f, true));
|
|
|
|
|
entries.Add(appearanceGroup);
|
|
|
|
|
|
|
|
|
|
// Date/Time 그룹
|
|
|
|
|
var dateGroup = new UTKPropertyGroup("datetime", "Date & Time");
|
|
|
|
|
dateGroup.AddItem(new UTKDatePropertyItem("createdDate", "Created Date", DateTime.Today.AddDays(-30)));
|
|
|
|
|
dateGroup.AddItem(new UTKDateTimePropertyItem("lastModified", "Last Modified", DateTime.Now));
|
|
|
|
|
dateGroup.AddItem(new UTKDateRangePropertyItem("validPeriod", "Valid Period", DateTime.Today, DateTime.Today.AddMonths(1)));
|
|
|
|
|
entries.Add(dateGroup);
|
|
|
|
|
|
|
|
|
|
// Selection 그룹
|
|
|
|
|
var selectionGroup = new UTKPropertyGroup("selection", "Selection");
|
|
|
|
|
selectionGroup.AddItem(new UTKEnumPropertyItem("layer", "Layer", SampleLayer.Default));
|
|
|
|
|
selectionGroup.AddItem(new UTKDropdownPropertyItem("tag", "Tag",
|
|
|
|
|
new List<string> { "Untagged", "Player", "Enemy", "Item", "Environment" }, "Player"));
|
|
|
|
|
selectionGroup.AddItem(new UTKRadioPropertyItem("quality", "Quality",
|
|
|
|
|
new List<string> { "Low", "Medium", "High", "Ultra" }, 2));
|
|
|
|
|
entries.Add(selectionGroup);
|
|
|
|
|
|
|
|
|
|
// Range 그룹
|
|
|
|
|
var rangeGroup = new UTKPropertyGroup("range", "Range Properties");
|
|
|
|
|
rangeGroup.AddItem(new UTKIntRangePropertyItem("levelRange", "Level Range", 1, 50));
|
|
|
|
|
rangeGroup.AddItem(new UTKFloatRangePropertyItem("damageRange", "Damage Range", 10.5f, 25.0f));
|
|
|
|
|
entries.Add(rangeGroup);
|
|
|
|
|
|
|
|
|
|
// Special 그룹
|
|
|
|
|
var specialGroup = new UTKPropertyGroup("special", "Special Properties");
|
|
|
|
|
specialGroup.AddItem(new UTKColorStatePropertyItem("status", "Status",
|
|
|
|
|
new UTKColorState("Active", Color.green)));
|
|
|
|
|
specialGroup.AddItem(new UTKVector2PropertyItem("uv", "UV Offset", new Vector2(0.5f, 0.5f)));
|
|
|
|
|
entries.Add(specialGroup);
|
|
|
|
|
|
|
|
|
|
// 읽기 전용 그룹
|
|
|
|
|
var readOnlyGroup = new UTKPropertyGroup("readonly", "Read-Only Properties");
|
|
|
|
|
var idItem = new UTKStringPropertyItem("id", "ID", "OBJ-12345");
|
|
|
|
|
idItem.IsReadOnly = true;
|
|
|
|
|
readOnlyGroup.AddItem(idItem);
|
|
|
|
|
|
|
|
|
|
var versionItem = new UTKIntPropertyItem("version", "Version", 3);
|
|
|
|
|
versionItem.IsReadOnly = true;
|
|
|
|
|
readOnlyGroup.AddItem(versionItem);
|
|
|
|
|
entries.Add(readOnlyGroup);
|
|
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
_propertyWindow?.Dispose();
|
|
|
|
|
_propertyWindow = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 샘플 열거형
|
|
|
|
|
public enum SampleLayer
|
|
|
|
|
{
|
|
|
|
|
Default,
|
|
|
|
|
TransparentFX,
|
|
|
|
|
IgnoreRaycast,
|
|
|
|
|
Water,
|
|
|
|
|
UI
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|