2026-01-08 20:15:57 +09:00
|
|
|
#nullable enable
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
2026-01-20 20:18:47 +09:00
|
|
|
namespace UVC.UIToolkit
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 2D 벡터 속성 아이템
|
2026-02-02 19:33:27 +09:00
|
|
|
/// UTKVector2Field 사용
|
2026-01-08 20:15:57 +09:00
|
|
|
/// </summary>
|
|
|
|
|
public class UTKVector2PropertyItem : UTKPropertyItemBase<Vector2>
|
|
|
|
|
{
|
|
|
|
|
#region Fields
|
2026-02-02 19:33:27 +09:00
|
|
|
private UTKVector2Field? _vectorField;
|
2026-01-08 20:15:57 +09:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
public override UTKPropertyType PropertyType => UTKPropertyType.Vector2;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
public UTKVector2PropertyItem(string id, string name, Vector2 initialValue = default)
|
|
|
|
|
: base(id, name, initialValue)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Override Methods
|
|
|
|
|
public override VisualElement CreateUI()
|
2026-02-02 19:33:27 +09:00
|
|
|
{
|
|
|
|
|
var container = CreateUIFromUxml("UTKVector2PropertyItem");
|
|
|
|
|
if (container == null)
|
|
|
|
|
{
|
|
|
|
|
return CreateUIFallback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_vectorField = container.Q<UTKVector2Field>("value-field");
|
|
|
|
|
if (_vectorField != null)
|
|
|
|
|
{
|
|
|
|
|
_vectorField.Value = Value;
|
|
|
|
|
_vectorField.label = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return container;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private VisualElement CreateUIFallback()
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
|
|
|
|
var container = CreateContainer();
|
|
|
|
|
|
|
|
|
|
var label = CreateNameLabel();
|
|
|
|
|
container.Add(label);
|
|
|
|
|
|
|
|
|
|
var valueContainer = new VisualElement();
|
|
|
|
|
valueContainer.AddToClassList("utk-property-item__value");
|
|
|
|
|
|
2026-02-02 19:33:27 +09:00
|
|
|
_vectorField = new UTKVector2Field();
|
|
|
|
|
_vectorField.name = "value-field";
|
|
|
|
|
_vectorField.label = "";
|
|
|
|
|
_vectorField.Value = Value;
|
|
|
|
|
_vectorField.AddToClassList("utk-property-item__vector2-field");
|
|
|
|
|
valueContainer.Add(_vectorField);
|
2026-01-08 20:15:57 +09:00
|
|
|
|
|
|
|
|
container.Add(valueContainer);
|
|
|
|
|
|
|
|
|
|
return container;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void BindUI(VisualElement element)
|
|
|
|
|
{
|
|
|
|
|
base.BindUI(element);
|
|
|
|
|
|
2026-02-02 19:33:27 +09:00
|
|
|
_vectorField = element.Q<UTKVector2Field>("value-field");
|
2026-01-08 20:15:57 +09:00
|
|
|
|
2026-02-02 19:33:27 +09:00
|
|
|
if (_vectorField != null)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_vectorField.Value = Value;
|
|
|
|
|
_vectorField.label = "";
|
|
|
|
|
_vectorField.IsEnabled = !IsReadOnly;
|
|
|
|
|
_vectorField.OnValueChanged += OnVectorChanged;
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UnbindUI(VisualElement element)
|
|
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
if (_vectorField != null)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_vectorField.OnValueChanged -= OnVectorChanged;
|
|
|
|
|
_vectorField = null;
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.UnbindUI(element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void RefreshUI()
|
|
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
if (_vectorField != null && _vectorField.Value != Value)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_vectorField.SetValueWithoutNotify(Value);
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateReadOnlyState()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateReadOnlyState();
|
|
|
|
|
|
2026-02-02 19:33:27 +09:00
|
|
|
if (_vectorField != null)
|
|
|
|
|
{
|
|
|
|
|
_vectorField.IsEnabled = !IsReadOnly;
|
|
|
|
|
}
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private Methods
|
2026-02-02 19:33:27 +09:00
|
|
|
private void OnVectorChanged(Vector2 newValue)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
|
|
|
|
DebounceValueChange(newValue, 100).Forget();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|