2025-08-21 07:25:27 +00:00
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
2025-08-24 20:12:05 +00:00
|
|
|
using UnityEngine.Localization;
|
|
|
|
using UnityEngine.Localization.Components;
|
2025-08-21 07:25:27 +00:00
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
namespace DDD
|
|
|
|
{
|
|
|
|
public interface IBindingTarget
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 바인딩된 속성의 경로
|
|
|
|
/// </summary>
|
|
|
|
string PropertyPath { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// UI 요소의 값을 업데이트
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">새로운 값</param>
|
|
|
|
void UpdateValue(object value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TextBindingTarget : IBindingTarget
|
|
|
|
{
|
|
|
|
private readonly TextMeshProUGUI _text;
|
|
|
|
public string PropertyPath { get; }
|
|
|
|
|
|
|
|
public TextBindingTarget(TextMeshProUGUI text, string propertyPath)
|
|
|
|
{
|
|
|
|
_text = text;
|
|
|
|
PropertyPath = propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateValue(object value)
|
|
|
|
{
|
|
|
|
if (_text != null)
|
|
|
|
{
|
|
|
|
_text.text = value?.ToString() ?? string.Empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-08-24 20:12:05 +00:00
|
|
|
public class LocalizeStringEventBindingTarget : IBindingTarget
|
|
|
|
{
|
|
|
|
private readonly LocalizeStringEvent _localizeEvent;
|
|
|
|
public string PropertyPath { get; }
|
|
|
|
|
|
|
|
public LocalizeStringEventBindingTarget(LocalizeStringEvent localizeEvent, string propertyPath)
|
|
|
|
{
|
|
|
|
_localizeEvent = localizeEvent;
|
|
|
|
PropertyPath = propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateValue(object value)
|
|
|
|
{
|
|
|
|
if (_localizeEvent == null) return;
|
|
|
|
|
|
|
|
if (value is LocalizedString localized)
|
|
|
|
{
|
|
|
|
_localizeEvent.StringReference = localized;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// null 또는 다른 타입인 경우 초기화
|
|
|
|
_localizeEvent.StringReference = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-08-21 07:25:27 +00:00
|
|
|
public class ImageBindingTarget : IBindingTarget
|
|
|
|
{
|
|
|
|
private readonly Image _image;
|
|
|
|
public string PropertyPath { get; }
|
|
|
|
|
|
|
|
public ImageBindingTarget(Image image, string propertyPath)
|
|
|
|
{
|
|
|
|
_image = image;
|
|
|
|
PropertyPath = propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateValue(object value)
|
|
|
|
{
|
2025-08-24 20:12:05 +00:00
|
|
|
if (value is Sprite sprite)
|
2025-08-21 07:25:27 +00:00
|
|
|
{
|
|
|
|
_image.sprite = sprite;
|
|
|
|
}
|
2025-08-24 20:12:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_image.sprite = null;
|
|
|
|
}
|
2025-08-21 07:25:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ImageFilledBindingTarget : IBindingTarget
|
|
|
|
{
|
|
|
|
private readonly Image _image;
|
|
|
|
public string PropertyPath { get; }
|
|
|
|
|
|
|
|
public ImageFilledBindingTarget(Image image, string propertyPath)
|
|
|
|
{
|
|
|
|
_image = image;
|
|
|
|
PropertyPath = propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateValue(object value)
|
|
|
|
{
|
|
|
|
if (_image != null && value is float floatValue)
|
|
|
|
{
|
|
|
|
_image.fillAmount = Mathf.Clamp01(floatValue); // 0-1 범위로 제한
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ActiveBindingTarget : IBindingTarget
|
|
|
|
{
|
|
|
|
private readonly GameObject _gameObject;
|
|
|
|
public string PropertyPath { get; }
|
|
|
|
|
|
|
|
public ActiveBindingTarget(GameObject go, string propertyPath)
|
|
|
|
{
|
|
|
|
_gameObject = go;
|
|
|
|
PropertyPath = propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateValue(object value)
|
|
|
|
{
|
|
|
|
if (_gameObject != null)
|
|
|
|
{
|
|
|
|
_gameObject.SetActive(value is true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class SliderBindingTarget : IBindingTarget
|
|
|
|
{
|
|
|
|
private readonly Slider _slider;
|
|
|
|
public string PropertyPath { get; }
|
|
|
|
|
|
|
|
public SliderBindingTarget(Slider slider, string propertyPath)
|
|
|
|
{
|
|
|
|
_slider = slider;
|
|
|
|
PropertyPath = propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateValue(object value)
|
|
|
|
{
|
|
|
|
if (_slider != null && value is float floatValue)
|
|
|
|
_slider.value = floatValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|