#nullable enable using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; using UVC.UIToolkit.Property; namespace UVC.Sample.UIToolkit { /// /// UTKPropertyWindow 샘플 코드 /// 기존 PropertyWindowSample과 동일한 데이터를 UTKPropertyWindow로 표시 /// public class UTKPropertyWindowSample : MonoBehaviour { [SerializeField] private UIDocument? _uiDocument; private UTKPropertyWindow? _propertyWindow; private void Start() { if (_uiDocument == null) { Debug.LogError("UIDocument is not assigned!"); return; } var root = _uiDocument.rootVisualElement; CreateSamplePropertyWindow(root); } private void CreateSamplePropertyWindow(VisualElement root) { _propertyWindow = new UTKPropertyWindow("Sample Properties"); // 세로 높이를 부모에 맞게 꽉 채우기 _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 => { Debug.Log($"Property Changed: {args.PropertyName} ({args.PropertyType}) = {args.NewValue}"); }; // 샘플 데이터 생성 var entries = CreateSampleEntries(); _propertyWindow.LoadMixedProperties(entries); root.Add(_propertyWindow); } private List CreateSampleEntries() { var entries = new List(); // 기본 속성 그룹 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 { "Untagged", "Player", "Enemy", "Item", "Environment" }, "Player")); selectionGroup.AddItem(new UTKRadioPropertyItem("quality", "Quality", new List { "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 } } }