118 lines
3.0 KiB
C#
118 lines
3.0 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (_image != null && value is Sprite sprite)
|
|
{
|
|
_image.sprite = sprite;
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |