2025-08-24 20:12:05 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq.Expressions;
|
2025-08-21 07:25:27 +00:00
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
2025-08-24 20:12:05 +00:00
|
|
|
using UnityEngine.Localization.Components;
|
2025-08-21 07:25:27 +00:00
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
namespace DDD
|
|
|
|
{
|
|
|
|
public static class BindingHelper
|
|
|
|
{
|
|
|
|
public static void BindText(BindingContext context, TextMeshProUGUI text, string propertyPath, IValueConverter converter = null)
|
|
|
|
{
|
|
|
|
var target = new TextBindingTarget(text, propertyPath);
|
|
|
|
context?.Bind(propertyPath, target, converter);
|
|
|
|
}
|
2025-08-24 20:12:05 +00:00
|
|
|
|
|
|
|
public static void BindLocalizedStringEvent(BindingContext context, LocalizeStringEvent localizeEvent, string propertyPath, IValueConverter converter = null)
|
|
|
|
{
|
|
|
|
var target = new LocalizeStringEventBindingTarget(localizeEvent, propertyPath);
|
|
|
|
context?.Bind(propertyPath, target, converter);
|
|
|
|
}
|
2025-08-21 07:25:27 +00:00
|
|
|
|
|
|
|
public static void BindImage(BindingContext context, Image image, string propertyPath, IValueConverter converter = null)
|
|
|
|
{
|
|
|
|
var target = new ImageBindingTarget(image, propertyPath);
|
|
|
|
context?.Bind(propertyPath, target, converter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void BindImageFilled(BindingContext context, Image image, string propertyPath, IValueConverter converter = null)
|
|
|
|
{
|
|
|
|
var target = new ImageFilledBindingTarget(image, propertyPath);
|
|
|
|
context?.Bind(propertyPath, target, converter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void BindActive(BindingContext context, GameObject gameObject, string propertyPath, IValueConverter converter = null)
|
|
|
|
{
|
|
|
|
var target = new ActiveBindingTarget(gameObject, propertyPath);
|
|
|
|
context?.Bind(propertyPath, target, converter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void BindSlider(BindingContext context, Slider slider, string propertyPath, IValueConverter converter = null)
|
|
|
|
{
|
|
|
|
var target = new SliderBindingTarget(slider, propertyPath);
|
|
|
|
context?.Bind(propertyPath, target, converter);
|
|
|
|
}
|
2025-08-24 20:12:05 +00:00
|
|
|
|
|
|
|
public static void BindText<TVm>(BindingContext ctx, TextMeshProUGUI text,
|
|
|
|
Expression<Func<TVm, object>> prop, IValueConverter conv = null)
|
|
|
|
=> BindText(ctx, text, BindingPath.For(prop), conv);
|
|
|
|
|
|
|
|
public static void BindLocalizedStringEvent<TVm>(BindingContext ctx, LocalizeStringEvent loc,
|
|
|
|
Expression<Func<TVm, object>> prop, IValueConverter conv = null)
|
|
|
|
=> BindLocalizedStringEvent(ctx, loc, BindingPath.For(prop), conv);
|
|
|
|
|
|
|
|
public static void BindImage<TVm>(BindingContext ctx, Image img,
|
|
|
|
Expression<Func<TVm, object>> prop, IValueConverter conv = null)
|
|
|
|
=> BindImage(ctx, img, BindingPath.For(prop), conv);
|
|
|
|
|
|
|
|
public static void BindImageFilled<TVm>(BindingContext ctx, Image img,
|
|
|
|
Expression<Func<TVm, object>> prop, IValueConverter conv = null)
|
|
|
|
=> BindImageFilled(ctx, img, BindingPath.For(prop), conv);
|
|
|
|
|
|
|
|
public static void BindActive<TVm>(BindingContext ctx, GameObject go,
|
|
|
|
Expression<Func<TVm, object>> prop, IValueConverter conv = null)
|
|
|
|
=> BindActive(ctx, go, BindingPath.For(prop), conv);
|
|
|
|
|
|
|
|
public static void BindSlider<TVm>(BindingContext ctx, Slider slider,
|
|
|
|
Expression<Func<TVm, object>> prop, IValueConverter conv = null)
|
|
|
|
=> BindSlider(ctx, slider, BindingPath.For(prop), conv);
|
|
|
|
|
|
|
|
public static void BindImage<TVm, TProp>(BindingContext ctx, Image img,
|
|
|
|
Expression<Func<TVm, TProp>> prop, IValueConverter conv = null)
|
|
|
|
=> BindImage(ctx, img, BindingPath.For(prop), conv);
|
|
|
|
|
|
|
|
public static void BindActive<TVm, TProp>(BindingContext ctx, GameObject go,
|
|
|
|
Expression<Func<TVm, TProp>> prop, IValueConverter conv = null)
|
|
|
|
=> BindActive(ctx, go, BindingPath.For(prop), conv);
|
|
|
|
|
|
|
|
public static void BindLocalizedStringEvent<TVm, TProp>(BindingContext ctx, LocalizeStringEvent loc,
|
|
|
|
Expression<Func<TVm, TProp>> prop, IValueConverter conv = null)
|
|
|
|
=> BindLocalizedStringEvent(ctx, loc, BindingPath.For(prop), conv);
|
2025-08-21 07:25:27 +00:00
|
|
|
}
|
|
|
|
}
|