2026-01-08 20:15:57 +09:00
|
|
|
#nullable enable
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
2026-01-20 20:18:47 +09:00
|
|
|
namespace UVC.UIToolkit
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 문자열 속성 아이템
|
|
|
|
|
/// TextField를 사용한 텍스트 입력
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class UTKStringPropertyItem : UTKPropertyItemBase<string>
|
|
|
|
|
{
|
|
|
|
|
#region Fields
|
2026-02-02 19:33:27 +09:00
|
|
|
private UTKInputField? _inputField;
|
2026-01-08 20:15:57 +09:00
|
|
|
private bool _isMultiline;
|
|
|
|
|
private int _maxLength;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
public override UTKPropertyType PropertyType => UTKPropertyType.String;
|
|
|
|
|
|
|
|
|
|
/// <summary>멀티라인 모드 여부</summary>
|
|
|
|
|
public bool IsMultiline
|
|
|
|
|
{
|
|
|
|
|
get => _isMultiline;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_isMultiline = value;
|
2026-02-02 19:33:27 +09:00
|
|
|
if (_inputField != null)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_inputField.multiline = value;
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>최대 문자 길이 (0 = 무제한)</summary>
|
|
|
|
|
public int MaxLength
|
|
|
|
|
{
|
|
|
|
|
get => _maxLength;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_maxLength = value;
|
2026-02-02 19:33:27 +09:00
|
|
|
if (_inputField != null)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_inputField.maxLength = value;
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
public UTKStringPropertyItem(string id, string name, string initialValue = "")
|
|
|
|
|
: base(id, name, initialValue ?? string.Empty)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Override Methods
|
|
|
|
|
public override VisualElement CreateUI()
|
2026-02-02 19:33:27 +09:00
|
|
|
{
|
|
|
|
|
var container = CreateUIFromUxml("UTKStringPropertyItem");
|
|
|
|
|
if (container == null)
|
|
|
|
|
{
|
|
|
|
|
return CreateUIFallback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_inputField = container.Q<UTKInputField>("value-field");
|
|
|
|
|
if (_inputField != null)
|
|
|
|
|
{
|
|
|
|
|
_inputField.Value = Value;
|
|
|
|
|
_inputField.multiline = _isMultiline;
|
|
|
|
|
if (_maxLength > 0)
|
|
|
|
|
{
|
|
|
|
|
_inputField.maxLength = _maxLength;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
_inputField = new UTKInputField();
|
|
|
|
|
_inputField.name = "value-field";
|
|
|
|
|
_inputField.Value = Value;
|
|
|
|
|
_inputField.multiline = _isMultiline;
|
2026-01-08 20:15:57 +09:00
|
|
|
if (_maxLength > 0)
|
|
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_inputField.maxLength = _maxLength;
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-02 19:33:27 +09:00
|
|
|
valueContainer.Add(_inputField);
|
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
|
|
|
_inputField = element.Q<UTKInputField>("value-field");
|
|
|
|
|
if (_inputField != null)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_inputField.Value = Value;
|
|
|
|
|
_inputField.SetEnabled(!IsReadOnly);
|
|
|
|
|
_inputField.OnValueChanged += OnTextChanged;
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UnbindUI(VisualElement element)
|
|
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
if (_inputField != null)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_inputField.OnValueChanged -= OnTextChanged;
|
|
|
|
|
_inputField = 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 (_inputField != null && _inputField.Value != Value)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_inputField.SetValue(Value, false);
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateReadOnlyState()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateReadOnlyState();
|
|
|
|
|
|
2026-02-02 19:33:27 +09:00
|
|
|
if (_inputField != null)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
_inputField.SetEnabled(!IsReadOnly);
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private Methods
|
2026-02-02 19:33:27 +09:00
|
|
|
private void OnTextChanged(string newValue)
|
2026-01-08 20:15:57 +09:00
|
|
|
{
|
2026-02-02 19:33:27 +09:00
|
|
|
DebounceValueChange(newValue).Forget();
|
2026-01-08 20:15:57 +09:00
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|